| 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 "mojo/edk/platform/scoped_platform_handle.h" | 13 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 14 #include "mojo/edk/platform/task_runner.h" |
| 14 #include "mojo/edk/system/channel_endpoint.h" | 15 #include "mojo/edk/system/channel_endpoint.h" |
| 15 #include "mojo/edk/system/channel_endpoint_id.h" | 16 #include "mojo/edk/system/channel_endpoint_id.h" |
| 16 #include "mojo/edk/system/incoming_endpoint.h" | 17 #include "mojo/edk/system/incoming_endpoint.h" |
| 17 #include "mojo/edk/system/message_in_transit.h" | 18 #include "mojo/edk/system/message_in_transit.h" |
| 18 #include "mojo/edk/system/raw_channel.h" | 19 #include "mojo/edk/system/raw_channel.h" |
| 19 #include "mojo/edk/util/mutex.h" | 20 #include "mojo/edk/util/mutex.h" |
| 20 #include "mojo/edk/util/ref_counted.h" | 21 #include "mojo/edk/util/ref_counted.h" |
| 21 #include "mojo/edk/util/ref_ptr.h" | 22 #include "mojo/edk/util/ref_ptr.h" |
| 22 #include "mojo/edk/util/thread_annotations.h" | 23 #include "mojo/edk/util/thread_annotations.h" |
| 23 #include "mojo/edk/util/thread_checker.h" | 24 #include "mojo/edk/util/thread_checker.h" |
| 24 #include "mojo/public/c/system/types.h" | 25 #include "mojo/public/c/system/types.h" |
| 25 #include "mojo/public/cpp/system/macros.h" | 26 #include "mojo/public/cpp/system/macros.h" |
| 26 | 27 |
| 27 namespace mojo { | 28 namespace mojo { |
| 28 | 29 |
| 29 namespace embedder { | 30 namespace embedder { |
| 30 class PlatformSupport; | 31 class PlatformSupport; |
| 31 } | 32 } |
| 32 | 33 |
| 34 namespace platform { |
| 35 class PlatformHandleWatcher; |
| 36 } |
| 37 |
| 33 namespace system { | 38 namespace system { |
| 34 | 39 |
| 35 class ChannelEndpointClient; | 40 class ChannelEndpointClient; |
| 36 class ChannelManager; | 41 class ChannelManager; |
| 37 class MessageInTransitQueue; | 42 class MessageInTransitQueue; |
| 38 | 43 |
| 39 // This class is mostly thread-safe. It must be created on an I/O thread. | 44 // This class is mostly thread-safe. It may be created and destroyed on any |
| 40 // |Init()| must be called on that same thread before it becomes thread-safe (in | 45 // thread. However, |Init()| must be called on an I/O thread before other |
| 41 // particular, before references are given to any other thread) and |Shutdown()| | 46 // methods are called. Before destruction, |Shutdown()| must be called on that |
| 42 // must be called on that same thread before destruction. Its public methods are | 47 // same thread, after which other methods may not be called. Subject to these |
| 43 // otherwise thread-safe. (Many private methods are restricted to the creation | 48 // restrictions, its public methods are otherwise thread-safe. (Many private |
| 44 // thread.) It may be destroyed on any thread, in the sense that the last | 49 // methods are restricted to the I/O thread.) |
| 45 // reference to it may be released on any thread, with the proviso that | |
| 46 // |Shutdown()| must have been called first (so the pattern is that a "main" | |
| 47 // reference is kept on its creation thread and is released after |Shutdown()| | |
| 48 // is called, but other threads may have temporarily "dangling" references). | |
| 49 // | 50 // |
| 50 // Note the lock order (in order of allowable acquisition): | 51 // Note the lock order (in order of allowable acquisition): |
| 51 // |ChannelEndpointClient| (e.g., |MessagePipe|), |ChannelEndpoint|, |Channel|. | 52 // |ChannelEndpointClient| (e.g., |MessagePipe|), |ChannelEndpoint|, |Channel|. |
| 52 // Thus |Channel| may not call into |ChannelEndpoint| with |Channel|'s lock | 53 // Thus |Channel| may not call into |ChannelEndpoint| with |Channel|'s lock |
| 53 // held. | 54 // held. |
| 54 class Channel final : public util::RefCountedThreadSafe<Channel>, | 55 class Channel final : public util::RefCountedThreadSafe<Channel>, |
| 55 public RawChannel::Delegate { | 56 public RawChannel::Delegate { |
| 56 public: | 57 public: |
| 57 // Note: Use |util::MakeRefCounted<Channel>()|. | 58 // Note: Use |util::MakeRefCounted<Channel>()|. |
| 58 | 59 |
| 59 // This must be called on the creation thread before any other methods are | 60 // This must be called on an I/O thread before any other methods are called. |
| 60 // called, and before references to this object are given to any other | 61 // |io_task_runner| and |io_watcher| should be for this thread. |raw_channel| |
| 61 // threads. |raw_channel| should be uninitialized. | 62 // should be uninitialized. |
| 62 void Init(std::unique_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; | 63 void Init(util::RefPtr<platform::TaskRunner>&& io_task_runner, |
| 64 platform::PlatformHandleWatcher* io_watcher, |
| 65 std::unique_ptr<RawChannel> raw_channel) MOJO_NOT_THREAD_SAFE; |
| 63 | 66 |
| 64 // Sets the channel manager associated with this channel. This should be set | 67 // Sets the channel manager associated with this channel. This should be set |
| 65 // at most once and only called before |WillShutdownSoon()| (and | 68 // at most once and only called before |WillShutdownSoon()| (and |
| 66 // |Shutdown()|). (This is called by the channel manager when adding a | 69 // |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 | 70 // channel; this should not be called before the channel is managed by the |
| 68 // channel manager.) | 71 // channel manager.) |
| 69 void SetChannelManager(ChannelManager* channel_manager); | 72 void SetChannelManager(ChannelManager* channel_manager); |
| 70 | 73 |
| 71 // This must be called on the creation thread before destruction (which can | 74 // This must be called on the creation thread before destruction (which can |
| 72 // happen on any thread). | 75 // happen on any thread). |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 // if/when we wrap). | 284 // if/when we wrap). |
| 282 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); | 285 RemoteChannelEndpointIdGenerator remote_id_generator_ MOJO_GUARDED_BY(mutex_); |
| 283 | 286 |
| 284 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); | 287 MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); |
| 285 }; | 288 }; |
| 286 | 289 |
| 287 } // namespace system | 290 } // namespace system |
| 288 } // namespace mojo | 291 } // namespace mojo |
| 289 | 292 |
| 290 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 293 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
| OLD | NEW |