15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_vector.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/threading/thread.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "tools/android/forwarder2/pipe_notifier.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace forwarder2 {
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Forwarder;
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Socket;
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Creates, owns and notifies Forwarder instances on its own internal thread.
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ForwardersManager {
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ForwardersManager();
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Must be called on the thread the constructor was called on.
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ~ForwardersManager();
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Can be called on any thread.
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                  scoped_ptr<Socket> socket2);
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CreateNewForwarderOnInternalThread(scoped_ptr<Socket> socket1,
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          scoped_ptr<Socket> socket2);
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void WaitForEventsOnInternalThreadSoon();
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void WaitForEventsOnInternalThread();
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ScopedVector<Forwarder> forwarders_;
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PipeNotifier deletion_notifier_;
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PipeNotifier wakeup_notifier_;
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::Thread thread_;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace forwarder2
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
46