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

Side by Side 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, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/android/forwarder2/forwarder.cc ('k') | tools/android/forwarder2/forwarders_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_ 5 #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
6 #define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_ 6 #define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
7 7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/threading/thread.h"
11 #include "tools/android/forwarder2/pipe_notifier.h" 11 #include "tools/android/forwarder2/pipe_notifier.h"
12 12
13 namespace base {
14
15 class SingleThreadTaskRunner;
16
17 } // namespace base
18
19 namespace forwarder2 { 13 namespace forwarder2 {
20 14
21 class Forwarder; 15 class Forwarder;
22 class Socket; 16 class Socket;
23 17
24 // Creates and manages lifetime of a set of Forwarder instances. This class 18 // Creates, owns and notifies Forwarder instances on its own internal thread.
25 // ensures in particular that the forwarder instances are deleted on their
26 // construction thread no matter which thread ~ForwardersManager() is called on.
27 class ForwardersManager { 19 class ForwardersManager {
28 public: 20 public:
29 // Can be called on any thread.
30 ForwardersManager(); 21 ForwardersManager();
22
23 // Must be called on the thread the constructor was called on.
31 ~ForwardersManager(); 24 ~ForwardersManager();
32 25
33 // Note that the (unique) thread that this method is called on must outlive 26 // Can be called on any thread.
34 // the ForwardersManager instance. This is needed since the Forwarder
35 // instances are deleted on the thread they were constructed on.
36 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1, 27 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
37 scoped_ptr<Socket> socket2); 28 scoped_ptr<Socket> socket2);
38 29
39 private: 30 private:
40 // Ref-counted thread-safe delegate that can (by definition) outlive its outer 31 void CreateNewForwarderOnInternalThread(scoped_ptr<Socket> socket1,
41 // ForwarderManager instance. This is needed since the forwarder instances are 32 scoped_ptr<Socket> socket2);
42 // destroyed on a thread other than the one ~ForwardersManager() is called on.
43 // The forwarder instances can also call OnForwarderError() below at any time
44 // on their construction thread (which is the same as their destruction
45 // thread). This means that a WeakPtr to ForwardersManager can't be used
46 // instead of ref-counting since checking the validity of the WeakPtr on a
47 // thread other than the one ~ForwardersManager() is called on would be racy.
48 class Delegate : public base::RefCountedThreadSafe<Delegate> {
49 public:
50 Delegate();
51 33
52 void Clear(); 34 void WaitForEventsOnInternalThreadSoon();
35 void WaitForEventsOnInternalThread();
53 36
54 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1, 37 ScopedVector<Forwarder> forwarders_;
55 scoped_ptr<Socket> socket2); 38 PipeNotifier deletion_notifier_;
56 39 PipeNotifier wakeup_notifier_;
57 private: 40 base::Thread thread_;
58 friend class base::RefCountedThreadSafe<Delegate>;
59
60 virtual ~Delegate();
61
62 void OnForwarderError(scoped_ptr<Forwarder> forwarder);
63
64 void ClearOnForwarderConstructorThread();
65
66 scoped_refptr<base::SingleThreadTaskRunner> forwarders_constructor_runner_;
67 PipeNotifier deletion_notifier_;
68 ScopedVector<Forwarder> forwarders_;
69 };
70
71 const scoped_refptr<Delegate> delegate_;
72 }; 41 };
73 42
74 } // namespace forwarder2 43 } // namespace forwarder2
75 44
76 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_ 45 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
OLDNEW
« 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