forwarders_manager.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
  5. #define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/threading/thread.h"
  9. #include "tools/android/forwarder2/pipe_notifier.h"
  10. namespace forwarder2 {
  11. class Forwarder;
  12. class Socket;
  13. // Creates, owns and notifies Forwarder instances on its own internal thread.
  14. class ForwardersManager {
  15. public:
  16. ForwardersManager();
  17. // Must be called on the thread the constructor was called on.
  18. ~ForwardersManager();
  19. // Can be called on any thread.
  20. void CreateAndStartNewForwarder(std::unique_ptr<Socket> socket1,
  21. std::unique_ptr<Socket> socket2);
  22. private:
  23. void CreateNewForwarderOnInternalThread(std::unique_ptr<Socket> socket1,
  24. std::unique_ptr<Socket> socket2);
  25. void WaitForEventsOnInternalThreadSoon();
  26. void WaitForEventsOnInternalThread();
  27. std::vector<std::unique_ptr<Forwarder>> forwarders_;
  28. PipeNotifier deletion_notifier_;
  29. PipeNotifier wakeup_notifier_;
  30. base::Thread thread_;
  31. };
  32. } // namespace forwarder2
  33. #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_