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> | 10 #include <memory> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
16 #include "mojo/edk/system/channel_endpoint.h" | 16 #include "mojo/edk/system/channel_endpoint.h" |
17 #include "mojo/edk/system/channel_endpoint_id.h" | 17 #include "mojo/edk/system/channel_endpoint_id.h" |
18 #include "mojo/edk/system/incoming_endpoint.h" | 18 #include "mojo/edk/system/incoming_endpoint.h" |
19 #include "mojo/edk/system/message_in_transit.h" | 19 #include "mojo/edk/system/message_in_transit.h" |
20 #include "mojo/edk/system/mutex.h" | 20 #include "mojo/edk/system/mutex.h" |
21 #include "mojo/edk/system/raw_channel.h" | 21 #include "mojo/edk/system/raw_channel.h" |
22 #include "mojo/edk/system/system_impl_export.h" | |
23 #include "mojo/public/c/system/types.h" | 22 #include "mojo/public/c/system/types.h" |
24 #include "mojo/public/cpp/system/macros.h" | 23 #include "mojo/public/cpp/system/macros.h" |
25 | 24 |
26 namespace mojo { | 25 namespace mojo { |
27 | 26 |
28 namespace embedder { | 27 namespace embedder { |
29 class PlatformSupport; | 28 class PlatformSupport; |
30 } | 29 } |
31 | 30 |
32 namespace system { | 31 namespace system { |
(...skipping 10 matching lines...) Expand all Loading... |
43 // thread.) It may be destroyed on any thread, in the sense that the last | 42 // thread.) It may be destroyed on any thread, in the sense that the last |
44 // reference to it may be released on any thread, with the proviso that | 43 // reference to it may be released on any thread, with the proviso that |
45 // |Shutdown()| must have been called first (so the pattern is that a "main" | 44 // |Shutdown()| must have been called first (so the pattern is that a "main" |
46 // reference is kept on its creation thread and is released after |Shutdown()| | 45 // reference is kept on its creation thread and is released after |Shutdown()| |
47 // is called, but other threads may have temporarily "dangling" references). | 46 // is called, but other threads may have temporarily "dangling" references). |
48 // | 47 // |
49 // Note the lock order (in order of allowable acquisition): | 48 // Note the lock order (in order of allowable acquisition): |
50 // |ChannelEndpointClient| (e.g., |MessagePipe|), |ChannelEndpoint|, |Channel|. | 49 // |ChannelEndpointClient| (e.g., |MessagePipe|), |ChannelEndpoint|, |Channel|. |
51 // Thus |Channel| may not call into |ChannelEndpoint| with |Channel|'s lock | 50 // Thus |Channel| may not call into |ChannelEndpoint| with |Channel|'s lock |
52 // held. | 51 // held. |
53 class MOJO_SYSTEM_IMPL_EXPORT Channel final | 52 class Channel final : public base::RefCountedThreadSafe<Channel>, |
54 : public base::RefCountedThreadSafe<Channel>, | 53 public RawChannel::Delegate { |
55 public RawChannel::Delegate { | |
56 public: | 54 public: |
57 // |platform_support| must remain alive until after |Shutdown()| is called. | 55 // |platform_support| must remain alive until after |Shutdown()| is called. |
58 explicit Channel(embedder::PlatformSupport* platform_support); | 56 explicit Channel(embedder::PlatformSupport* platform_support); |
59 | 57 |
60 // This must be called on the creation thread before any other methods are | 58 // 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 | 59 // called, and before references to this object are given to any other |
62 // threads. |raw_channel| should be uninitialized. | 60 // threads. |raw_channel| should be uninitialized. |
63 void Init(std::unique_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; | 61 void Init(std::unique_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; |
64 | 62 |
65 // Sets the channel manager associated with this channel. This should be set | 63 // Sets the channel manager associated with this channel. This should be set |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // if/when we wrap). | 271 // if/when we wrap). |
274 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); | 272 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); |
275 | 273 |
276 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); | 274 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); |
277 }; | 275 }; |
278 | 276 |
279 } // namespace system | 277 } // namespace system |
280 } // namespace mojo | 278 } // namespace mojo |
281 | 279 |
282 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 280 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
OLD | NEW |