Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: tools/android/forwarder2/forwarders_manager.h

Issue 148113003: forwarder2: Make the Forwarder instances operate on a single thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address David's comment Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/android/forwarder2/forwarder.cc ('k') | tools/android/forwarder2/forwarders_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « tools/android/forwarder2/forwarder.cc ('k') | tools/android/forwarder2/forwarders_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698