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

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

Issue 1748503002: [mojo-edk] Add MojoWatch and MojoCancelWatch APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 9 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
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 <string.h> 7 #include <string.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "mojo/edk/system/async_waiter.h" 24 #include "mojo/edk/system/async_waiter.h"
25 #include "mojo/edk/system/channel.h" 25 #include "mojo/edk/system/channel.h"
26 #include "mojo/edk/system/configuration.h" 26 #include "mojo/edk/system/configuration.h"
27 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" 27 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
28 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" 28 #include "mojo/edk/system/data_pipe_producer_dispatcher.h"
29 #include "mojo/edk/system/handle_signals_state.h" 29 #include "mojo/edk/system/handle_signals_state.h"
30 #include "mojo/edk/system/message_pipe_dispatcher.h" 30 #include "mojo/edk/system/message_pipe_dispatcher.h"
31 #include "mojo/edk/system/platform_handle_dispatcher.h" 31 #include "mojo/edk/system/platform_handle_dispatcher.h"
32 #include "mojo/edk/system/ports/node.h" 32 #include "mojo/edk/system/ports/node.h"
33 #include "mojo/edk/system/remote_message_pipe_bootstrap.h" 33 #include "mojo/edk/system/remote_message_pipe_bootstrap.h"
34 #include "mojo/edk/system/request_context.h"
34 #include "mojo/edk/system/shared_buffer_dispatcher.h" 35 #include "mojo/edk/system/shared_buffer_dispatcher.h"
35 #include "mojo/edk/system/wait_set_dispatcher.h" 36 #include "mojo/edk/system/wait_set_dispatcher.h"
36 #include "mojo/edk/system/waiter.h" 37 #include "mojo/edk/system/waiter.h"
37 38
38 namespace mojo { 39 namespace mojo {
39 namespace edk { 40 namespace edk {
40 41
41 namespace { 42 namespace {
42 43
43 // This is an unnecessarily large limit that is relatively easy to enforce. 44 // This is an unnecessarily large limit that is relatively easy to enforce.
44 const uint32_t kMaxHandlesPerMessage = 1024 * 1024; 45 const uint32_t kMaxHandlesPerMessage = 1024 * 1024;
45 46
46 // TODO: Maybe we could negotiate a debugging pipe ID for cross-process pipes 47 // TODO: Maybe we could negotiate a debugging pipe ID for cross-process pipes
47 // too; for now we just use a constant. This only affects bootstrap pipes. 48 // too; for now we just use a constant. This only affects bootstrap pipes.
48 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL; 49 const uint64_t kUnknownPipeIdForDebug = 0x7f7f7f7f7f7f7f7fUL;
49 50
51 void CallWatchCallback(MojoWatchCallback callback,
52 uintptr_t context,
53 MojoResult result,
54 MojoHandleSignalsState signals_state) {
55 callback(context, result, signals_state);
56 }
57
50 } // namespace 58 } // namespace
51 59
52 Core::Core() {} 60 Core::Core() {}
53 61
54 Core::~Core() { 62 Core::~Core() {
55 if (node_controller_ && node_controller_->io_task_runner()) { 63 if (node_controller_ && node_controller_->io_task_runner()) {
56 // If this races with IO thread shutdown the callback will be dropped and 64 // If this races with IO thread shutdown the callback will be dropped and
57 // the NodeController will be shutdown on this thread anyway, which is also 65 // the NodeController will be shutdown on this thread anyway, which is also
58 // just fine. 66 // just fine.
59 scoped_refptr<base::TaskRunner> io_task_runner = 67 scoped_refptr<base::TaskRunner> io_task_runner =
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 if (rv == MOJO_RESULT_OK) 269 if (rv == MOJO_RESULT_OK)
262 ignore_result(waiter.release()); 270 ignore_result(waiter.release());
263 return rv; 271 return rv;
264 } 272 }
265 273
266 MojoTimeTicks Core::GetTimeTicksNow() { 274 MojoTimeTicks Core::GetTimeTicksNow() {
267 return base::TimeTicks::Now().ToInternalValue(); 275 return base::TimeTicks::Now().ToInternalValue();
268 } 276 }
269 277
270 MojoResult Core::Close(MojoHandle handle) { 278 MojoResult Core::Close(MojoHandle handle) {
279 RequestContext request_context;
271 scoped_refptr<Dispatcher> dispatcher; 280 scoped_refptr<Dispatcher> dispatcher;
272 { 281 {
273 base::AutoLock lock(handles_lock_); 282 base::AutoLock lock(handles_lock_);
274 MojoResult rv = handles_.GetAndRemoveDispatcher(handle, &dispatcher); 283 MojoResult rv = handles_.GetAndRemoveDispatcher(handle, &dispatcher);
275 if (rv != MOJO_RESULT_OK) 284 if (rv != MOJO_RESULT_OK)
276 return rv; 285 return rv;
277 } 286 }
278 dispatcher->Close(); 287 dispatcher->Close();
279 return MOJO_RESULT_OK; 288 return MOJO_RESULT_OK;
280 } 289 }
281 290
282 MojoResult Core::Wait(MojoHandle handle, 291 MojoResult Core::Wait(MojoHandle handle,
283 MojoHandleSignals signals, 292 MojoHandleSignals signals,
284 MojoDeadline deadline, 293 MojoDeadline deadline,
285 MojoHandleSignalsState* signals_state) { 294 MojoHandleSignalsState* signals_state) {
295 RequestContext request_context;
286 uint32_t unused = static_cast<uint32_t>(-1); 296 uint32_t unused = static_cast<uint32_t>(-1);
287 HandleSignalsState hss; 297 HandleSignalsState hss;
288 MojoResult rv = WaitManyInternal(&handle, &signals, 1, deadline, &unused, 298 MojoResult rv = WaitManyInternal(&handle, &signals, 1, deadline, &unused,
289 signals_state ? &hss : nullptr); 299 signals_state ? &hss : nullptr);
290 if (rv != MOJO_RESULT_INVALID_ARGUMENT && signals_state) 300 if (rv != MOJO_RESULT_INVALID_ARGUMENT && signals_state)
291 *signals_state = hss; 301 *signals_state = hss;
292 return rv; 302 return rv;
293 } 303 }
294 304
295 MojoResult Core::WaitMany(const MojoHandle* handles, 305 MojoResult Core::WaitMany(const MojoHandle* handles,
296 const MojoHandleSignals* signals, 306 const MojoHandleSignals* signals,
297 uint32_t num_handles, 307 uint32_t num_handles,
298 MojoDeadline deadline, 308 MojoDeadline deadline,
299 uint32_t* result_index, 309 uint32_t* result_index,
300 MojoHandleSignalsState* signals_state) { 310 MojoHandleSignalsState* signals_state) {
311 RequestContext request_context;
301 if (num_handles < 1) 312 if (num_handles < 1)
302 return MOJO_RESULT_INVALID_ARGUMENT; 313 return MOJO_RESULT_INVALID_ARGUMENT;
303 if (num_handles > GetConfiguration().max_wait_many_num_handles) 314 if (num_handles > GetConfiguration().max_wait_many_num_handles)
304 return MOJO_RESULT_RESOURCE_EXHAUSTED; 315 return MOJO_RESULT_RESOURCE_EXHAUSTED;
305 316
306 uint32_t index = static_cast<uint32_t>(-1); 317 uint32_t index = static_cast<uint32_t>(-1);
307 MojoResult rv; 318 MojoResult rv;
308 if (!signals_state) { 319 if (!signals_state) {
309 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, 320 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index,
310 nullptr); 321 nullptr);
311 } else { 322 } else {
312 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a 323 // Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a
313 // subclass of |MojoHandleSignalsState| that doesn't add any data members. 324 // subclass of |MojoHandleSignalsState| that doesn't add any data members.
314 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index, 325 rv = WaitManyInternal(handles, signals, num_handles, deadline, &index,
315 reinterpret_cast<HandleSignalsState*>(signals_state)); 326 reinterpret_cast<HandleSignalsState*>(signals_state));
316 } 327 }
317 if (index != static_cast<uint32_t>(-1) && result_index) 328 if (index != static_cast<uint32_t>(-1) && result_index)
318 *result_index = index; 329 *result_index = index;
319 return rv; 330 return rv;
320 } 331 }
321 332
333 MojoResult Core::Watch(MojoHandle handle,
334 MojoHandleSignals signals,
335 MojoWatchCallback callback,
336 uintptr_t context) {
337 RequestContext request_context;
338 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
339 if (!dispatcher)
340 return MOJO_RESULT_INVALID_ARGUMENT;
341 return dispatcher->Watch(
342 signals, base::Bind(&CallWatchCallback, callback, context), context);
343 }
344
345 MojoResult Core::CancelWatch(MojoHandle handle, uintptr_t context) {
346 RequestContext request_context;
347 scoped_refptr<Dispatcher> dispatcher = GetDispatcher(handle);
348 if (!dispatcher)
349 return MOJO_RESULT_INVALID_ARGUMENT;
350 return dispatcher->CancelWatch(context);
351 }
352
322 MojoResult Core::CreateWaitSet(MojoHandle* wait_set_handle) { 353 MojoResult Core::CreateWaitSet(MojoHandle* wait_set_handle) {
354 RequestContext request_context;
323 if (!wait_set_handle) 355 if (!wait_set_handle)
324 return MOJO_RESULT_INVALID_ARGUMENT; 356 return MOJO_RESULT_INVALID_ARGUMENT;
325 357
326 scoped_refptr<WaitSetDispatcher> dispatcher = new WaitSetDispatcher(); 358 scoped_refptr<WaitSetDispatcher> dispatcher = new WaitSetDispatcher();
327 MojoHandle h = AddDispatcher(dispatcher); 359 MojoHandle h = AddDispatcher(dispatcher);
328 if (h == MOJO_HANDLE_INVALID) { 360 if (h == MOJO_HANDLE_INVALID) {
329 LOG(ERROR) << "Handle table full"; 361 LOG(ERROR) << "Handle table full";
330 dispatcher->Close(); 362 dispatcher->Close();
331 return MOJO_RESULT_RESOURCE_EXHAUSTED; 363 return MOJO_RESULT_RESOURCE_EXHAUSTED;
332 } 364 }
333 365
334 *wait_set_handle = h; 366 *wait_set_handle = h;
335 return MOJO_RESULT_OK; 367 return MOJO_RESULT_OK;
336 } 368 }
337 369
338 MojoResult Core::AddHandle(MojoHandle wait_set_handle, 370 MojoResult Core::AddHandle(MojoHandle wait_set_handle,
339 MojoHandle handle, 371 MojoHandle handle,
340 MojoHandleSignals signals) { 372 MojoHandleSignals signals) {
373 RequestContext request_context;
341 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle)); 374 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
342 if (!wait_set_dispatcher) 375 if (!wait_set_dispatcher)
343 return MOJO_RESULT_INVALID_ARGUMENT; 376 return MOJO_RESULT_INVALID_ARGUMENT;
344 377
345 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle)); 378 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle));
346 if (!dispatcher) 379 if (!dispatcher)
347 return MOJO_RESULT_INVALID_ARGUMENT; 380 return MOJO_RESULT_INVALID_ARGUMENT;
348 381
349 return wait_set_dispatcher->AddWaitingDispatcher(dispatcher, signals, handle); 382 return wait_set_dispatcher->AddWaitingDispatcher(dispatcher, signals, handle);
350 } 383 }
351 384
352 MojoResult Core::RemoveHandle(MojoHandle wait_set_handle, 385 MojoResult Core::RemoveHandle(MojoHandle wait_set_handle,
353 MojoHandle handle) { 386 MojoHandle handle) {
387 RequestContext request_context;
354 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle)); 388 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
355 if (!wait_set_dispatcher) 389 if (!wait_set_dispatcher)
356 return MOJO_RESULT_INVALID_ARGUMENT; 390 return MOJO_RESULT_INVALID_ARGUMENT;
357 391
358 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle)); 392 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(handle));
359 if (!dispatcher) 393 if (!dispatcher)
360 return MOJO_RESULT_INVALID_ARGUMENT; 394 return MOJO_RESULT_INVALID_ARGUMENT;
361 395
362 return wait_set_dispatcher->RemoveWaitingDispatcher(dispatcher); 396 return wait_set_dispatcher->RemoveWaitingDispatcher(dispatcher);
363 } 397 }
364 398
365 MojoResult Core::GetReadyHandles(MojoHandle wait_set_handle, 399 MojoResult Core::GetReadyHandles(MojoHandle wait_set_handle,
366 uint32_t* count, 400 uint32_t* count,
367 MojoHandle* handles, 401 MojoHandle* handles,
368 MojoResult* results, 402 MojoResult* results,
369 MojoHandleSignalsState* signals_states) { 403 MojoHandleSignalsState* signals_states) {
404 RequestContext request_context;
370 if (!handles || !count || !(*count) || !results) 405 if (!handles || !count || !(*count) || !results)
371 return MOJO_RESULT_INVALID_ARGUMENT; 406 return MOJO_RESULT_INVALID_ARGUMENT;
372 407
373 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle)); 408 scoped_refptr<Dispatcher> wait_set_dispatcher(GetDispatcher(wait_set_handle));
374 if (!wait_set_dispatcher) 409 if (!wait_set_dispatcher)
375 return MOJO_RESULT_INVALID_ARGUMENT; 410 return MOJO_RESULT_INVALID_ARGUMENT;
376 411
377 DispatcherVector awoken_dispatchers; 412 DispatcherVector awoken_dispatchers;
378 base::StackVector<uintptr_t, 16> contexts; 413 base::StackVector<uintptr_t, 16> contexts;
379 contexts->assign(*count, MOJO_HANDLE_INVALID); 414 contexts->assign(*count, MOJO_HANDLE_INVALID);
380 415
381 MojoResult result = wait_set_dispatcher->GetReadyDispatchers( 416 MojoResult result = wait_set_dispatcher->GetReadyDispatchers(
382 count, &awoken_dispatchers, results, contexts->data()); 417 count, &awoken_dispatchers, results, contexts->data());
383 418
384 if (result == MOJO_RESULT_OK) { 419 if (result == MOJO_RESULT_OK) {
385 for (size_t i = 0; i < *count; i++) { 420 for (size_t i = 0; i < *count; i++) {
386 handles[i] = static_cast<MojoHandle>(contexts[i]); 421 handles[i] = static_cast<MojoHandle>(contexts[i]);
387 if (signals_states) 422 if (signals_states)
388 signals_states[i] = awoken_dispatchers[i]->GetHandleSignalsState(); 423 signals_states[i] = awoken_dispatchers[i]->GetHandleSignalsState();
389 } 424 }
390 } 425 }
391 426
392 return result; 427 return result;
393 } 428 }
394 429
395 MojoResult Core::CreateMessagePipe( 430 MojoResult Core::CreateMessagePipe(
396 const MojoCreateMessagePipeOptions* options, 431 const MojoCreateMessagePipeOptions* options,
397 MojoHandle* message_pipe_handle0, 432 MojoHandle* message_pipe_handle0,
398 MojoHandle* message_pipe_handle1) { 433 MojoHandle* message_pipe_handle1) {
434 RequestContext request_context;
399 ports::PortRef port0, port1; 435 ports::PortRef port0, port1;
400 GetNodeController()->node()->CreatePortPair(&port0, &port1); 436 GetNodeController()->node()->CreatePortPair(&port0, &port1);
401 437
402 CHECK(message_pipe_handle0); 438 CHECK(message_pipe_handle0);
403 CHECK(message_pipe_handle1); 439 CHECK(message_pipe_handle1);
404 440
405 uint64_t pipe_id = base::RandUint64(); 441 uint64_t pipe_id = base::RandUint64();
406 442
407 *message_pipe_handle0 = AddDispatcher( 443 *message_pipe_handle0 = AddDispatcher(
408 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0)); 444 new MessagePipeDispatcher(GetNodeController(), port0, pipe_id, 0));
(...skipping 11 matching lines...) Expand all
420 456
421 return MOJO_RESULT_OK; 457 return MOJO_RESULT_OK;
422 } 458 }
423 459
424 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle, 460 MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
425 const void* bytes, 461 const void* bytes,
426 uint32_t num_bytes, 462 uint32_t num_bytes,
427 const MojoHandle* handles, 463 const MojoHandle* handles,
428 uint32_t num_handles, 464 uint32_t num_handles,
429 MojoWriteMessageFlags flags) { 465 MojoWriteMessageFlags flags) {
466 RequestContext request_context;
430 auto dispatcher = GetDispatcher(message_pipe_handle); 467 auto dispatcher = GetDispatcher(message_pipe_handle);
431 if (!dispatcher) 468 if (!dispatcher)
432 return MOJO_RESULT_INVALID_ARGUMENT; 469 return MOJO_RESULT_INVALID_ARGUMENT;
433 470
434 if (num_handles == 0) // Fast path: no handles. 471 if (num_handles == 0) // Fast path: no handles.
435 return dispatcher->WriteMessage(bytes, num_bytes, nullptr, 0, flags); 472 return dispatcher->WriteMessage(bytes, num_bytes, nullptr, 0, flags);
436 473
437 CHECK(handles); 474 CHECK(handles);
438 475
439 if (num_handles > kMaxHandlesPerMessage) 476 if (num_handles > kMaxHandlesPerMessage)
(...skipping 29 matching lines...) Expand all
469 506
470 return rv; 507 return rv;
471 } 508 }
472 509
473 MojoResult Core::ReadMessage(MojoHandle message_pipe_handle, 510 MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
474 void* bytes, 511 void* bytes,
475 uint32_t* num_bytes, 512 uint32_t* num_bytes,
476 MojoHandle* handles, 513 MojoHandle* handles,
477 uint32_t* num_handles, 514 uint32_t* num_handles,
478 MojoReadMessageFlags flags) { 515 MojoReadMessageFlags flags) {
516 RequestContext request_context;
479 CHECK((!num_handles || !*num_handles || handles) && 517 CHECK((!num_handles || !*num_handles || handles) &&
480 (!num_bytes || !*num_bytes || bytes)); 518 (!num_bytes || !*num_bytes || bytes));
481 auto dispatcher = GetDispatcher(message_pipe_handle); 519 auto dispatcher = GetDispatcher(message_pipe_handle);
482 if (!dispatcher) 520 if (!dispatcher)
483 return MOJO_RESULT_INVALID_ARGUMENT; 521 return MOJO_RESULT_INVALID_ARGUMENT;
484 return dispatcher->ReadMessage(bytes, num_bytes, handles, num_handles, flags); 522 return dispatcher->ReadMessage(bytes, num_bytes, handles, num_handles, flags);
485 } 523 }
486 524
487 MojoResult Core::CreateDataPipe( 525 MojoResult Core::CreateDataPipe(
488 const MojoCreateDataPipeOptions* options, 526 const MojoCreateDataPipeOptions* options,
489 MojoHandle* data_pipe_producer_handle, 527 MojoHandle* data_pipe_producer_handle,
490 MojoHandle* data_pipe_consumer_handle) { 528 MojoHandle* data_pipe_consumer_handle) {
529 RequestContext request_context;
491 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions)) 530 if (options && options->struct_size != sizeof(MojoCreateDataPipeOptions))
492 return MOJO_RESULT_INVALID_ARGUMENT; 531 return MOJO_RESULT_INVALID_ARGUMENT;
493 532
494 MojoCreateDataPipeOptions create_options; 533 MojoCreateDataPipeOptions create_options;
495 create_options.struct_size = sizeof(MojoCreateDataPipeOptions); 534 create_options.struct_size = sizeof(MojoCreateDataPipeOptions);
496 create_options.flags = options ? options->flags : 0; 535 create_options.flags = options ? options->flags : 0;
497 create_options.element_num_bytes = options ? options->element_num_bytes : 1; 536 create_options.element_num_bytes = options ? options->element_num_bytes : 1;
498 // TODO: Use Configuration to get default data pipe capacity. 537 // TODO: Use Configuration to get default data pipe capacity.
499 create_options.capacity_num_bytes = 538 create_options.capacity_num_bytes =
500 options && options->capacity_num_bytes ? options->capacity_num_bytes 539 options && options->capacity_num_bytes ? options->capacity_num_bytes
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return MOJO_RESULT_RESOURCE_EXHAUSTED; 574 return MOJO_RESULT_RESOURCE_EXHAUSTED;
536 } 575 }
537 576
538 return MOJO_RESULT_OK; 577 return MOJO_RESULT_OK;
539 } 578 }
540 579
541 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle, 580 MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle,
542 const void* elements, 581 const void* elements,
543 uint32_t* num_bytes, 582 uint32_t* num_bytes,
544 MojoWriteDataFlags flags) { 583 MojoWriteDataFlags flags) {
584 RequestContext request_context;
545 scoped_refptr<Dispatcher> dispatcher( 585 scoped_refptr<Dispatcher> dispatcher(
546 GetDispatcher(data_pipe_producer_handle)); 586 GetDispatcher(data_pipe_producer_handle));
547 if (!dispatcher) 587 if (!dispatcher)
548 return MOJO_RESULT_INVALID_ARGUMENT; 588 return MOJO_RESULT_INVALID_ARGUMENT;
549 589
550 return dispatcher->WriteData(elements, num_bytes, flags); 590 return dispatcher->WriteData(elements, num_bytes, flags);
551 } 591 }
552 592
553 MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle, 593 MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle,
554 void** buffer, 594 void** buffer,
555 uint32_t* buffer_num_bytes, 595 uint32_t* buffer_num_bytes,
556 MojoWriteDataFlags flags) { 596 MojoWriteDataFlags flags) {
597 RequestContext request_context;
557 scoped_refptr<Dispatcher> dispatcher( 598 scoped_refptr<Dispatcher> dispatcher(
558 GetDispatcher(data_pipe_producer_handle)); 599 GetDispatcher(data_pipe_producer_handle));
559 if (!dispatcher) 600 if (!dispatcher)
560 return MOJO_RESULT_INVALID_ARGUMENT; 601 return MOJO_RESULT_INVALID_ARGUMENT;
561 602
562 return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags); 603 return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags);
563 } 604 }
564 605
565 MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle, 606 MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle,
566 uint32_t num_bytes_written) { 607 uint32_t num_bytes_written) {
608 RequestContext request_context;
567 scoped_refptr<Dispatcher> dispatcher( 609 scoped_refptr<Dispatcher> dispatcher(
568 GetDispatcher(data_pipe_producer_handle)); 610 GetDispatcher(data_pipe_producer_handle));
569 if (!dispatcher) 611 if (!dispatcher)
570 return MOJO_RESULT_INVALID_ARGUMENT; 612 return MOJO_RESULT_INVALID_ARGUMENT;
571 613
572 return dispatcher->EndWriteData(num_bytes_written); 614 return dispatcher->EndWriteData(num_bytes_written);
573 } 615 }
574 616
575 MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle, 617 MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle,
576 void* elements, 618 void* elements,
577 uint32_t* num_bytes, 619 uint32_t* num_bytes,
578 MojoReadDataFlags flags) { 620 MojoReadDataFlags flags) {
621 RequestContext request_context;
579 scoped_refptr<Dispatcher> dispatcher( 622 scoped_refptr<Dispatcher> dispatcher(
580 GetDispatcher(data_pipe_consumer_handle)); 623 GetDispatcher(data_pipe_consumer_handle));
581 if (!dispatcher) 624 if (!dispatcher)
582 return MOJO_RESULT_INVALID_ARGUMENT; 625 return MOJO_RESULT_INVALID_ARGUMENT;
583 626
584 return dispatcher->ReadData(elements, num_bytes, flags); 627 return dispatcher->ReadData(elements, num_bytes, flags);
585 } 628 }
586 629
587 MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle, 630 MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle,
588 const void** buffer, 631 const void** buffer,
589 uint32_t* buffer_num_bytes, 632 uint32_t* buffer_num_bytes,
590 MojoReadDataFlags flags) { 633 MojoReadDataFlags flags) {
634 RequestContext request_context;
591 scoped_refptr<Dispatcher> dispatcher( 635 scoped_refptr<Dispatcher> dispatcher(
592 GetDispatcher(data_pipe_consumer_handle)); 636 GetDispatcher(data_pipe_consumer_handle));
593 if (!dispatcher) 637 if (!dispatcher)
594 return MOJO_RESULT_INVALID_ARGUMENT; 638 return MOJO_RESULT_INVALID_ARGUMENT;
595 639
596 return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags); 640 return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags);
597 } 641 }
598 642
599 MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle, 643 MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle,
600 uint32_t num_bytes_read) { 644 uint32_t num_bytes_read) {
645 RequestContext request_context;
601 scoped_refptr<Dispatcher> dispatcher( 646 scoped_refptr<Dispatcher> dispatcher(
602 GetDispatcher(data_pipe_consumer_handle)); 647 GetDispatcher(data_pipe_consumer_handle));
603 if (!dispatcher) 648 if (!dispatcher)
604 return MOJO_RESULT_INVALID_ARGUMENT; 649 return MOJO_RESULT_INVALID_ARGUMENT;
605 650
606 return dispatcher->EndReadData(num_bytes_read); 651 return dispatcher->EndReadData(num_bytes_read);
607 } 652 }
608 653
609 MojoResult Core::CreateSharedBuffer( 654 MojoResult Core::CreateSharedBuffer(
610 const MojoCreateSharedBufferOptions* options, 655 const MojoCreateSharedBufferOptions* options,
611 uint64_t num_bytes, 656 uint64_t num_bytes,
612 MojoHandle* shared_buffer_handle) { 657 MojoHandle* shared_buffer_handle) {
658 RequestContext request_context;
613 MojoCreateSharedBufferOptions validated_options = {}; 659 MojoCreateSharedBufferOptions validated_options = {};
614 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions( 660 MojoResult result = SharedBufferDispatcher::ValidateCreateOptions(
615 options, &validated_options); 661 options, &validated_options);
616 if (result != MOJO_RESULT_OK) 662 if (result != MOJO_RESULT_OK)
617 return result; 663 return result;
618 664
619 scoped_refptr<SharedBufferDispatcher> dispatcher; 665 scoped_refptr<SharedBufferDispatcher> dispatcher;
620 result = 666 result =
621 SharedBufferDispatcher::Create(validated_options, num_bytes, &dispatcher); 667 SharedBufferDispatcher::Create(validated_options, num_bytes, &dispatcher);
622 if (result != MOJO_RESULT_OK) { 668 if (result != MOJO_RESULT_OK) {
623 DCHECK(!dispatcher); 669 DCHECK(!dispatcher);
624 return result; 670 return result;
625 } 671 }
626 672
627 *shared_buffer_handle = AddDispatcher(dispatcher); 673 *shared_buffer_handle = AddDispatcher(dispatcher);
628 if (*shared_buffer_handle == MOJO_HANDLE_INVALID) { 674 if (*shared_buffer_handle == MOJO_HANDLE_INVALID) {
629 LOG(ERROR) << "Handle table full"; 675 LOG(ERROR) << "Handle table full";
630 dispatcher->Close(); 676 dispatcher->Close();
631 return MOJO_RESULT_RESOURCE_EXHAUSTED; 677 return MOJO_RESULT_RESOURCE_EXHAUSTED;
632 } 678 }
633 679
634 return MOJO_RESULT_OK; 680 return MOJO_RESULT_OK;
635 } 681 }
636 682
637 MojoResult Core::DuplicateBufferHandle( 683 MojoResult Core::DuplicateBufferHandle(
638 MojoHandle buffer_handle, 684 MojoHandle buffer_handle,
639 const MojoDuplicateBufferHandleOptions* options, 685 const MojoDuplicateBufferHandleOptions* options,
640 MojoHandle* new_buffer_handle) { 686 MojoHandle* new_buffer_handle) {
687 RequestContext request_context;
641 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); 688 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
642 if (!dispatcher) 689 if (!dispatcher)
643 return MOJO_RESULT_INVALID_ARGUMENT; 690 return MOJO_RESULT_INVALID_ARGUMENT;
644 691
645 // Don't verify |options| here; that's the dispatcher's job. 692 // Don't verify |options| here; that's the dispatcher's job.
646 scoped_refptr<Dispatcher> new_dispatcher; 693 scoped_refptr<Dispatcher> new_dispatcher;
647 MojoResult result = 694 MojoResult result =
648 dispatcher->DuplicateBufferHandle(options, &new_dispatcher); 695 dispatcher->DuplicateBufferHandle(options, &new_dispatcher);
649 if (result != MOJO_RESULT_OK) 696 if (result != MOJO_RESULT_OK)
650 return result; 697 return result;
651 698
652 *new_buffer_handle = AddDispatcher(new_dispatcher); 699 *new_buffer_handle = AddDispatcher(new_dispatcher);
653 if (*new_buffer_handle == MOJO_HANDLE_INVALID) { 700 if (*new_buffer_handle == MOJO_HANDLE_INVALID) {
654 LOG(ERROR) << "Handle table full"; 701 LOG(ERROR) << "Handle table full";
655 dispatcher->Close(); 702 dispatcher->Close();
656 return MOJO_RESULT_RESOURCE_EXHAUSTED; 703 return MOJO_RESULT_RESOURCE_EXHAUSTED;
657 } 704 }
658 705
659 return MOJO_RESULT_OK; 706 return MOJO_RESULT_OK;
660 } 707 }
661 708
662 MojoResult Core::MapBuffer(MojoHandle buffer_handle, 709 MojoResult Core::MapBuffer(MojoHandle buffer_handle,
663 uint64_t offset, 710 uint64_t offset,
664 uint64_t num_bytes, 711 uint64_t num_bytes,
665 void** buffer, 712 void** buffer,
666 MojoMapBufferFlags flags) { 713 MojoMapBufferFlags flags) {
714 RequestContext request_context;
667 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle)); 715 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
668 if (!dispatcher) 716 if (!dispatcher)
669 return MOJO_RESULT_INVALID_ARGUMENT; 717 return MOJO_RESULT_INVALID_ARGUMENT;
670 718
671 scoped_ptr<PlatformSharedBufferMapping> mapping; 719 scoped_ptr<PlatformSharedBufferMapping> mapping;
672 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping); 720 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping);
673 if (result != MOJO_RESULT_OK) 721 if (result != MOJO_RESULT_OK)
674 return result; 722 return result;
675 723
676 DCHECK(mapping); 724 DCHECK(mapping);
677 void* address = mapping->GetBase(); 725 void* address = mapping->GetBase();
678 { 726 {
679 base::AutoLock locker(mapping_table_lock_); 727 base::AutoLock locker(mapping_table_lock_);
680 result = mapping_table_.AddMapping(std::move(mapping)); 728 result = mapping_table_.AddMapping(std::move(mapping));
681 } 729 }
682 if (result != MOJO_RESULT_OK) 730 if (result != MOJO_RESULT_OK)
683 return result; 731 return result;
684 732
685 *buffer = address; 733 *buffer = address;
686 return MOJO_RESULT_OK; 734 return MOJO_RESULT_OK;
687 } 735 }
688 736
689 MojoResult Core::UnmapBuffer(void* buffer) { 737 MojoResult Core::UnmapBuffer(void* buffer) {
738 RequestContext request_context;
690 base::AutoLock lock(mapping_table_lock_); 739 base::AutoLock lock(mapping_table_lock_);
691 return mapping_table_.RemoveMapping(buffer); 740 return mapping_table_.RemoveMapping(buffer);
692 } 741 }
693 742
694 void Core::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { 743 void Core::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) {
695 base::AutoLock lock(handles_lock_); 744 base::AutoLock lock(handles_lock_);
696 handles_.GetActiveHandlesForTest(handles); 745 handles_.GetActiveHandlesForTest(handles);
697 } 746 }
698 747
699 MojoResult Core::WaitManyInternal(const MojoHandle* handles, 748 MojoResult Core::WaitManyInternal(const MojoHandle* handles,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 scoped_ptr<NodeController> node_controller) { 818 scoped_ptr<NodeController> node_controller) {
770 // It's OK to leak this reference. At this point we know the IO loop is still 819 // It's OK to leak this reference. At this point we know the IO loop is still
771 // running, and we know the NodeController will observe its eventual 820 // running, and we know the NodeController will observe its eventual
772 // destruction. This tells the NodeController to delete itself when that 821 // destruction. This tells the NodeController to delete itself when that
773 // happens. 822 // happens.
774 node_controller.release()->DestroyOnIOThreadShutdown(); 823 node_controller.release()->DestroyOnIOThreadShutdown();
775 } 824 }
776 825
777 } // namespace edk 826 } // namespace edk
778 } // namespace mojo 827 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698