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

Side by Side Diff: mojo/system/core_impl.cc

Issue 169463012: Mojo: Add Dispatcher::{DuplicateBufferHandle,MapBuffer} methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/system/core_impl_unittest.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 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/system/core_impl.h" 5 #include "mojo/system/core_impl.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"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (!VerifyUserPointer<MojoHandle>(message_pipe_handle1, 1)) 155 if (!VerifyUserPointer<MojoHandle>(message_pipe_handle1, 1))
156 return MOJO_RESULT_INVALID_ARGUMENT; 156 return MOJO_RESULT_INVALID_ARGUMENT;
157 157
158 scoped_refptr<MessagePipeDispatcher> dispatcher0(new MessagePipeDispatcher()); 158 scoped_refptr<MessagePipeDispatcher> dispatcher0(new MessagePipeDispatcher());
159 scoped_refptr<MessagePipeDispatcher> dispatcher1(new MessagePipeDispatcher()); 159 scoped_refptr<MessagePipeDispatcher> dispatcher1(new MessagePipeDispatcher());
160 160
161 MojoHandle h0, h1; 161 MojoHandle h0, h1;
162 { 162 {
163 base::AutoLock locker(handle_table_lock_); 163 base::AutoLock locker(handle_table_lock_);
164 164
165 // TODO(vtl): crbug.com/345911: On failure, we should close the dispatcher
166 // (outside the table lock).
165 h0 = AddDispatcherNoLock(dispatcher0); 167 h0 = AddDispatcherNoLock(dispatcher0);
166 if (h0 == MOJO_HANDLE_INVALID) 168 if (h0 == MOJO_HANDLE_INVALID)
167 return MOJO_RESULT_RESOURCE_EXHAUSTED; 169 return MOJO_RESULT_RESOURCE_EXHAUSTED;
168 170
171 // TODO(vtl): crbug.com/345911: On failure, we should close both dispatchers
172 // (outside the table lock).
169 h1 = AddDispatcherNoLock(dispatcher1); 173 h1 = AddDispatcherNoLock(dispatcher1);
170 if (h1 == MOJO_HANDLE_INVALID) { 174 if (h1 == MOJO_HANDLE_INVALID) {
171 handle_table_.erase(h0); 175 handle_table_.erase(h0);
172 return MOJO_RESULT_RESOURCE_EXHAUSTED; 176 return MOJO_RESULT_RESOURCE_EXHAUSTED;
173 } 177 }
174 } 178 }
175 179
176 scoped_refptr<MessagePipe> message_pipe(new MessagePipe()); 180 scoped_refptr<MessagePipe> message_pipe(new MessagePipe());
177 dispatcher0->Init(message_pipe, 0); 181 dispatcher0->Init(message_pipe, 0);
178 dispatcher1->Init(message_pipe, 1); 182 dispatcher1->Init(message_pipe, 1);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 DCHECK_EQ(rv, MOJO_RESULT_OK); 356 DCHECK_EQ(rv, MOJO_RESULT_OK);
353 DCHECK(num_handles); 357 DCHECK(num_handles);
354 DCHECK_LE(dispatchers.size(), static_cast<size_t>(*num_handles)); 358 DCHECK_LE(dispatchers.size(), static_cast<size_t>(*num_handles));
355 359
356 base::AutoLock locker(handle_table_lock_); 360 base::AutoLock locker(handle_table_lock_);
357 361
358 for (size_t i = 0; i < dispatchers.size(); i++) { 362 for (size_t i = 0; i < dispatchers.size(); i++) {
359 // TODO(vtl): What should we do if we hit the maximum handle table size 363 // TODO(vtl): What should we do if we hit the maximum handle table size
360 // here? Currently, we'll just fill in those handles with 364 // here? Currently, we'll just fill in those handles with
361 // |MOJO_HANDLE_INVALID| (and return success anyway). 365 // |MOJO_HANDLE_INVALID| (and return success anyway).
366 // TODO(vtl): crbug.com/345911: On failure, we should close the dispatcher
367 // (outside the table lock).
362 handles[i] = AddDispatcherNoLock(dispatchers[i]); 368 handles[i] = AddDispatcherNoLock(dispatchers[i]);
363 LOG_IF(ERROR, handles[i] == MOJO_HANDLE_INVALID) 369 LOG_IF(ERROR, handles[i] == MOJO_HANDLE_INVALID)
364 << "Failed to add dispatcher (" << dispatchers[i].get() << ")"; 370 << "Failed to add dispatcher (" << dispatchers[i].get() << ")";
365 } 371 }
366 } 372 }
367 373
368 return rv; 374 return rv;
369 } 375 }
370 376
371 MojoResult CoreImpl::CreateDataPipe(const MojoCreateDataPipeOptions* options, 377 MojoResult CoreImpl::CreateDataPipe(const MojoCreateDataPipeOptions* options,
(...skipping 19 matching lines...) Expand all
391 397
392 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher( 398 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher(
393 new DataPipeProducerDispatcher()); 399 new DataPipeProducerDispatcher());
394 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher( 400 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher(
395 new DataPipeConsumerDispatcher()); 401 new DataPipeConsumerDispatcher());
396 402
397 MojoHandle producer_handle, consumer_handle; 403 MojoHandle producer_handle, consumer_handle;
398 { 404 {
399 base::AutoLock locker(handle_table_lock_); 405 base::AutoLock locker(handle_table_lock_);
400 406
407 // TODO(vtl): crbug.com/345911: On failure, we should close the dispatcher
408 // (outside the table lock).
401 producer_handle = AddDispatcherNoLock(producer_dispatcher); 409 producer_handle = AddDispatcherNoLock(producer_dispatcher);
402 if (producer_handle == MOJO_HANDLE_INVALID) 410 if (producer_handle == MOJO_HANDLE_INVALID)
403 return MOJO_RESULT_RESOURCE_EXHAUSTED; 411 return MOJO_RESULT_RESOURCE_EXHAUSTED;
404 412
413 // TODO(vtl): crbug.com/345911: On failure, we should close both dispatchers
414 // (outside the table lock).
405 consumer_handle = AddDispatcherNoLock(consumer_dispatcher); 415 consumer_handle = AddDispatcherNoLock(consumer_dispatcher);
406 if (consumer_handle == MOJO_HANDLE_INVALID) { 416 if (consumer_handle == MOJO_HANDLE_INVALID) {
407 handle_table_.erase(producer_handle); 417 handle_table_.erase(producer_handle);
408 return MOJO_RESULT_RESOURCE_EXHAUSTED; 418 return MOJO_RESULT_RESOURCE_EXHAUSTED;
409 } 419 }
410 } 420 }
411 421
412 scoped_refptr<DataPipe> data_pipe(new LocalDataPipe(validated_options)); 422 scoped_refptr<DataPipe> data_pipe(new LocalDataPipe(validated_options));
413 producer_dispatcher->Init(data_pipe); 423 producer_dispatcher->Init(data_pipe);
414 consumer_dispatcher->Init(data_pipe); 424 consumer_dispatcher->Init(data_pipe);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 MojoHandle* shared_buffer_handle) { 502 MojoHandle* shared_buffer_handle) {
493 // TODO(vtl) 503 // TODO(vtl)
494 NOTIMPLEMENTED(); 504 NOTIMPLEMENTED();
495 return MOJO_RESULT_UNIMPLEMENTED; 505 return MOJO_RESULT_UNIMPLEMENTED;
496 } 506 }
497 507
498 MojoResult CoreImpl::DuplicateBufferHandle( 508 MojoResult CoreImpl::DuplicateBufferHandle(
499 MojoHandle buffer_handle, 509 MojoHandle buffer_handle,
500 const MojoDuplicateBufferHandleOptions* options, 510 const MojoDuplicateBufferHandleOptions* options,
501 MojoHandle* new_buffer_handle) { 511 MojoHandle* new_buffer_handle) {
502 // TODO(vtl) 512 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
503 NOTIMPLEMENTED(); 513 if (!dispatcher.get())
504 return MOJO_RESULT_UNIMPLEMENTED; 514 return MOJO_RESULT_INVALID_ARGUMENT;
515
516 if (!VerifyUserPointer<MojoHandle>(new_buffer_handle, 1))
517 return MOJO_RESULT_INVALID_ARGUMENT;
518
519 scoped_refptr<Dispatcher> new_dispatcher;
520 MojoResult result = dispatcher->DuplicateBufferHandle(options,
521 &new_dispatcher);
522 if (result != MOJO_RESULT_OK)
523 return result;
524
525 MojoHandle new_handle;
526 {
527 base::AutoLock locker(handle_table_lock_);
528
529 // TODO(vtl): crbug.com/345911: On failure, we should close the dispatcher
530 // (outside the table lock).
531 new_handle = AddDispatcherNoLock(new_dispatcher);
532 if (new_handle == MOJO_HANDLE_INVALID)
533 return MOJO_RESULT_RESOURCE_EXHAUSTED;
534 }
535
536 *new_buffer_handle = new_handle;
537 return MOJO_RESULT_OK;
505 } 538 }
506 539
507 MojoResult CoreImpl::MapBuffer(MojoHandle buffer_handle, 540 MojoResult CoreImpl::MapBuffer(MojoHandle buffer_handle,
508 uint64_t offset, 541 uint64_t offset,
509 uint64_t num_bytes, 542 uint64_t num_bytes,
510 void** buffer, 543 void** buffer,
511 MojoMapBufferFlags flags) { 544 MojoMapBufferFlags flags) {
512 // TODO(vtl) 545 scoped_refptr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
513 NOTIMPLEMENTED(); 546 if (!dispatcher.get())
514 return MOJO_RESULT_UNIMPLEMENTED; 547 return MOJO_RESULT_INVALID_ARGUMENT;
548
549 MojoResult result = dispatcher->MapBuffer(offset, num_bytes, buffer, flags);
550 if (result != MOJO_RESULT_OK)
551 return result;
552
553 // TODO(vtl): Record the mapping.
554
555 return MOJO_RESULT_OK;
515 } 556 }
516 557
517 MojoResult CoreImpl::UnmapBuffer(void* buffer) { 558 MojoResult CoreImpl::UnmapBuffer(void* buffer) {
518 // TODO(vtl) 559 // TODO(vtl)
519 NOTIMPLEMENTED(); 560 NOTIMPLEMENTED();
520 return MOJO_RESULT_UNIMPLEMENTED; 561 return MOJO_RESULT_UNIMPLEMENTED;
521 } 562 }
522 563
523 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) { 564 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) {
524 if (handle == MOJO_HANDLE_INVALID) 565 if (handle == MOJO_HANDLE_INVALID)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be 642 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be
602 // destroyed, but this would still be required if the waiter were in TLS.) 643 // destroyed, but this would still be required if the waiter were in TLS.)
603 for (i = 0; i < num_added; i++) 644 for (i = 0; i < num_added; i++)
604 dispatchers[i]->RemoveWaiter(&waiter); 645 dispatchers[i]->RemoveWaiter(&waiter);
605 646
606 return rv; 647 return rv;
607 } 648 }
608 649
609 } // namespace system 650 } // namespace system
610 } // namespace mojo 651 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/system/core_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698