1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
6#define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "base/memory/scoped_vector.h"
10#include "base/threading/thread.h"
11#include "tools/android/forwarder2/pipe_notifier.h"
12
13namespace forwarder2 {
14
15class Forwarder;
16class Socket;
17
18// Creates, owns and notifies Forwarder instances on its own internal thread.
19class ForwardersManager {
20 public:
21  ForwardersManager();
22
23  // Must be called on the thread the constructor was called on.
24  ~ForwardersManager();
25
26  // Can be called on any thread.
27  void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
28                                  scoped_ptr<Socket> socket2);
29
30 private:
31  void CreateNewForwarderOnInternalThread(scoped_ptr<Socket> socket1,
32                                          scoped_ptr<Socket> socket2);
33
34  void WaitForEventsOnInternalThreadSoon();
35  void WaitForEventsOnInternalThread();
36
37  ScopedVector<Forwarder> forwarders_;
38  PipeNotifier deletion_notifier_;
39  PipeNotifier wakeup_notifier_;
40  base::Thread thread_;
41};
42
43}  // namespace forwarder2
44
45#endif  // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
46