OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/task_runner.h" | |
15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/embedder/scoped_platform_handle.h" |
16 #include "mojo/edk/system/channel.h" | 15 #include "mojo/edk/system/channel.h" |
17 #include "mojo/edk/system/channel_info.h" | 16 #include "mojo/edk/system/channel_info.h" |
18 | 17 |
18 namespace base { | |
19 class TaskRunner; | |
20 } | |
21 | |
19 namespace mojo { | 22 namespace mojo { |
20 | 23 |
21 namespace embedder { | 24 namespace embedder { |
22 class PlatformSupport; | 25 class PlatformSupport; |
23 } | 26 } |
24 | 27 |
25 namespace system { | 28 namespace system { |
26 | 29 |
27 // IDs for |Channel|s managed by a |ChannelManager|. (IDs should be thought of | 30 // IDs for |Channel|s managed by a |ChannelManager|. (IDs should be thought of |
28 // as specific to a given |ChannelManager|.) 0 is never a valid ID. | 31 // as specific to a given |ChannelManager|.) 0 is never a valid ID. |
(...skipping 10 matching lines...) Expand all Loading... | |
39 explicit ChannelManager(embedder::PlatformSupport* platform_support); | 42 explicit ChannelManager(embedder::PlatformSupport* platform_support); |
40 ~ChannelManager(); | 43 ~ChannelManager(); |
41 | 44 |
42 // Creates a |Channel| and adds it to the set of channels managed by this | 45 // Creates a |Channel| and adds it to the set of channels managed by this |
43 // |ChannelManager|. |channel_id| should be a valid |ChannelId| (i.e., | 46 // |ChannelManager|. |channel_id| should be a valid |ChannelId| (i.e., |
44 // nonzero) not "assigned" to any other |Channel| being managed by this | 47 // nonzero) not "assigned" to any other |Channel| being managed by this |
45 // |ChannelManager|. | 48 // |ChannelManager|. |
46 // TODO(vtl): Currently, this should be called on any I/O thread (which will | 49 // TODO(vtl): Currently, this should be called on any I/O thread (which will |
47 // become the new channel's "channel thread"). Eventually, the channel manager | 50 // become the new channel's "channel thread"). Eventually, the channel manager |
48 // will have an assigned I/O thread, on which this must be called. | 51 // will have an assigned I/O thread, on which this must be called. |
49 // TODO(vtl): Maybe this should return a message pipe dispatcher (for the | 52 // TODO(vtl): Probably this should return a message pipe dispatcher (for the |
50 // bootstrap message pipe) instead. | 53 // bootstrap message pipe) instead. |
51 void CreateChannelOnIOThread( | 54 void CreateChannelOnIOThread( |
52 ChannelId channel_id, | 55 ChannelId channel_id, |
53 embedder::ScopedPlatformHandle platform_handle, | 56 embedder::ScopedPlatformHandle platform_handle, |
54 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint); | 57 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint); |
55 | 58 |
59 // Like |CreateChannelOnIOThread()|, but may be called from any thread. On | |
60 // completion, will call |callback| ("on" |io_thread_task_runner| if | |
61 // |callback_thread_task_runner| is null else by posting to using | |
yzshen1
2015/02/04 21:21:06
nit: using is not needed.
| |
62 // |callback_thread_task_runner|). Note: This will always post a task to the | |
63 // I/O thread, even if |io_thread_task_runner| is the task runner for the | |
64 // current thread. | |
65 // TODO(vtl): The |io_thread_task_runner| argument is temporary (we should use | |
66 // the channel manager's I/O thread). | |
67 // TODO(vtl): Probably this should return a message pipe dispatcher (for the | |
68 // bootstrap message pipe) instead. | |
69 void CreateChannel( | |
70 ChannelId channel_id, | |
71 embedder::ScopedPlatformHandle platform_handle, | |
72 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint, | |
73 scoped_refptr<base::TaskRunner> io_thread_task_runner, | |
74 base::Closure callback, | |
75 scoped_refptr<base::TaskRunner> callback_thread_task_runner); | |
76 | |
56 // Gets the |Channel| with the given ID (which must exist). | 77 // Gets the |Channel| with the given ID (which must exist). |
57 scoped_refptr<Channel> GetChannel(ChannelId channel_id) const; | 78 scoped_refptr<Channel> GetChannel(ChannelId channel_id) const; |
58 | 79 |
59 // Informs the channel manager (and thus channel) that it will be shutdown | 80 // Informs the channel manager (and thus channel) that it will be shutdown |
60 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in | 81 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in |
61 // fact be called multiple times) but it will suppress certain warnings (e.g., | 82 // fact be called multiple times) but it will suppress certain warnings (e.g., |
62 // for the channel being broken) and enable others (if messages are written to | 83 // for the channel being broken) and enable others (if messages are written to |
63 // the channel). | 84 // the channel). |
64 void WillShutdownChannel(ChannelId channel_id); | 85 void WillShutdownChannel(ChannelId channel_id); |
65 | 86 |
66 // Shuts down the channel specified by the given ID. It is up to the caller to | 87 // Shuts down the channel specified by the given ID. It is up to the caller to |
67 // guarantee that this is only called once per channel (that was added using | 88 // guarantee that this is only called once per channel (that was added using |
68 // |CreateChannelOnIOThread()|). If called from the channel's creation thread | 89 // |CreateChannelOnIOThread()|). If called from the channel's creation thread |
69 // (i.e., |base::MessageLoopProxy::current()| is the channel thread's | 90 // (i.e., |base::MessageLoopProxy::current()| is the channel thread's |
70 // |TaskRunner|), this will complete synchronously. | 91 // |TaskRunner|), this will complete synchronously. |
71 void ShutdownChannel(ChannelId channel_id); | 92 void ShutdownChannel(ChannelId channel_id); |
72 | 93 |
73 private: | 94 private: |
95 void CreateChannelHelper( | |
96 ChannelId channel_id, | |
97 embedder::ScopedPlatformHandle platform_handle, | |
98 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint, | |
99 base::Closure callback, | |
100 scoped_refptr<base::TaskRunner> callback_thread_task_runner); | |
101 | |
74 embedder::PlatformSupport* const platform_support_; | 102 embedder::PlatformSupport* const platform_support_; |
75 | 103 |
76 // Note: |Channel| methods should not be called under |lock_|. | 104 // Note: |Channel| methods should not be called under |lock_|. |
77 mutable base::Lock lock_; // Protects the members below. | 105 mutable base::Lock lock_; // Protects the members below. |
78 | 106 |
79 // TODO(vtl): Once we give the |ChannelManager| one single I/O thread, we can | 107 // TODO(vtl): Once we give the |ChannelManager| one single I/O thread, we can |
80 // get rid of |ChannelInfo| (and just have ref pointers to |Channel|s). | 108 // get rid of |ChannelInfo| (and just have ref pointers to |Channel|s). |
81 base::hash_map<ChannelId, ChannelInfo> channel_infos_; | 109 base::hash_map<ChannelId, ChannelInfo> channel_infos_; |
82 | 110 |
83 DISALLOW_COPY_AND_ASSIGN(ChannelManager); | 111 DISALLOW_COPY_AND_ASSIGN(ChannelManager); |
84 }; | 112 }; |
85 | 113 |
86 } // namespace system | 114 } // namespace system |
87 } // namespace mojo | 115 } // namespace mojo |
88 | 116 |
89 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ | 117 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
OLD | NEW |