Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_IPC_SUPPORT_H_ | 5 #ifndef MOJO_EDK_SYSTEM_IPC_SUPPORT_H_ |
| 6 #define MOJO_EDK_SYSTEM_IPC_SUPPORT_H_ | 6 #define MOJO_EDK_SYSTEM_IPC_SUPPORT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "mojo/edk/embedder/platform_task_runner.h" | |
| 13 #include "mojo/edk/embedder/process_type.h" | 12 #include "mojo/edk/embedder/process_type.h" |
| 14 #include "mojo/edk/embedder/scoped_platform_handle.h" | 13 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 15 #include "mojo/edk/embedder/slave_info.h" | 14 #include "mojo/edk/embedder/slave_info.h" |
| 15 #include "mojo/edk/platform/task_runner.h" | |
| 16 #include "mojo/edk/system/channel_id.h" | 16 #include "mojo/edk/system/channel_id.h" |
| 17 #include "mojo/edk/system/connection_identifier.h" | 17 #include "mojo/edk/system/connection_identifier.h" |
| 18 #include "mojo/edk/system/process_identifier.h" | 18 #include "mojo/edk/system/process_identifier.h" |
| 19 #include "mojo/edk/util/ref_ptr.h" | 19 #include "mojo/edk/util/ref_ptr.h" |
| 20 #include "mojo/public/cpp/system/macros.h" | 20 #include "mojo/public/cpp/system/macros.h" |
| 21 | 21 |
| 22 namespace mojo { | 22 namespace mojo { |
| 23 | 23 |
| 24 namespace embedder { | 24 namespace embedder { |
| 25 class PlatformSupport; | 25 class PlatformSupport; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 55 // be called during/after |ShutdownOnIOThread()|.) | 55 // be called during/after |ShutdownOnIOThread()|.) |
| 56 class IPCSupport { | 56 class IPCSupport { |
| 57 public: | 57 public: |
| 58 // Constructor: initializes for the given |process_type|; |process_delegate| | 58 // Constructor: initializes for the given |process_type|; |process_delegate| |
| 59 // must match the process type. |platform_handle| is only used for slave | 59 // must match the process type. |platform_handle| is only used for slave |
| 60 // processes. | 60 // processes. |
| 61 // | 61 // |
| 62 // All the (pointer) arguments must remain alive (and, in the case of task | 62 // All the (pointer) arguments must remain alive (and, in the case of task |
| 63 // runners, continue to process tasks) until |ShutdownOnIOThread()| has been | 63 // runners, continue to process tasks) until |ShutdownOnIOThread()| has been |
| 64 // called. | 64 // called. |
| 65 IPCSupport( | 65 IPCSupport(embedder::PlatformSupport* platform_support, |
| 66 embedder::PlatformSupport* platform_support, | 66 embedder::ProcessType process_type, |
| 67 embedder::ProcessType process_type, | 67 util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, |
| 68 util::RefPtr<embedder::PlatformTaskRunner>&& delegate_thread_task_runner, | 68 embedder::ProcessDelegate* process_delegate, |
| 69 embedder::ProcessDelegate* process_delegate, | 69 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, |
| 70 util::RefPtr<embedder::PlatformTaskRunner>&& io_thread_task_runner, | 70 embedder::ScopedPlatformHandle platform_handle); |
| 71 embedder::ScopedPlatformHandle platform_handle); | |
| 72 // Note: This object must be shut down before destruction (see | 71 // Note: This object must be shut down before destruction (see |
| 73 // |ShutdownOnIOThread()|). | 72 // |ShutdownOnIOThread()|). |
| 74 ~IPCSupport(); | 73 ~IPCSupport(); |
| 75 | 74 |
| 76 // This must be called (exactly once) on the I/O thread before this object is | 75 // This must be called (exactly once) on the I/O thread before this object is |
| 77 // destroyed (which may happen on any thread). Note: This does *not* call the | 76 // destroyed (which may happen on any thread). Note: This does *not* call the |
| 78 // process delegate's |OnShutdownComplete()|. | 77 // process delegate's |OnShutdownComplete()|. |
| 79 void ShutdownOnIOThread(); | 78 void ShutdownOnIOThread(); |
| 80 | 79 |
| 81 // Generates a new (unique) connection identifier, for use with | 80 // Generates a new (unique) connection identifier, for use with |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 98 // channel may be destroyed using this ID, but only after the callback has | 97 // channel may be destroyed using this ID, but only after the callback has |
| 99 // been run. | 98 // been run. |
| 100 // | 99 // |
| 101 // TODO(vtl): Add some more channel management functionality to this class. | 100 // TODO(vtl): Add some more channel management functionality to this class. |
| 102 // Maybe make this callback interface more sane. | 101 // Maybe make this callback interface more sane. |
| 103 util::RefPtr<MessagePipeDispatcher> ConnectToSlave( | 102 util::RefPtr<MessagePipeDispatcher> ConnectToSlave( |
| 104 const ConnectionIdentifier& connection_id, | 103 const ConnectionIdentifier& connection_id, |
| 105 embedder::SlaveInfo slave_info, | 104 embedder::SlaveInfo slave_info, |
| 106 embedder::ScopedPlatformHandle platform_handle, | 105 embedder::ScopedPlatformHandle platform_handle, |
| 107 const base::Closure& callback, | 106 const base::Closure& callback, |
| 108 util::RefPtr<embedder::PlatformTaskRunner>&& callback_thread_task_runner, | 107 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner, |
| 109 ChannelId* channel_id); | 108 ChannelId* channel_id); |
| 110 | 109 |
| 111 // Called in a slave process to connect it to the master process and thus the | 110 // Called in a slave process to connect it to the master process and thus the |
| 112 // IPC system, creating a |Channel| and an initial message pipe (return a | 111 // IPC system, creating a |Channel| and an initial message pipe (return a |
| 113 // dispatcher for the slave's side). See |ConnectToSlave()|, above. | 112 // dispatcher for the slave's side). See |ConnectToSlave()|, above. |
| 114 // | 113 // |
| 115 // |callback|, |callback_thread_task_runner|, and |channel_id| are as in | 114 // |callback|, |callback_thread_task_runner|, and |channel_id| are as in |
| 116 // |ConnectToSlave()|. | 115 // |ConnectToSlave()|. |
| 117 // | 116 // |
| 118 // TODO(vtl): |ConnectToSlave()|'s channel management TODO also applies here. | 117 // TODO(vtl): |ConnectToSlave()|'s channel management TODO also applies here. |
| 119 util::RefPtr<MessagePipeDispatcher> ConnectToMaster( | 118 util::RefPtr<MessagePipeDispatcher> ConnectToMaster( |
| 120 const ConnectionIdentifier& connection_id, | 119 const ConnectionIdentifier& connection_id, |
| 121 const base::Closure& callback, | 120 const base::Closure& callback, |
| 122 util::RefPtr<embedder::PlatformTaskRunner>&& callback_thread_task_runner, | 121 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner, |
| 123 ChannelId* channel_id); | 122 ChannelId* channel_id); |
| 124 | 123 |
| 125 embedder::ProcessType process_type() const { return process_type_; } | 124 embedder::ProcessType process_type() const { return process_type_; } |
| 126 embedder::ProcessDelegate* process_delegate() const { | 125 embedder::ProcessDelegate* process_delegate() const { |
| 127 return process_delegate_; | 126 return process_delegate_; |
| 128 } | 127 } |
| 129 embedder::PlatformTaskRunner* delegate_thread_task_runner() const { | 128 const util::RefPtr<platform::TaskRunner>& delegate_thread_task_runner() |
|
kulakowski
2015/11/23 19:11:21
Nice.
| |
| 130 return delegate_thread_task_runner_.get(); | 129 const { |
| 130 return delegate_thread_task_runner_; | |
| 131 } | 131 } |
| 132 embedder::PlatformTaskRunner* io_thread_task_runner() const { | 132 const util::RefPtr<platform::TaskRunner>& io_thread_task_runner() const { |
| 133 return io_thread_task_runner_.get(); | 133 return io_thread_task_runner_; |
| 134 } | 134 } |
| 135 // TODO(vtl): The things that use the following should probably be moved into | 135 // TODO(vtl): The things that use the following should probably be moved into |
| 136 // this class. | 136 // this class. |
| 137 ChannelManager* channel_manager() const { return channel_manager_.get(); } | 137 ChannelManager* channel_manager() const { return channel_manager_.get(); } |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 // These test |ConnectToSlaveInternal()| and |ConnectToMasterInternal()|. | 140 // These test |ConnectToSlaveInternal()| and |ConnectToMasterInternal()|. |
| 141 FRIEND_TEST_ALL_PREFIXES(IPCSupportTest, MasterSlaveInternal); | 141 FRIEND_TEST_ALL_PREFIXES(IPCSupportTest, MasterSlaveInternal); |
| 142 FRIEND_TEST_ALL_PREFIXES(IPCSupportTest, MultiprocessMasterSlaveInternal); | 142 FRIEND_TEST_ALL_PREFIXES(IPCSupportTest, MultiprocessMasterSlaveInternal); |
| 143 friend void MultiprocessMasterSlaveInternalTestChildTest(); | 143 friend void MultiprocessMasterSlaveInternalTestChildTest(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 159 // the master and slave (returning the slave's handle). | 159 // the master and slave (returning the slave's handle). |
| 160 embedder::ScopedPlatformHandle ConnectToMasterInternal( | 160 embedder::ScopedPlatformHandle ConnectToMasterInternal( |
| 161 const ConnectionIdentifier& connection_id); | 161 const ConnectionIdentifier& connection_id); |
| 162 | 162 |
| 163 ConnectionManager* connection_manager() const { | 163 ConnectionManager* connection_manager() const { |
| 164 return connection_manager_.get(); | 164 return connection_manager_.get(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // These are all set on construction and reset by |ShutdownOnIOThread()|. | 167 // These are all set on construction and reset by |ShutdownOnIOThread()|. |
| 168 embedder::ProcessType process_type_; | 168 embedder::ProcessType process_type_; |
| 169 util::RefPtr<embedder::PlatformTaskRunner> delegate_thread_task_runner_; | 169 util::RefPtr<platform::TaskRunner> delegate_thread_task_runner_; |
| 170 embedder::ProcessDelegate* process_delegate_; | 170 embedder::ProcessDelegate* process_delegate_; |
| 171 util::RefPtr<embedder::PlatformTaskRunner> io_thread_task_runner_; | 171 util::RefPtr<platform::TaskRunner> io_thread_task_runner_; |
| 172 | 172 |
| 173 std::unique_ptr<ConnectionManager> connection_manager_; | 173 std::unique_ptr<ConnectionManager> connection_manager_; |
| 174 std::unique_ptr<ChannelManager> channel_manager_; | 174 std::unique_ptr<ChannelManager> channel_manager_; |
| 175 | 175 |
| 176 MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupport); | 176 MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupport); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 } // namespace system | 179 } // namespace system |
| 180 } // namespace mojo | 180 } // namespace mojo |
| 181 | 181 |
| 182 #endif // MOJO_EDK_SYSTEM_IPC_SUPPORT_H_ | 182 #endif // MOJO_EDK_SYSTEM_IPC_SUPPORT_H_ |
| OLD | NEW |