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

Side by Side Diff: mojo/edk/system/core.cc

Issue 1387963004: Create a broker interface for the new Mojo EDK so that the browser can create and duplicate messa... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: presubmit whitespace error Created 5 years 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 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 #include "mojo/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "mojo/edk/embedder/embedder_internal.h"
11 #include "mojo/edk/embedder/platform_channel_pair.h" 12 #include "mojo/edk/embedder/platform_channel_pair.h"
12 #include "mojo/edk/embedder/platform_shared_buffer.h" 13 #include "mojo/edk/embedder/platform_shared_buffer.h"
13 #include "mojo/edk/embedder/platform_support.h" 14 #include "mojo/edk/embedder/platform_support.h"
14 #include "mojo/edk/system/async_waiter.h" 15 #include "mojo/edk/system/async_waiter.h"
15 #include "mojo/edk/system/configuration.h" 16 #include "mojo/edk/system/configuration.h"
16 #include "mojo/edk/system/data_pipe.h" 17 #include "mojo/edk/system/data_pipe.h"
17 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 18 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
18 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 19 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
19 #include "mojo/edk/system/dispatcher.h" 20 #include "mojo/edk/system/dispatcher.h"
20 #include "mojo/edk/system/handle_signals_state.h" 21 #include "mojo/edk/system/handle_signals_state.h"
21 #include "mojo/edk/system/message_pipe_dispatcher.h" 22 #include "mojo/edk/system/message_pipe_dispatcher.h"
22 #include "mojo/edk/system/shared_buffer_dispatcher.h" 23 #include "mojo/edk/system/shared_buffer_dispatcher.h"
23 #include "mojo/edk/system/waiter.h" 24 #include "mojo/edk/system/waiter.h"
24 #include "mojo/public/c/system/macros.h" 25 #include "mojo/public/c/system/macros.h"
25 #include "mojo/public/cpp/system/macros.h" 26 #include "mojo/public/cpp/system/macros.h"
26 27
28 #if defined(OS_WIN)
29 #include "mojo/edk/system/token_serializer_win.h"
30 #endif
31
27 namespace mojo { 32 namespace mojo {
28 namespace edk { 33 namespace edk {
29 34
30 // Implementation notes 35 // Implementation notes
31 // 36 //
32 // Mojo primitives are implemented by the singleton |Core| object. Most calls 37 // Mojo primitives are implemented by the singleton |Core| object. Most calls
33 // are for a "primary" handle (the first argument). |Core::GetDispatcher()| is 38 // are for a "primary" handle (the first argument). |Core::GetDispatcher()| is
34 // used to look up a |Dispatcher| object for a given handle. That object 39 // used to look up a |Dispatcher| object for a given handle. That object
35 // implements most primitives for that object. The wait primitives are not 40 // implements most primitives for that object. The wait primitives are not
36 // attached to objects and are implemented by |Core| itself. 41 // attached to objects and are implemented by |Core| itself.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 handle_pair = handle_table_.AddDispatcherPair(dispatcher0, dispatcher1); 202 handle_pair = handle_table_.AddDispatcherPair(dispatcher0, dispatcher1);
198 } 203 }
199 if (handle_pair.first == MOJO_HANDLE_INVALID) { 204 if (handle_pair.first == MOJO_HANDLE_INVALID) {
200 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); 205 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID);
201 LOG(ERROR) << "Handle table full"; 206 LOG(ERROR) << "Handle table full";
202 dispatcher0->Close(); 207 dispatcher0->Close();
203 dispatcher1->Close(); 208 dispatcher1->Close();
204 return MOJO_RESULT_RESOURCE_EXHAUSTED; 209 return MOJO_RESULT_RESOURCE_EXHAUSTED;
205 } 210 }
206 211
212 ScopedPlatformHandle server_handle, client_handle;
213 #if defined(OS_WIN)
214 internal::g_token_serializer->CreatePlatformChannelPair(
215 &server_handle, &client_handle);
216 #else
207 PlatformChannelPair channel_pair; 217 PlatformChannelPair channel_pair;
208 dispatcher0->Init(channel_pair.PassServerHandle(), nullptr, 0u, nullptr, 0u, 218 server_handle = channel_pair.PassServerHandle();
209 nullptr, nullptr); 219 client_handle = channel_pair.PassClientHandle();
210 dispatcher1->Init(channel_pair.PassClientHandle(), nullptr, 0u, nullptr, 0u, 220 #endif
211 nullptr, nullptr); 221 dispatcher0->Init(server_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
222 nullptr);
223 dispatcher1->Init(client_handle.Pass(), nullptr, 0u, nullptr, 0u, nullptr,
224 nullptr);
212 225
213 *message_pipe_handle0 = handle_pair.first; 226 *message_pipe_handle0 = handle_pair.first;
214 *message_pipe_handle1 = handle_pair.second; 227 *message_pipe_handle1 = handle_pair.second;
215 return MOJO_RESULT_OK; 228 return MOJO_RESULT_OK;
216 } 229 }
217 230
218 // Implementation note: To properly cancel waiters and avoid other races, this 231 // Implementation note: To properly cancel waiters and avoid other races, this
219 // does not transfer dispatchers from one handle to another, even when sending a 232 // does not transfer dispatchers from one handle to another, even when sending a
220 // message in-process. Instead, it must transfer the "contents" of the 233 // message in-process. Instead, it must transfer the "contents" of the
221 // dispatcher to a new dispatcher, and then close the old dispatcher. If this 234 // dispatcher to a new dispatcher, and then close the old dispatcher. If this
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 370 }
358 if (handle_pair.first == MOJO_HANDLE_INVALID) { 371 if (handle_pair.first == MOJO_HANDLE_INVALID) {
359 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); 372 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID);
360 LOG(ERROR) << "Handle table full"; 373 LOG(ERROR) << "Handle table full";
361 producer_dispatcher->Close(); 374 producer_dispatcher->Close();
362 consumer_dispatcher->Close(); 375 consumer_dispatcher->Close();
363 return MOJO_RESULT_RESOURCE_EXHAUSTED; 376 return MOJO_RESULT_RESOURCE_EXHAUSTED;
364 } 377 }
365 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); 378 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID);
366 379
380 ScopedPlatformHandle server_handle, client_handle;
381 #if defined(OS_WIN)
382 internal::g_token_serializer->CreatePlatformChannelPair(
383 &server_handle, &client_handle);
384 #else
367 PlatformChannelPair channel_pair; 385 PlatformChannelPair channel_pair;
368 producer_dispatcher->Init(channel_pair.PassServerHandle(), nullptr, 0u); 386 server_handle = channel_pair.PassServerHandle();
369 consumer_dispatcher->Init(channel_pair.PassClientHandle(), nullptr, 0u); 387 client_handle = channel_pair.PassClientHandle();
388 #endif
389 producer_dispatcher->Init(server_handle.Pass(), nullptr, 0u);
390 consumer_dispatcher->Init(client_handle.Pass(), nullptr, 0u);
370 391
371 *data_pipe_producer_handle = handle_pair.first; 392 *data_pipe_producer_handle = handle_pair.first;
372 *data_pipe_consumer_handle = handle_pair.second; 393 *data_pipe_consumer_handle = handle_pair.second;
373 return MOJO_RESULT_OK; 394 return MOJO_RESULT_OK;
374 } 395 }
375 396
376 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, 397 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle,
377 const void* elements, 398 const void* elements,
378 uint32_t* num_bytes, 399 uint32_t* num_bytes,
379 MojoWriteDataFlags flags) { 400 MojoWriteDataFlags flags) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 if (signals_states) { 611 if (signals_states) {
591 for (; i < num_handles; i++) 612 for (; i < num_handles; i++)
592 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); 613 signals_states[i] = dispatchers[i]->GetHandleSignalsState();
593 } 614 }
594 615
595 return rv; 616 return rv;
596 } 617 }
597 618
598 } // namespace edk 619 } // namespace edk
599 } // namespace mojo 620 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698