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

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: Create ScopedClosureRunner later 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 unified diff | Download patch | Annotate | Revision Log
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
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 { 18 class ForwardersManager {
digit1 2014/01/28 17:28:33 what, no doc for this class?. Come on, you can do
Philippe 2014/01/29 10:50:03 Yeah, I kept the comment quite minimalist though :
28 public: 19 public:
29 // Can be called on any thread.
30 ForwardersManager(); 20 ForwardersManager();
31 ~ForwardersManager(); 21 ~ForwardersManager();
32 22
33 // Note that the (unique) thread that this method is called on must outlive
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, 23 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
37 scoped_ptr<Socket> socket2); 24 scoped_ptr<Socket> socket2);
38 25
39 private: 26 private:
40 // Ref-counted thread-safe delegate that can (by definition) outlive its outer 27 void CreateNewForwarderOnInternalThread(scoped_ptr<Socket> socket1,
41 // ForwarderManager instance. This is needed since the forwarder instances are 28 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 29
52 void Clear(); 30 void WaitForEventsOnInternalThreadSoon();
31 void WaitForEventsOnInternalThread();
53 32
54 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1, 33 ScopedVector<Forwarder> forwarders_;
55 scoped_ptr<Socket> socket2); 34 PipeNotifier deletion_notifier_;
56 35 PipeNotifier wakeup_notifier_;
57 private: 36 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 }; 37 };
73 38
74 } // namespace forwarder2 39 } // namespace forwarder2
75 40
76 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_ 41 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698