| Index: tools/android/forwarder2/forwarders_manager.h
|
| diff --git a/tools/android/forwarder2/forwarders_manager.h b/tools/android/forwarder2/forwarders_manager.h
|
| index 303ec5cdf7708347ad4646b4e86aefd550a40bb0..4c6dea6797622e7c39ddee204bbd6d211dfdb445 100644
|
| --- a/tools/android/forwarder2/forwarders_manager.h
|
| +++ b/tools/android/forwarder2/forwarders_manager.h
|
| @@ -5,70 +5,39 @@
|
| #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
|
| #define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
|
|
|
| -#include "base/memory/ref_counted.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/memory/scoped_vector.h"
|
| +#include "base/threading/thread.h"
|
| #include "tools/android/forwarder2/pipe_notifier.h"
|
|
|
| -namespace base {
|
| -
|
| -class SingleThreadTaskRunner;
|
| -
|
| -} // namespace base
|
| -
|
| namespace forwarder2 {
|
|
|
| class Forwarder;
|
| class Socket;
|
|
|
| -// Creates and manages lifetime of a set of Forwarder instances. This class
|
| -// ensures in particular that the forwarder instances are deleted on their
|
| -// construction thread no matter which thread ~ForwardersManager() is called on.
|
| +// Creates, owns and notifies Forwarder instances on its own internal thread.
|
| class ForwardersManager {
|
| public:
|
| - // Can be called on any thread.
|
| ForwardersManager();
|
| +
|
| + // Must be called on the thread the constructor was called on.
|
| ~ForwardersManager();
|
|
|
| - // Note that the (unique) thread that this method is called on must outlive
|
| - // the ForwardersManager instance. This is needed since the Forwarder
|
| - // instances are deleted on the thread they were constructed on.
|
| + // Can be called on any thread.
|
| void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
|
| scoped_ptr<Socket> socket2);
|
|
|
| private:
|
| - // Ref-counted thread-safe delegate that can (by definition) outlive its outer
|
| - // ForwarderManager instance. This is needed since the forwarder instances are
|
| - // destroyed on a thread other than the one ~ForwardersManager() is called on.
|
| - // The forwarder instances can also call OnForwarderError() below at any time
|
| - // on their construction thread (which is the same as their destruction
|
| - // thread). This means that a WeakPtr to ForwardersManager can't be used
|
| - // instead of ref-counting since checking the validity of the WeakPtr on a
|
| - // thread other than the one ~ForwardersManager() is called on would be racy.
|
| - class Delegate : public base::RefCountedThreadSafe<Delegate> {
|
| - public:
|
| - Delegate();
|
| -
|
| - void Clear();
|
| -
|
| - void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
|
| - scoped_ptr<Socket> socket2);
|
| -
|
| - private:
|
| - friend class base::RefCountedThreadSafe<Delegate>;
|
| -
|
| - virtual ~Delegate();
|
| -
|
| - void OnForwarderError(scoped_ptr<Forwarder> forwarder);
|
| -
|
| - void ClearOnForwarderConstructorThread();
|
| + void CreateNewForwarderOnInternalThread(scoped_ptr<Socket> socket1,
|
| + scoped_ptr<Socket> socket2);
|
|
|
| - scoped_refptr<base::SingleThreadTaskRunner> forwarders_constructor_runner_;
|
| - PipeNotifier deletion_notifier_;
|
| - ScopedVector<Forwarder> forwarders_;
|
| - };
|
| + void WaitForEventsOnInternalThreadSoon();
|
| + void WaitForEventsOnInternalThread();
|
|
|
| - const scoped_refptr<Delegate> delegate_;
|
| + ScopedVector<Forwarder> forwarders_;
|
| + PipeNotifier deletion_notifier_;
|
| + PipeNotifier wakeup_notifier_;
|
| + base::Thread thread_;
|
| };
|
|
|
| } // namespace forwarder2
|
|
|