| 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_EDK_SYSTEM_CHANNEL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ |
| 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 14 #include "mojo/edk/embedder/scoped_platform_handle.h" | 16 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 15 #include "mojo/edk/system/channel_endpoint.h" | 17 #include "mojo/edk/system/channel_endpoint.h" |
| 16 #include "mojo/edk/system/channel_endpoint_id.h" | 18 #include "mojo/edk/system/channel_endpoint_id.h" |
| 17 #include "mojo/edk/system/incoming_endpoint.h" | 19 #include "mojo/edk/system/incoming_endpoint.h" |
| 18 #include "mojo/edk/system/message_in_transit.h" | 20 #include "mojo/edk/system/message_in_transit.h" |
| 19 #include "mojo/edk/system/mutex.h" | 21 #include "mojo/edk/system/mutex.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 class MOJO_SYSTEM_IMPL_EXPORT Channel final | 54 class MOJO_SYSTEM_IMPL_EXPORT Channel final |
| 53 : public base::RefCountedThreadSafe<Channel>, | 55 : public base::RefCountedThreadSafe<Channel>, |
| 54 public RawChannel::Delegate { | 56 public RawChannel::Delegate { |
| 55 public: | 57 public: |
| 56 // |platform_support| must remain alive until after |Shutdown()| is called. | 58 // |platform_support| must remain alive until after |Shutdown()| is called. |
| 57 explicit Channel(embedder::PlatformSupport* platform_support); | 59 explicit Channel(embedder::PlatformSupport* platform_support); |
| 58 | 60 |
| 59 // This must be called on the creation thread before any other methods are | 61 // This must be called on the creation thread before any other methods are |
| 60 // called, and before references to this object are given to any other | 62 // called, and before references to this object are given to any other |
| 61 // threads. |raw_channel| should be uninitialized. | 63 // threads. |raw_channel| should be uninitialized. |
| 62 void Init(scoped_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; | 64 void Init(std::unique_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; |
| 63 | 65 |
| 64 // Sets the channel manager associated with this channel. This should be set | 66 // Sets the channel manager associated with this channel. This should be set |
| 65 // at most once and only called before |WillShutdownSoon()| (and | 67 // at most once and only called before |WillShutdownSoon()| (and |
| 66 // |Shutdown()|). (This is called by the channel manager when adding a | 68 // |Shutdown()|). (This is called by the channel manager when adding a |
| 67 // channel; this should not be called before the channel is managed by the | 69 // channel; this should not be called before the channel is managed by the |
| 68 // channel manager.) | 70 // channel manager.) |
| 69 void SetChannelManager(ChannelManager* channel_manager); | 71 void SetChannelManager(ChannelManager* channel_manager); |
| 70 | 72 |
| 71 // This must be called on the creation thread before destruction (which can | 73 // This must be called on the creation thread before destruction (which can |
| 72 // happen on any thread). | 74 // happen on any thread). |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Note: |ChannelEndpointClient|s (in particular, |MessagePipe|s) MUST NOT be | 242 // Note: |ChannelEndpointClient|s (in particular, |MessagePipe|s) MUST NOT be |
| 241 // used under |mutex_|. E.g., |mutex_| can only be acquired after | 243 // used under |mutex_|. E.g., |mutex_| can only be acquired after |
| 242 // |MessagePipe::lock_|, never before. Thus to call into a | 244 // |MessagePipe::lock_|, never before. Thus to call into a |
| 243 // |ChannelEndpointClient|, a reference should be acquired from | 245 // |ChannelEndpointClient|, a reference should be acquired from |
| 244 // |local_id_to_endpoint_map_| under |mutex_| and then the lock released. | 246 // |local_id_to_endpoint_map_| under |mutex_| and then the lock released. |
| 245 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|, | 247 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|, |
| 246 // once clang actually checks such annotations. | 248 // once clang actually checks such annotations. |
| 247 // https://github.com/domokit/mojo/issues/313 | 249 // https://github.com/domokit/mojo/issues/313 |
| 248 mutable Mutex mutex_; | 250 mutable Mutex mutex_; |
| 249 | 251 |
| 250 scoped_ptr<RawChannel> raw_channel_ MOJO_GUARDED_BY(mutex_); | 252 std::unique_ptr<RawChannel> raw_channel_ MOJO_GUARDED_BY(mutex_); |
| 251 bool is_running_ MOJO_GUARDED_BY(mutex_); | 253 bool is_running_ MOJO_GUARDED_BY(mutex_); |
| 252 // Set when |WillShutdownSoon()| is called. | 254 // Set when |WillShutdownSoon()| is called. |
| 253 bool is_shutting_down_ MOJO_GUARDED_BY(mutex_); | 255 bool is_shutting_down_ MOJO_GUARDED_BY(mutex_); |
| 254 | 256 |
| 255 // Has a reference to us. | 257 // Has a reference to us. |
| 256 ChannelManager* channel_manager_ MOJO_GUARDED_BY(mutex_); | 258 ChannelManager* channel_manager_ MOJO_GUARDED_BY(mutex_); |
| 257 | 259 |
| 258 using IdToEndpointMap = | 260 using IdToEndpointMap = |
| 259 base::hash_map<ChannelEndpointId, scoped_refptr<ChannelEndpoint>>; | 261 base::hash_map<ChannelEndpointId, scoped_refptr<ChannelEndpoint>>; |
| 260 // Map from local IDs to endpoints. If the endpoint is null, this means that | 262 // Map from local IDs to endpoints. If the endpoint is null, this means that |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 // if/when we wrap). | 274 // if/when we wrap). |
| 273 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); | 275 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); |
| 274 | 276 |
| 275 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); | 277 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); |
| 276 }; | 278 }; |
| 277 | 279 |
| 278 } // namespace system | 280 } // namespace system |
| 279 } // namespace mojo | 281 } // namespace mojo |
| 280 | 282 |
| 281 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 283 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
| OLD | NEW |