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

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

Issue 1423713009: EDK: Move ref counting classes to mojo/edk/util. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « mojo/edk/embedder/BUILD.gn ('k') | mojo/edk/embedder/system_impl_private_entrypoints.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/task_runner.h" 14 #include "base/task_runner.h"
15 #include "mojo/edk/embedder/embedder_internal.h" 15 #include "mojo/edk/embedder/embedder_internal.h"
16 #include "mojo/edk/embedder/master_process_delegate.h" 16 #include "mojo/edk/embedder/master_process_delegate.h"
17 #include "mojo/edk/embedder/platform_support.h" 17 #include "mojo/edk/embedder/platform_support.h"
18 #include "mojo/edk/embedder/process_delegate.h" 18 #include "mojo/edk/embedder/process_delegate.h"
19 #include "mojo/edk/embedder/slave_process_delegate.h" 19 #include "mojo/edk/embedder/slave_process_delegate.h"
20 #include "mojo/edk/system/channel.h" 20 #include "mojo/edk/system/channel.h"
21 #include "mojo/edk/system/channel_manager.h" 21 #include "mojo/edk/system/channel_manager.h"
22 #include "mojo/edk/system/configuration.h" 22 #include "mojo/edk/system/configuration.h"
23 #include "mojo/edk/system/core.h" 23 #include "mojo/edk/system/core.h"
24 #include "mojo/edk/system/ipc_support.h" 24 #include "mojo/edk/system/ipc_support.h"
25 #include "mojo/edk/system/message_pipe_dispatcher.h" 25 #include "mojo/edk/system/message_pipe_dispatcher.h"
26 #include "mojo/edk/system/platform_handle_dispatcher.h" 26 #include "mojo/edk/system/platform_handle_dispatcher.h"
27 #include "mojo/edk/system/raw_channel.h" 27 #include "mojo/edk/system/raw_channel.h"
28 #include "mojo/edk/system/ref_ptr.h" 28 #include "mojo/edk/util/ref_ptr.h"
29
30 using mojo::util::RefPtr;
29 31
30 namespace mojo { 32 namespace mojo {
31 namespace embedder { 33 namespace embedder {
32 34
33 namespace internal { 35 namespace internal {
34 36
35 // Declared in embedder_internal.h. 37 // Declared in embedder_internal.h.
36 PlatformSupport* g_platform_support = nullptr; 38 PlatformSupport* g_platform_support = nullptr;
37 system::Core* g_core = nullptr; 39 system::Core* g_core = nullptr;
38 system::IPCSupport* g_ipc_support = nullptr; 40 system::IPCSupport* g_ipc_support = nullptr;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 std::string* platform_connection_id, 179 std::string* platform_connection_id,
178 ChannelInfo** channel_info) { 180 ChannelInfo** channel_info) {
179 DCHECK(platform_connection_id); 181 DCHECK(platform_connection_id);
180 DCHECK(channel_info); 182 DCHECK(channel_info);
181 DCHECK(internal::g_ipc_support); 183 DCHECK(internal::g_ipc_support);
182 184
183 system::ConnectionIdentifier connection_id = 185 system::ConnectionIdentifier connection_id =
184 internal::g_ipc_support->GenerateConnectionIdentifier(); 186 internal::g_ipc_support->GenerateConnectionIdentifier();
185 *platform_connection_id = connection_id.ToString(); 187 *platform_connection_id = connection_id.ToString();
186 system::ChannelId channel_id = system::kInvalidChannelId; 188 system::ChannelId channel_id = system::kInvalidChannelId;
187 system::RefPtr<system::MessagePipeDispatcher> dispatcher = 189 RefPtr<system::MessagePipeDispatcher> dispatcher =
188 internal::g_ipc_support->ConnectToSlave( 190 internal::g_ipc_support->ConnectToSlave(
189 connection_id, slave_info, platform_handle.Pass(), 191 connection_id, slave_info, platform_handle.Pass(),
190 did_connect_to_slave_callback, std::move(did_connect_to_slave_runner), 192 did_connect_to_slave_callback, std::move(did_connect_to_slave_runner),
191 &channel_id); 193 &channel_id);
192 *channel_info = new ChannelInfo(channel_id); 194 *channel_info = new ChannelInfo(channel_id);
193 195
194 ScopedMessagePipeHandle rv( 196 ScopedMessagePipeHandle rv(
195 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 197 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
196 CHECK(rv.is_valid()); 198 CHECK(rv.is_valid());
197 return rv; 199 return rv;
198 } 200 }
199 201
200 ScopedMessagePipeHandle ConnectToMaster( 202 ScopedMessagePipeHandle ConnectToMaster(
201 const std::string& platform_connection_id, 203 const std::string& platform_connection_id,
202 const base::Closure& did_connect_to_master_callback, 204 const base::Closure& did_connect_to_master_callback,
203 PlatformTaskRunnerRefPtr did_connect_to_master_runner, 205 PlatformTaskRunnerRefPtr did_connect_to_master_runner,
204 ChannelInfo** channel_info) { 206 ChannelInfo** channel_info) {
205 DCHECK(channel_info); 207 DCHECK(channel_info);
206 DCHECK(internal::g_ipc_support); 208 DCHECK(internal::g_ipc_support);
207 209
208 bool ok = false; 210 bool ok = false;
209 system::ConnectionIdentifier connection_id = 211 system::ConnectionIdentifier connection_id =
210 system::ConnectionIdentifier::FromString(platform_connection_id, &ok); 212 system::ConnectionIdentifier::FromString(platform_connection_id, &ok);
211 CHECK(ok); 213 CHECK(ok);
212 214
213 system::ChannelId channel_id = system::kInvalidChannelId; 215 system::ChannelId channel_id = system::kInvalidChannelId;
214 system::RefPtr<system::MessagePipeDispatcher> dispatcher = 216 RefPtr<system::MessagePipeDispatcher> dispatcher =
215 internal::g_ipc_support->ConnectToMaster( 217 internal::g_ipc_support->ConnectToMaster(
216 connection_id, did_connect_to_master_callback, 218 connection_id, did_connect_to_master_callback,
217 std::move(did_connect_to_master_runner), &channel_id); 219 std::move(did_connect_to_master_runner), &channel_id);
218 *channel_info = new ChannelInfo(channel_id); 220 *channel_info = new ChannelInfo(channel_id);
219 221
220 ScopedMessagePipeHandle rv( 222 ScopedMessagePipeHandle rv(
221 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 223 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
222 CHECK(rv.is_valid()); 224 CHECK(rv.is_valid());
223 return rv; 225 return rv;
224 } 226 }
225 227
226 // TODO(vtl): Write tests for this. 228 // TODO(vtl): Write tests for this.
227 ScopedMessagePipeHandle CreateChannelOnIOThread( 229 ScopedMessagePipeHandle CreateChannelOnIOThread(
228 ScopedPlatformHandle platform_handle, 230 ScopedPlatformHandle platform_handle,
229 ChannelInfo** channel_info) { 231 ChannelInfo** channel_info) {
230 DCHECK(platform_handle.is_valid()); 232 DCHECK(platform_handle.is_valid());
231 DCHECK(channel_info); 233 DCHECK(channel_info);
232 DCHECK(internal::g_ipc_support); 234 DCHECK(internal::g_ipc_support);
233 235
234 system::ChannelManager* channel_manager = 236 system::ChannelManager* channel_manager =
235 internal::g_ipc_support->channel_manager(); 237 internal::g_ipc_support->channel_manager();
236 238
237 *channel_info = new ChannelInfo(MakeChannelId()); 239 *channel_info = new ChannelInfo(MakeChannelId());
238 system::RefPtr<system::MessagePipeDispatcher> dispatcher = 240 RefPtr<system::MessagePipeDispatcher> dispatcher =
239 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id, 241 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id,
240 platform_handle.Pass()); 242 platform_handle.Pass());
241 243
242 ScopedMessagePipeHandle rv( 244 ScopedMessagePipeHandle rv(
243 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 245 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
244 CHECK(rv.is_valid()); 246 CHECK(rv.is_valid());
245 return rv; 247 return rv;
246 } 248 }
247 249
248 ScopedMessagePipeHandle CreateChannel( 250 ScopedMessagePipeHandle CreateChannel(
249 ScopedPlatformHandle platform_handle, 251 ScopedPlatformHandle platform_handle,
250 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, 252 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback,
251 PlatformTaskRunnerRefPtr did_create_channel_runner) { 253 PlatformTaskRunnerRefPtr did_create_channel_runner) {
252 DCHECK(platform_handle.is_valid()); 254 DCHECK(platform_handle.is_valid());
253 DCHECK(!did_create_channel_callback.is_null()); 255 DCHECK(!did_create_channel_callback.is_null());
254 DCHECK(internal::g_ipc_support); 256 DCHECK(internal::g_ipc_support);
255 257
256 system::ChannelManager* channel_manager = 258 system::ChannelManager* channel_manager =
257 internal::g_ipc_support->channel_manager(); 259 internal::g_ipc_support->channel_manager();
258 260
259 system::ChannelId channel_id = MakeChannelId(); 261 system::ChannelId channel_id = MakeChannelId();
260 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id)); 262 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id));
261 system::RefPtr<system::MessagePipeDispatcher> dispatcher = 263 RefPtr<system::MessagePipeDispatcher> dispatcher =
262 channel_manager->CreateChannel( 264 channel_manager->CreateChannel(
263 channel_id, platform_handle.Pass(), 265 channel_id, platform_handle.Pass(),
264 base::Bind(did_create_channel_callback, 266 base::Bind(did_create_channel_callback,
265 base::Unretained(channel_info.release())), 267 base::Unretained(channel_info.release())),
266 did_create_channel_runner); 268 did_create_channel_runner);
267 269
268 ScopedMessagePipeHandle rv( 270 ScopedMessagePipeHandle rv(
269 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get()))); 271 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
270 CHECK(rv.is_valid()); 272 CHECK(rv.is_valid());
271 return rv; 273 return rv;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 DCHECK(channel_info); 306 DCHECK(channel_info);
305 DCHECK(internal::g_ipc_support); 307 DCHECK(internal::g_ipc_support);
306 308
307 system::ChannelManager* channel_manager = 309 system::ChannelManager* channel_manager =
308 internal::g_ipc_support->channel_manager(); 310 internal::g_ipc_support->channel_manager();
309 channel_manager->WillShutdownChannel(channel_info->channel_id); 311 channel_manager->WillShutdownChannel(channel_info->channel_id);
310 } 312 }
311 313
312 } // namespace embedder 314 } // namespace embedder
313 } // namespace mojo 315 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/BUILD.gn ('k') | mojo/edk/embedder/system_impl_private_entrypoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698