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

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

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change Created 5 years, 2 months 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 | « no previous file | 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 "base/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/task_runner.h" 12 #include "base/task_runner.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/system/ref_ptr.h"
26 27
27 namespace mojo { 28 namespace mojo {
28 namespace embedder { 29 namespace embedder {
29 30
30 namespace internal { 31 namespace internal {
31 32
32 // Declared in embedder_internal.h. 33 // Declared in embedder_internal.h.
33 PlatformSupport* g_platform_support = nullptr; 34 PlatformSupport* g_platform_support = nullptr;
34 system::Core* g_core = nullptr; 35 system::Core* g_core = nullptr;
35 system::IPCSupport* g_ipc_support = nullptr; 36 system::IPCSupport* g_ipc_support = nullptr;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 MojoHandleSignals signals, 96 MojoHandleSignals signals,
96 const base::Callback<void(MojoResult)>& callback) { 97 const base::Callback<void(MojoResult)>& callback) {
97 return internal::g_core->AsyncWait(handle, signals, callback); 98 return internal::g_core->AsyncWait(handle, signals, callback);
98 } 99 }
99 100
100 MojoResult CreatePlatformHandleWrapper( 101 MojoResult CreatePlatformHandleWrapper(
101 ScopedPlatformHandle platform_handle, 102 ScopedPlatformHandle platform_handle,
102 MojoHandle* platform_handle_wrapper_handle) { 103 MojoHandle* platform_handle_wrapper_handle) {
103 DCHECK(platform_handle_wrapper_handle); 104 DCHECK(platform_handle_wrapper_handle);
104 105
105 scoped_refptr<system::Dispatcher> dispatcher = 106 auto dispatcher =
106 system::PlatformHandleDispatcher::Create(platform_handle.Pass()); 107 system::PlatformHandleDispatcher::Create(platform_handle.Pass());
107 108
108 DCHECK(internal::g_core); 109 DCHECK(internal::g_core);
109 MojoHandle h = internal::g_core->AddDispatcher(dispatcher); 110 MojoHandle h = internal::g_core->AddDispatcher(dispatcher.get());
110 if (h == MOJO_HANDLE_INVALID) { 111 if (h == MOJO_HANDLE_INVALID) {
111 LOG(ERROR) << "Handle table full"; 112 LOG(ERROR) << "Handle table full";
112 dispatcher->Close(); 113 dispatcher->Close();
113 return MOJO_RESULT_RESOURCE_EXHAUSTED; 114 return MOJO_RESULT_RESOURCE_EXHAUSTED;
114 } 115 }
115 116
116 *platform_handle_wrapper_handle = h; 117 *platform_handle_wrapper_handle = h;
117 return MOJO_RESULT_OK; 118 return MOJO_RESULT_OK;
118 } 119 }
119 120
120 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, 121 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
121 ScopedPlatformHandle* platform_handle) { 122 ScopedPlatformHandle* platform_handle) {
122 DCHECK(platform_handle); 123 DCHECK(platform_handle);
123 124
124 DCHECK(internal::g_core); 125 DCHECK(internal::g_core);
125 scoped_refptr<system::Dispatcher> dispatcher( 126 auto dispatcher =
126 internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); 127 internal::g_core->GetDispatcher(platform_handle_wrapper_handle);
127 if (!dispatcher) 128 if (!dispatcher)
128 return MOJO_RESULT_INVALID_ARGUMENT; 129 return MOJO_RESULT_INVALID_ARGUMENT;
129 130
130 if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE) 131 if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE)
131 return MOJO_RESULT_INVALID_ARGUMENT; 132 return MOJO_RESULT_INVALID_ARGUMENT;
132 133
133 *platform_handle = 134 *platform_handle =
134 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) 135 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get())
135 ->PassPlatformHandle() 136 ->PassPlatformHandle()
136 .Pass(); 137 .Pass();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 scoped_refptr<system::MessagePipeDispatcher> dispatcher = 188 system::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, did_connect_to_slave_runner.Pass(), 191 did_connect_to_slave_callback, did_connect_to_slave_runner.Pass(),
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))); 196 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
196 CHECK(rv.is_valid()); 197 CHECK(rv.is_valid());
197 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it 198 return rv;
198 // once that's fixed.
199 return rv.Pass();
200 } 199 }
201 200
202 ScopedMessagePipeHandle ConnectToMaster( 201 ScopedMessagePipeHandle ConnectToMaster(
203 const std::string& platform_connection_id, 202 const std::string& platform_connection_id,
204 const base::Closure& did_connect_to_master_callback, 203 const base::Closure& did_connect_to_master_callback,
205 scoped_refptr<base::TaskRunner> did_connect_to_master_runner, 204 scoped_refptr<base::TaskRunner> did_connect_to_master_runner,
206 ChannelInfo** channel_info) { 205 ChannelInfo** channel_info) {
207 DCHECK(channel_info); 206 DCHECK(channel_info);
208 DCHECK(internal::g_ipc_support); 207 DCHECK(internal::g_ipc_support);
209 208
210 bool ok = false; 209 bool ok = false;
211 system::ConnectionIdentifier connection_id = 210 system::ConnectionIdentifier connection_id =
212 system::ConnectionIdentifier::FromString(platform_connection_id, &ok); 211 system::ConnectionIdentifier::FromString(platform_connection_id, &ok);
213 CHECK(ok); 212 CHECK(ok);
214 213
215 system::ChannelId channel_id = system::kInvalidChannelId; 214 system::ChannelId channel_id = system::kInvalidChannelId;
216 scoped_refptr<system::MessagePipeDispatcher> dispatcher = 215 system::RefPtr<system::MessagePipeDispatcher> dispatcher =
217 internal::g_ipc_support->ConnectToMaster( 216 internal::g_ipc_support->ConnectToMaster(
218 connection_id, did_connect_to_master_callback, 217 connection_id, did_connect_to_master_callback,
219 did_connect_to_master_runner.Pass(), &channel_id); 218 did_connect_to_master_runner.Pass(), &channel_id);
220 *channel_info = new ChannelInfo(channel_id); 219 *channel_info = new ChannelInfo(channel_id);
221 220
222 ScopedMessagePipeHandle rv( 221 ScopedMessagePipeHandle rv(
223 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); 222 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
224 CHECK(rv.is_valid()); 223 CHECK(rv.is_valid());
225 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it 224 return rv;
226 // once that's fixed.
227 return rv.Pass();
228 } 225 }
229 226
230 // TODO(vtl): Write tests for this. 227 // TODO(vtl): Write tests for this.
231 ScopedMessagePipeHandle CreateChannelOnIOThread( 228 ScopedMessagePipeHandle CreateChannelOnIOThread(
232 ScopedPlatformHandle platform_handle, 229 ScopedPlatformHandle platform_handle,
233 ChannelInfo** channel_info) { 230 ChannelInfo** channel_info) {
234 DCHECK(platform_handle.is_valid()); 231 DCHECK(platform_handle.is_valid());
235 DCHECK(channel_info); 232 DCHECK(channel_info);
236 DCHECK(internal::g_ipc_support); 233 DCHECK(internal::g_ipc_support);
237 234
238 system::ChannelManager* channel_manager = 235 system::ChannelManager* channel_manager =
239 internal::g_ipc_support->channel_manager(); 236 internal::g_ipc_support->channel_manager();
240 237
241 *channel_info = new ChannelInfo(MakeChannelId()); 238 *channel_info = new ChannelInfo(MakeChannelId());
242 scoped_refptr<system::MessagePipeDispatcher> dispatcher = 239 system::RefPtr<system::MessagePipeDispatcher> dispatcher =
243 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id, 240 channel_manager->CreateChannelOnIOThread((*channel_info)->channel_id,
244 platform_handle.Pass()); 241 platform_handle.Pass());
245 242
246 ScopedMessagePipeHandle rv( 243 ScopedMessagePipeHandle rv(
247 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); 244 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
248 CHECK(rv.is_valid()); 245 CHECK(rv.is_valid());
249 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it 246 return rv;
250 // once that's fixed.
251 return rv.Pass();
252 } 247 }
253 248
254 ScopedMessagePipeHandle CreateChannel( 249 ScopedMessagePipeHandle CreateChannel(
255 ScopedPlatformHandle platform_handle, 250 ScopedPlatformHandle platform_handle,
256 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback, 251 const base::Callback<void(ChannelInfo*)>& did_create_channel_callback,
257 scoped_refptr<base::TaskRunner> did_create_channel_runner) { 252 scoped_refptr<base::TaskRunner> did_create_channel_runner) {
258 DCHECK(platform_handle.is_valid()); 253 DCHECK(platform_handle.is_valid());
259 DCHECK(!did_create_channel_callback.is_null()); 254 DCHECK(!did_create_channel_callback.is_null());
260 DCHECK(internal::g_ipc_support); 255 DCHECK(internal::g_ipc_support);
261 256
262 system::ChannelManager* channel_manager = 257 system::ChannelManager* channel_manager =
263 internal::g_ipc_support->channel_manager(); 258 internal::g_ipc_support->channel_manager();
264 259
265 system::ChannelId channel_id = MakeChannelId(); 260 system::ChannelId channel_id = MakeChannelId();
266 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id)); 261 std::unique_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id));
267 scoped_refptr<system::MessagePipeDispatcher> dispatcher = 262 system::RefPtr<system::MessagePipeDispatcher> dispatcher =
268 channel_manager->CreateChannel( 263 channel_manager->CreateChannel(
269 channel_id, platform_handle.Pass(), 264 channel_id, platform_handle.Pass(),
270 base::Bind(did_create_channel_callback, 265 base::Bind(did_create_channel_callback,
271 base::Unretained(channel_info.release())), 266 base::Unretained(channel_info.release())),
272 did_create_channel_runner); 267 did_create_channel_runner);
273 268
274 ScopedMessagePipeHandle rv( 269 ScopedMessagePipeHandle rv(
275 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); 270 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher.get())));
276 CHECK(rv.is_valid()); 271 CHECK(rv.is_valid());
277 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it 272 return rv;
278 // once that's fixed.
279 return rv.Pass();
280 } 273 }
281 274
282 // TODO(vtl): Write tests for this. 275 // TODO(vtl): Write tests for this.
283 void DestroyChannelOnIOThread(ChannelInfo* channel_info) { 276 void DestroyChannelOnIOThread(ChannelInfo* channel_info) {
284 DCHECK(channel_info); 277 DCHECK(channel_info);
285 DCHECK(channel_info->channel_id); 278 DCHECK(channel_info->channel_id);
286 DCHECK(internal::g_ipc_support); 279 DCHECK(internal::g_ipc_support);
287 280
288 system::ChannelManager* channel_manager = 281 system::ChannelManager* channel_manager =
289 internal::g_ipc_support->channel_manager(); 282 internal::g_ipc_support->channel_manager();
(...skipping 23 matching lines...) Expand all
313 DCHECK(channel_info); 306 DCHECK(channel_info);
314 DCHECK(internal::g_ipc_support); 307 DCHECK(internal::g_ipc_support);
315 308
316 system::ChannelManager* channel_manager = 309 system::ChannelManager* channel_manager =
317 internal::g_ipc_support->channel_manager(); 310 internal::g_ipc_support->channel_manager();
318 channel_manager->WillShutdownChannel(channel_info->channel_id); 311 channel_manager->WillShutdownChannel(channel_info->channel_id);
319 } 312 }
320 313
321 } // namespace embedder 314 } // namespace embedder
322 } // namespace mojo 315 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/embedder/system_impl_private_entrypoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698