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

Side by Side Diff: tools/android/forwarder2/forwarders_manager.h

Issue 60033002: Make HostController/DeviceListener deletion fully synchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « tools/android/forwarder2/forwarder.gyp ('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
(Empty)
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
5 #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
6 #define TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "tools/android/forwarder2/pipe_notifier.h"
12
13 namespace base {
14
15 class SingleThreadTaskRunner;
16
17 } // namespace base
18
19 namespace forwarder2 {
20
21 class Forwarder;
22 class Socket;
23
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 {
28 public:
29 // Can be called on any thread.
30 ForwardersManager();
31 ~ForwardersManager();
32
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,
37 scoped_ptr<Socket> socket2);
38
39 private:
40 // Ref-counted thread-safe delegate that can (by definition) outlive its outer
41 // ForwarderManager instance. This is needed since the forwarder instances are
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
52 void Clear();
53
54 void CreateAndStartNewForwarder(scoped_ptr<Socket> socket1,
55 scoped_ptr<Socket> socket2);
56
57 private:
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 };
73
74 } // namespace forwarder2
75
76 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDERS_MANAGER_H_
OLDNEW
« no previous file with comments | « tools/android/forwarder2/forwarder.gyp ('k') | tools/android/forwarder2/forwarders_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698