OLD | NEW |
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 MOJO_SYSTEM_CHANNEL_H_ | 5 #ifndef MOJO_SYSTEM_CHANNEL_H_ |
6 #define MOJO_SYSTEM_CHANNEL_H_ | 6 #define MOJO_SYSTEM_CHANNEL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // This must be called on the creation thread before any other methods are | 60 // This must be called on the creation thread before any other methods are |
61 // called, and before references to this object are given to any other | 61 // called, and before references to this object are given to any other |
62 // threads. |raw_channel| should be uninitialized. Returns true on success. On | 62 // threads. |raw_channel| should be uninitialized. Returns true on success. On |
63 // failure, no other methods should be called (including |Shutdown()|). | 63 // failure, no other methods should be called (including |Shutdown()|). |
64 bool Init(scoped_ptr<RawChannel> raw_channel); | 64 bool Init(scoped_ptr<RawChannel> raw_channel); |
65 | 65 |
66 // This must be called on the creation thread before destruction (which can | 66 // This must be called on the creation thread before destruction (which can |
67 // happen on any thread). | 67 // happen on any thread). |
68 void Shutdown(); | 68 void Shutdown(); |
69 | 69 |
| 70 // Signals that |Shutdown()| will be called soon (this may be called from any |
| 71 // thread, unlike |Shutdown()|). Warnings will be issued if, e.g., messages |
| 72 // are written after this is called; other warnings may be suppressed. (This |
| 73 // may be called multiple times, or not at all.) |
| 74 void WillShutdownSoon(); |
| 75 |
70 // Attaches the given message pipe/port's endpoint (which must be a | 76 // Attaches the given message pipe/port's endpoint (which must be a |
71 // |ProxyMessagePipeEndpoint|) to this channel. This assigns it a local ID, | 77 // |ProxyMessagePipeEndpoint|) to this channel. This assigns it a local ID, |
72 // which it returns. The first message pipe endpoint attached will always have | 78 // which it returns. The first message pipe endpoint attached will always have |
73 // |kBootstrapEndpointId| as its local ID. (For bootstrapping, this occurs on | 79 // |kBootstrapEndpointId| as its local ID. (For bootstrapping, this occurs on |
74 // both sides, so one should use |kBootstrapEndpointId| for the remote ID for | 80 // both sides, so one should use |kBootstrapEndpointId| for the remote ID for |
75 // the first message pipe across a channel.) Returns |kInvalidEndpointId| on | 81 // the first message pipe across a channel.) Returns |kInvalidEndpointId| on |
76 // failure. | 82 // failure. |
77 // TODO(vtl): Maybe limit the number of attached message pipes. | 83 // TODO(vtl): Maybe limit the number of attached message pipes. |
78 MessageInTransit::EndpointId AttachMessagePipeEndpoint( | 84 MessageInTransit::EndpointId AttachMessagePipeEndpoint( |
79 scoped_refptr<MessagePipe> message_pipe, | 85 scoped_refptr<MessagePipe> message_pipe, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 void HandleRemoteError(const base::StringPiece& error_message); | 171 void HandleRemoteError(const base::StringPiece& error_message); |
166 // Handles internal errors/failures from the local side. | 172 // Handles internal errors/failures from the local side. |
167 void HandleLocalError(const base::StringPiece& error_message); | 173 void HandleLocalError(const base::StringPiece& error_message); |
168 | 174 |
169 // Helper to send channel control messages. Returns true on success. Should be | 175 // Helper to send channel control messages. Returns true on success. Should be |
170 // called *without* |lock_| held. | 176 // called *without* |lock_| held. |
171 bool SendControlMessage(MessageInTransit::Subtype subtype, | 177 bool SendControlMessage(MessageInTransit::Subtype subtype, |
172 MessageInTransit::EndpointId source_id, | 178 MessageInTransit::EndpointId source_id, |
173 MessageInTransit::EndpointId destination_id); | 179 MessageInTransit::EndpointId destination_id); |
174 | 180 |
175 bool is_running_no_lock() const { return is_running_; } | |
176 | |
177 base::ThreadChecker creation_thread_checker_; | 181 base::ThreadChecker creation_thread_checker_; |
178 | 182 |
179 // Note: |MessagePipe|s MUST NOT be used under |lock_|. I.e., |lock_| can only | 183 // Note: |MessagePipe|s MUST NOT be used under |lock_|. I.e., |lock_| can only |
180 // be acquired after |MessagePipe::lock_|, never before. Thus to call into a | 184 // be acquired after |MessagePipe::lock_|, never before. Thus to call into a |
181 // |MessagePipe|, a reference should be acquired from | 185 // |MessagePipe|, a reference should be acquired from |
182 // |local_id_to_endpoint_info_map_| under |lock_| (e.g., by copying the | 186 // |local_id_to_endpoint_info_map_| under |lock_| (e.g., by copying the |
183 // |EndpointInfo|) and then the lock released. | 187 // |EndpointInfo|) and then the lock released. |
184 base::Lock lock_; // Protects the members below. | 188 base::Lock lock_; // Protects the members below. |
185 | 189 |
186 scoped_ptr<RawChannel> raw_channel_; | 190 scoped_ptr<RawChannel> raw_channel_; |
187 bool is_running_; | 191 bool is_running_; |
| 192 // Set when |WillShutdownSoon()| is called. |
| 193 bool is_shutting_down_; |
188 | 194 |
189 typedef base::hash_map<MessageInTransit::EndpointId, EndpointInfo> | 195 typedef base::hash_map<MessageInTransit::EndpointId, EndpointInfo> |
190 IdToEndpointInfoMap; | 196 IdToEndpointInfoMap; |
191 IdToEndpointInfoMap local_id_to_endpoint_info_map_; | 197 IdToEndpointInfoMap local_id_to_endpoint_info_map_; |
192 // The next local ID to try (when allocating new local IDs). Note: It should | 198 // The next local ID to try (when allocating new local IDs). Note: It should |
193 // be checked for existence before use. | 199 // be checked for existence before use. |
194 MessageInTransit::EndpointId next_local_id_; | 200 MessageInTransit::EndpointId next_local_id_; |
195 | 201 |
196 DISALLOW_COPY_AND_ASSIGN(Channel); | 202 DISALLOW_COPY_AND_ASSIGN(Channel); |
197 }; | 203 }; |
198 | 204 |
199 } // namespace system | 205 } // namespace system |
200 } // namespace mojo | 206 } // namespace mojo |
201 | 207 |
202 #endif // MOJO_SYSTEM_CHANNEL_H_ | 208 #endif // MOJO_SYSTEM_CHANNEL_H_ |
OLD | NEW |