Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: mojo/edk/embedder/embedder.cc

Issue 1462083003: Add //mojo/edk/platform and move platform_task_runners.h there. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: update readme Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "mojo/edk/embedder/embedder.h" 5 #include "mojo/edk/embedder/embedder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "mojo/edk/embedder/embedder_internal.h" 13 #include "mojo/edk/embedder/embedder_internal.h"
14 #include "mojo/edk/embedder/master_process_delegate.h" 14 #include "mojo/edk/embedder/master_process_delegate.h"
15 #include "mojo/edk/embedder/platform_support.h" 15 #include "mojo/edk/embedder/platform_support.h"
16 #include "mojo/edk/embedder/process_delegate.h" 16 #include "mojo/edk/embedder/process_delegate.h"
17 #include "mojo/edk/embedder/slave_process_delegate.h" 17 #include "mojo/edk/embedder/slave_process_delegate.h"
18 #include "mojo/edk/system/channel.h" 18 #include "mojo/edk/system/channel.h"
19 #include "mojo/edk/system/channel_manager.h" 19 #include "mojo/edk/system/channel_manager.h"
20 #include "mojo/edk/system/configuration.h" 20 #include "mojo/edk/system/configuration.h"
21 #include "mojo/edk/system/core.h" 21 #include "mojo/edk/system/core.h"
22 #include "mojo/edk/system/ipc_support.h" 22 #include "mojo/edk/system/ipc_support.h"
23 #include "mojo/edk/system/message_pipe_dispatcher.h" 23 #include "mojo/edk/system/message_pipe_dispatcher.h"
24 #include "mojo/edk/system/platform_handle_dispatcher.h" 24 #include "mojo/edk/system/platform_handle_dispatcher.h"
25 #include "mojo/edk/system/raw_channel.h" 25 #include "mojo/edk/system/raw_channel.h"
26 #include "mojo/edk/util/ref_ptr.h" 26 #include "mojo/edk/util/ref_ptr.h"
27 27
28 using mojo::platform::TaskRunner;
28 using mojo::util::RefPtr; 29 using mojo::util::RefPtr;
29 30
30 namespace mojo { 31 namespace mojo {
31 namespace embedder { 32 namespace embedder {
32 33
33 namespace internal { 34 namespace internal {
34 35
35 // Declared in embedder_internal.h. 36 // Declared in embedder_internal.h.
36 PlatformSupport* g_platform_support = nullptr; 37 PlatformSupport* g_platform_support = nullptr;
37 system::Core* g_core = nullptr; 38 system::Core* g_core = nullptr;
(...skipping 20 matching lines...) Expand all
58 CHECK_GT(new_counter_value, 0); 59 CHECK_GT(new_counter_value, 0);
59 // Use "negative" values for these IDs, so that we'll also be able to use 60 // Use "negative" values for these IDs, so that we'll also be able to use
60 // "positive" "process identifiers" (see connection_manager.h) as IDs (and 61 // "positive" "process identifiers" (see connection_manager.h) as IDs (and
61 // they won't conflict). 62 // they won't conflict).
62 return static_cast<system::ChannelId>(-new_counter_value); 63 return static_cast<system::ChannelId>(-new_counter_value);
63 } 64 }
64 65
65 // Note: Called on the I/O thread. 66 // Note: Called on the I/O thread.
66 void ShutdownIPCSupportHelper() { 67 void ShutdownIPCSupportHelper() {
67 // Save these before they get nuked by |ShutdownChannelOnIOThread()|. 68 // Save these before they get nuked by |ShutdownChannelOnIOThread()|.
68 RefPtr<PlatformTaskRunner> delegate_thread_task_runner( 69 RefPtr<TaskRunner> delegate_thread_task_runner(
69 internal::g_ipc_support->delegate_thread_task_runner()); 70 internal::g_ipc_support->delegate_thread_task_runner());
70 ProcessDelegate* process_delegate = 71 ProcessDelegate* process_delegate =
71 internal::g_ipc_support->process_delegate(); 72 internal::g_ipc_support->process_delegate();
72 73
73 ShutdownIPCSupportOnIOThread(); 74 ShutdownIPCSupportOnIOThread();
74 75
75 delegate_thread_task_runner->PostTask( 76 delegate_thread_task_runner->PostTask(
76 base::Bind(&ProcessDelegate::OnShutdownComplete, 77 base::Bind(&ProcessDelegate::OnShutdownComplete,
77 base::Unretained(process_delegate))); 78 base::Unretained(process_delegate)));
78 } 79 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE) 133 if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE)
133 return MOJO_RESULT_INVALID_ARGUMENT; 134 return MOJO_RESULT_INVALID_ARGUMENT;
134 135
135 *platform_handle = 136 *platform_handle =
136 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) 137 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get())
137 ->PassPlatformHandle(); 138 ->PassPlatformHandle();
138 return MOJO_RESULT_OK; 139 return MOJO_RESULT_OK;
139 } 140 }
140 141
141 void InitIPCSupport(ProcessType process_type, 142 void InitIPCSupport(ProcessType process_type,
142 RefPtr<PlatformTaskRunner>&& delegate_thread_task_runner, 143 RefPtr<TaskRunner>&& delegate_thread_task_runner,
143 ProcessDelegate* process_delegate, 144 ProcessDelegate* process_delegate,
144 RefPtr<PlatformTaskRunner>&& io_thread_task_runner, 145 RefPtr<TaskRunner>&& io_thread_task_runner,
145 ScopedPlatformHandle platform_handle) { 146 ScopedPlatformHandle platform_handle) {
146 // |Init()| must have already been called. 147 // |Init()| must have already been called.
147 DCHECK(internal::g_core); 148 DCHECK(internal::g_core);
148 // And not |InitIPCSupport()| (without |ShutdownIPCSupport()|). 149 // And not |InitIPCSupport()| (without |ShutdownIPCSupport()|).
149 DCHECK(!internal::g_ipc_support); 150 DCHECK(!internal::g_ipc_support);
150 151
151 internal::g_ipc_support = new system::IPCSupport( 152 internal::g_ipc_support = new system::IPCSupport(
152 internal::g_platform_support, process_type, 153 internal::g_platform_support, process_type,
153 std::move(delegate_thread_task_runner), process_delegate, 154 std::move(delegate_thread_task_runner), process_delegate,
154 std::move(io_thread_task_runner), platform_handle.Pass()); 155 std::move(io_thread_task_runner), platform_handle.Pass());
(...skipping 11 matching lines...) Expand all
166 DCHECK(internal::g_ipc_support); 167 DCHECK(internal::g_ipc_support);
167 168
168 internal::g_ipc_support->io_thread_task_runner()->PostTask( 169 internal::g_ipc_support->io_thread_task_runner()->PostTask(
169 base::Bind(&ShutdownIPCSupportHelper)); 170 base::Bind(&ShutdownIPCSupportHelper));
170 } 171 }
171 172
172 ScopedMessagePipeHandle ConnectToSlave( 173 ScopedMessagePipeHandle ConnectToSlave(
173 SlaveInfo slave_info, 174 SlaveInfo slave_info,
174 ScopedPlatformHandle platform_handle, 175 ScopedPlatformHandle platform_handle,
175 const base::Closure& did_connect_to_slave_callback, 176 const base::Closure& did_connect_to_slave_callback,
176 RefPtr<PlatformTaskRunner>&& did_connect_to_slave_runner, 177 RefPtr<TaskRunner>&& did_connect_to_slave_runner,
177 std::string* platform_connection_id, 178 std::string* platform_connection_id,
178 ChannelInfo** channel_info) { 179 ChannelInfo** channel_info) {
179 DCHECK(platform_connection_id); 180 DCHECK(platform_connection_id);
180 DCHECK(channel_info); 181 DCHECK(channel_info);
181 DCHECK(internal::g_ipc_support); 182 DCHECK(internal::g_ipc_support);
182 183
183 system::ConnectionIdentifier connection_id = 184 system::ConnectionIdentifier connection_id =
184 internal::g_ipc_support->GenerateConnectionIdentifier(); 185 internal::g_ipc_support->GenerateConnectionIdentifier();
185 *platform_connection_id = connection_id.ToString(); 186 *platform_connection_id = connection_id.ToString();
186 system::ChannelId channel_id = system::kInvalidChannelId; 187 system::ChannelId channel_id = system::kInvalidChannelId;
187 RefPtr<system::MessagePipeDispatcher> dispatcher = 188 RefPtr<system::MessagePipeDispatcher> dispatcher =
188 internal::g_ipc_support->ConnectToSlave( 189 internal::g_ipc_support->ConnectToSlave(
189 connection_id, slave_info, platform_handle.Pass(), 190 connection_id, slave_info, platform_handle.Pass(),
190 did_connect_to_slave_callback, std::move(did_connect_to_slave_runner), 191 did_connect_to_slave_callback, std::move(did_connect_to_slave_runner),
191 &channel_id); 192 &channel_id);
192 *channel_info = new ChannelInfo(channel_id); 193 *channel_info = new ChannelInfo(channel_id);
193 194
194 ScopedMessagePipeHandle rv( 195 ScopedMessagePipeHandle rv(
195 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 196 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
196 CHECK(rv.is_valid()); 197 CHECK(rv.is_valid());
197 return rv; 198 return rv;
198 } 199 }
199 200
200 ScopedMessagePipeHandle ConnectToMaster( 201 ScopedMessagePipeHandle ConnectToMaster(
201 const std::string& platform_connection_id, 202 const std::string& platform_connection_id,
202 const base::Closure& did_connect_to_master_callback, 203 const base::Closure& did_connect_to_master_callback,
203 RefPtr<PlatformTaskRunner>&& did_connect_to_master_runner, 204 RefPtr<TaskRunner>&& did_connect_to_master_runner,
204 ChannelInfo** channel_info) { 205 ChannelInfo** channel_info) {
205 DCHECK(channel_info); 206 DCHECK(channel_info);
206 DCHECK(internal::g_ipc_support); 207 DCHECK(internal::g_ipc_support);
207 208
208 bool ok = false; 209 bool ok = false;
209 system::ConnectionIdentifier connection_id = 210 system::ConnectionIdentifier connection_id =
210 system::ConnectionIdentifier::FromString(platform_connection_id, &ok); 211 system::ConnectionIdentifier::FromString(platform_connection_id, &ok);
211 CHECK(ok); 212 CHECK(ok);
212 213
213 system::ChannelId channel_id = system::kInvalidChannelId; 214 system::ChannelId channel_id = system::kInvalidChannelId;
(...skipping 27 matching lines...) Expand all
241 242
242 ScopedMessagePipeHandle rv( 243 ScopedMessagePipeHandle rv(
243 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 244 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
244 CHECK(rv.is_valid()); 245 CHECK(rv.is_valid());
245 return rv; 246 return rv;
246 } 247 }
247 248
248 ScopedMessagePipeHandle CreateChannel( 249 ScopedMessagePipeHandle CreateChannel(
249 ScopedPlatformHandle platform_handle, 250 ScopedPlatformHandle platform_handle,
250 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, 251 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback,
251 RefPtr<PlatformTaskRunner>&& did_create_channel_runner) { 252 RefPtr<TaskRunner>&& did_create_channel_runner) {
252 DCHECK(platform_handle.is_valid()); 253 DCHECK(platform_handle.is_valid());
253 DCHECK(!did_create_channel_callback.is_null()); 254 DCHECK(!did_create_channel_callback.is_null());
254 DCHECK(internal::g_ipc_support); 255 DCHECK(internal::g_ipc_support);
255 256
256 system::ChannelManager* channel_manager = 257 system::ChannelManager* channel_manager =
257 internal::g_ipc_support->channel_manager(); 258 internal::g_ipc_support->channel_manager();
258 259
259 system::ChannelId channel_id = MakeChannelId(); 260 system::ChannelId channel_id = MakeChannelId();
260 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id)); 261 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id));
261 RefPtr<system::MessagePipeDispatcher> dispatcher = 262 RefPtr<system::MessagePipeDispatcher> dispatcher =
(...skipping 17 matching lines...) Expand all
279 280
280 system::ChannelManager* channel_manager = 281 system::ChannelManager* channel_manager =
281 internal::g_ipc_support->channel_manager(); 282 internal::g_ipc_support->channel_manager();
282 channel_manager->ShutdownChannelOnIOThread(channel_info->channel_id); 283 channel_manager->ShutdownChannelOnIOThread(channel_info->channel_id);
283 delete channel_info; 284 delete channel_info;
284 } 285 }
285 286
286 // TODO(vtl): Write tests for this. 287 // TODO(vtl): Write tests for this.
287 void DestroyChannel(ChannelInfo* channel_info, 288 void DestroyChannel(ChannelInfo* channel_info,
288 const base::Closure& did_destroy_channel_callback, 289 const base::Closure& did_destroy_channel_callback,
289 RefPtr<PlatformTaskRunner>&& did_destroy_channel_runner) { 290 RefPtr<TaskRunner>&& did_destroy_channel_runner) {
290 DCHECK(channel_info); 291 DCHECK(channel_info);
291 DCHECK(channel_info->channel_id); 292 DCHECK(channel_info->channel_id);
292 DCHECK(!did_destroy_channel_callback.is_null()); 293 DCHECK(!did_destroy_channel_callback.is_null());
293 DCHECK(internal::g_ipc_support); 294 DCHECK(internal::g_ipc_support);
294 295
295 system::ChannelManager* channel_manager = 296 system::ChannelManager* channel_manager =
296 internal::g_ipc_support->channel_manager(); 297 internal::g_ipc_support->channel_manager();
297 channel_manager->ShutdownChannel(channel_info->channel_id, 298 channel_manager->ShutdownChannel(channel_info->channel_id,
298 did_destroy_channel_callback, 299 did_destroy_channel_callback,
299 std::move(did_destroy_channel_runner)); 300 std::move(did_destroy_channel_runner));
300 delete channel_info; 301 delete channel_info;
301 } 302 }
302 303
303 void WillDestroyChannelSoon(ChannelInfo* channel_info) { 304 void WillDestroyChannelSoon(ChannelInfo* channel_info) {
304 DCHECK(channel_info); 305 DCHECK(channel_info);
305 DCHECK(internal::g_ipc_support); 306 DCHECK(internal::g_ipc_support);
306 307
307 system::ChannelManager* channel_manager = 308 system::ChannelManager* channel_manager =
308 internal::g_ipc_support->channel_manager(); 309 internal::g_ipc_support->channel_manager();
309 channel_manager->WillShutdownChannel(channel_info->channel_id); 310 channel_manager->WillShutdownChannel(channel_info->channel_id);
310 } 311 }
311 312
312 } // namespace embedder 313 } // namespace embedder
313 } // namespace mojo 314 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698