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

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

Issue 1946423002: EDK: Remove Core::AddDispatcher(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 | « mojo/edk/system/core.h ('k') | mojo/edk/system/core_test_base.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/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 handle_table_(GetConfiguration().max_handle_table_size) {} 90 handle_table_(GetConfiguration().max_handle_table_size) {}
91 91
92 Core::~Core() { 92 Core::~Core() {
93 } 93 }
94 94
95 MojoHandle Core::AddHandle(Handle&& handle) { 95 MojoHandle Core::AddHandle(Handle&& handle) {
96 MutexLocker locker(&handle_table_mutex_); 96 MutexLocker locker(&handle_table_mutex_);
97 return handle_table_.AddHandle(std::move(handle)); 97 return handle_table_.AddHandle(std::move(handle));
98 } 98 }
99 99
100 // FIXME
101 MojoHandle Core::AddDispatcher(Dispatcher* dispatcher) {
102 return AddHandle(
103 Handle(RefPtr<Dispatcher>(dispatcher), MOJO_HANDLE_RIGHT_TRANSFER));
104 }
105
106 MojoResult Core::GetDispatcher(MojoHandle handle, 100 MojoResult Core::GetDispatcher(MojoHandle handle,
107 RefPtr<Dispatcher>* dispatcher) { 101 RefPtr<Dispatcher>* dispatcher) {
108 if (handle == MOJO_HANDLE_INVALID) 102 if (handle == MOJO_HANDLE_INVALID)
109 return MOJO_RESULT_INVALID_ARGUMENT; 103 return MOJO_RESULT_INVALID_ARGUMENT;
110 104
111 MutexLocker locker(&handle_table_mutex_); 105 MutexLocker locker(&handle_table_mutex_);
112 return handle_table_.GetDispatcher(handle, dispatcher); 106 return handle_table_.GetDispatcher(handle, dispatcher);
113 } 107 }
114 108
115 MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle, 109 MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 if (result != MOJO_RESULT_OK) 214 if (result != MOJO_RESULT_OK)
221 return result; 215 return result;
222 216
223 auto dispatcher0 = MessagePipeDispatcher::Create(validated_options); 217 auto dispatcher0 = MessagePipeDispatcher::Create(validated_options);
224 auto dispatcher1 = MessagePipeDispatcher::Create(validated_options); 218 auto dispatcher1 = MessagePipeDispatcher::Create(validated_options);
225 219
226 std::pair<MojoHandle, MojoHandle> handle_pair; 220 std::pair<MojoHandle, MojoHandle> handle_pair;
227 { 221 {
228 MutexLocker locker(&handle_table_mutex_); 222 MutexLocker locker(&handle_table_mutex_);
229 handle_pair = handle_table_.AddHandlePair( 223 handle_pair = handle_table_.AddHandlePair(
230 Handle(dispatcher0.Clone(), MOJO_HANDLE_RIGHT_TRANSFER | 224 Handle(dispatcher0.Clone(),
231 MOJO_HANDLE_RIGHT_READ | 225 MessagePipeDispatcher::kDefaultHandleRights),
232 MOJO_HANDLE_RIGHT_WRITE), 226 Handle(dispatcher1.Clone(),
233 Handle(dispatcher1.Clone(), MOJO_HANDLE_RIGHT_TRANSFER | 227 MessagePipeDispatcher::kDefaultHandleRights));
234 MOJO_HANDLE_RIGHT_READ |
235 MOJO_HANDLE_RIGHT_WRITE));
236 } 228 }
237 if (handle_pair.first == MOJO_HANDLE_INVALID) { 229 if (handle_pair.first == MOJO_HANDLE_INVALID) {
238 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); 230 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID);
239 LOG(ERROR) << "Handle table full"; 231 LOG(ERROR) << "Handle table full";
240 dispatcher0->Close(); 232 dispatcher0->Close();
241 dispatcher1->Close(); 233 dispatcher1->Close();
242 return MOJO_RESULT_RESOURCE_EXHAUSTED; 234 return MOJO_RESULT_RESOURCE_EXHAUSTED;
243 } 235 }
244 236
245 auto message_pipe = MessagePipe::CreateLocalLocal(); 237 auto message_pipe = MessagePipe::CreateLocalLocal();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return result; 383 return result;
392 384
393 auto producer_dispatcher = DataPipeProducerDispatcher::Create(); 385 auto producer_dispatcher = DataPipeProducerDispatcher::Create();
394 auto consumer_dispatcher = DataPipeConsumerDispatcher::Create(); 386 auto consumer_dispatcher = DataPipeConsumerDispatcher::Create();
395 387
396 std::pair<MojoHandle, MojoHandle> handle_pair; 388 std::pair<MojoHandle, MojoHandle> handle_pair;
397 { 389 {
398 MutexLocker locker(&handle_table_mutex_); 390 MutexLocker locker(&handle_table_mutex_);
399 handle_pair = handle_table_.AddHandlePair( 391 handle_pair = handle_table_.AddHandlePair(
400 Handle(producer_dispatcher.Clone(), 392 Handle(producer_dispatcher.Clone(),
401 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_WRITE), 393 DataPipeProducerDispatcher::kDefaultHandleRights),
402 Handle(consumer_dispatcher.Clone(), 394 Handle(consumer_dispatcher.Clone(),
403 MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ)); 395 DataPipeConsumerDispatcher::kDefaultHandleRights));
404 } 396 }
405 if (handle_pair.first == MOJO_HANDLE_INVALID) { 397 if (handle_pair.first == MOJO_HANDLE_INVALID) {
406 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID); 398 DCHECK_EQ(handle_pair.second, MOJO_HANDLE_INVALID);
407 LOG(ERROR) << "Handle table full"; 399 LOG(ERROR) << "Handle table full";
408 producer_dispatcher->Close(); 400 producer_dispatcher->Close();
409 consumer_dispatcher->Close(); 401 consumer_dispatcher->Close();
410 return MOJO_RESULT_RESOURCE_EXHAUSTED; 402 return MOJO_RESULT_RESOURCE_EXHAUSTED;
411 } 403 }
412 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID); 404 DCHECK_NE(handle_pair.second, MOJO_HANDLE_INVALID);
413 405
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (result != MOJO_RESULT_OK) 536 if (result != MOJO_RESULT_OK)
545 return result; 537 return result;
546 538
547 auto dispatcher = SharedBufferDispatcher::Create( 539 auto dispatcher = SharedBufferDispatcher::Create(
548 platform_support_, validated_options, num_bytes, &result); 540 platform_support_, validated_options, num_bytes, &result);
549 if (result != MOJO_RESULT_OK) { 541 if (result != MOJO_RESULT_OK) {
550 DCHECK(!dispatcher); 542 DCHECK(!dispatcher);
551 return result; 543 return result;
552 } 544 }
553 545
554 // Note that shared buffer handles are duplicatable (by default). 546 MojoHandle h = AddHandle(
555 MojoHandle h = AddHandle(Handle( 547 Handle(dispatcher.Clone(), SharedBufferDispatcher::kDefaultHandleRights));
556 dispatcher.Clone(), MOJO_HANDLE_RIGHT_DUPLICATE |
557 MOJO_HANDLE_RIGHT_TRANSFER |
558 MOJO_HANDLE_RIGHT_READ | MOJO_HANDLE_RIGHT_WRITE |
559 MOJO_HANDLE_RIGHT_EXECUTE));
560 if (h == MOJO_HANDLE_INVALID) { 548 if (h == MOJO_HANDLE_INVALID) {
561 LOG(ERROR) << "Handle table full"; 549 LOG(ERROR) << "Handle table full";
562 dispatcher->Close(); 550 dispatcher->Close();
563 return MOJO_RESULT_RESOURCE_EXHAUSTED; 551 return MOJO_RESULT_RESOURCE_EXHAUSTED;
564 } 552 }
565 553
566 shared_buffer_handle.Put(h); 554 shared_buffer_handle.Put(h);
567 return MOJO_RESULT_OK; 555 return MOJO_RESULT_OK;
568 } 556 }
569 557
570 MojoResult Core::DuplicateBufferHandle( 558 MojoResult Core::DuplicateBufferHandle(
571 MojoHandle buffer_handle, 559 MojoHandle buffer_handle,
572 UserPointer<const MojoDuplicateBufferHandleOptions> options, 560 UserPointer<const MojoDuplicateBufferHandleOptions> options,
573 UserPointer<MojoHandle> new_buffer_handle) { 561 UserPointer<MojoHandle> new_buffer_handle) {
574 RefPtr<Dispatcher> dispatcher; 562 RefPtr<Dispatcher> dispatcher;
575 MojoResult result = GetDispatcher(buffer_handle, &dispatcher); 563 MojoResult result = GetDispatcher(buffer_handle, &dispatcher);
576 if (result != MOJO_RESULT_OK) 564 if (result != MOJO_RESULT_OK)
577 return result; 565 return result;
578 566
579 // Don't verify |options| here; that's the dispatcher's job. 567 // Don't verify |options| here; that's the dispatcher's job.
580 RefPtr<Dispatcher> new_dispatcher; 568 RefPtr<Dispatcher> new_dispatcher;
581 result = dispatcher->DuplicateBufferHandle(options, &new_dispatcher); 569 result = dispatcher->DuplicateBufferHandle(options, &new_dispatcher);
582 if (result != MOJO_RESULT_OK) 570 if (result != MOJO_RESULT_OK)
583 return result; 571 return result;
584 572
585 MojoHandle new_handle = AddDispatcher(new_dispatcher.get()); 573 // TODO(vtl): This should be done with the original handle's rights.
574 MojoHandle new_handle = AddHandle(Handle(
575 new_dispatcher.Clone(), SharedBufferDispatcher::kDefaultHandleRights));
586 if (new_handle == MOJO_HANDLE_INVALID) { 576 if (new_handle == MOJO_HANDLE_INVALID) {
587 LOG(ERROR) << "Handle table full"; 577 LOG(ERROR) << "Handle table full";
588 new_dispatcher->Close(); 578 new_dispatcher->Close();
589 return MOJO_RESULT_RESOURCE_EXHAUSTED; 579 return MOJO_RESULT_RESOURCE_EXHAUSTED;
590 } 580 }
591 581
592 new_buffer_handle.Put(new_handle); 582 new_buffer_handle.Put(new_handle);
593 return MOJO_RESULT_OK; 583 return MOJO_RESULT_OK;
594 } 584 }
595 585
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 if (signals_states) { 692 if (signals_states) {
703 for (; i < num_handles; i++) 693 for (; i < num_handles; i++)
704 signals_states[i] = dispatchers[i]->GetHandleSignalsState(); 694 signals_states[i] = dispatchers[i]->GetHandleSignalsState();
705 } 695 }
706 696
707 return result; 697 return result;
708 } 698 }
709 699
710 } // namespace system 700 } // namespace system
711 } // namespace mojo 701 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.h ('k') | mojo/edk/system/core_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698