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

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

Issue 140403002: Mojo: Add the ability to hook up a channel to the embedder API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 11 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 | « mojo/system/core_impl.h ('k') | mojo/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/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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 CoreImpl::HandleTableEntry::HandleTableEntry( 78 CoreImpl::HandleTableEntry::HandleTableEntry(
79 const scoped_refptr<Dispatcher>& dispatcher) 79 const scoped_refptr<Dispatcher>& dispatcher)
80 : dispatcher(dispatcher), 80 : dispatcher(dispatcher),
81 busy(false) { 81 busy(false) {
82 } 82 }
83 83
84 CoreImpl::HandleTableEntry::~HandleTableEntry() { 84 CoreImpl::HandleTableEntry::~HandleTableEntry() {
85 DCHECK(!busy); 85 DCHECK(!busy);
86 } 86 }
87 87
88 // static 88 CoreImpl::CoreImpl()
89 void CoreImpl::Init() { 89 : next_handle_(MOJO_HANDLE_INVALID + 1) {
90 Core::Init(new CoreImpl()); 90 }
91
92 CoreImpl::~CoreImpl() {
93 // This should usually not be reached (the singleton lives forever), except in
94 // tests.
95 }
96
97 MojoHandle CoreImpl::AddDispatcher(
98 const scoped_refptr<Dispatcher>& dispatcher) {
99 base::AutoLock locker(handle_table_lock_);
100 return AddDispatcherNoLock(dispatcher);
91 } 101 }
92 102
93 MojoTimeTicks CoreImpl::GetTimeTicksNow() { 103 MojoTimeTicks CoreImpl::GetTimeTicksNow() {
94 return base::TimeTicks::Now().ToInternalValue(); 104 return base::TimeTicks::Now().ToInternalValue();
95 } 105 }
96 106
97 MojoResult CoreImpl::Close(MojoHandle handle) { 107 MojoResult CoreImpl::Close(MojoHandle handle) {
98 if (handle == MOJO_HANDLE_INVALID) 108 if (handle == MOJO_HANDLE_INVALID)
99 return MOJO_RESULT_INVALID_ARGUMENT; 109 return MOJO_RESULT_INVALID_ARGUMENT;
100 110
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 MojoResult CoreImpl::EndReadData(MojoHandle data_pipe_consumer_handle, 474 MojoResult CoreImpl::EndReadData(MojoHandle data_pipe_consumer_handle,
465 uint32_t num_bytes_read) { 475 uint32_t num_bytes_read) {
466 scoped_refptr<Dispatcher> dispatcher( 476 scoped_refptr<Dispatcher> dispatcher(
467 GetDispatcher(data_pipe_consumer_handle)); 477 GetDispatcher(data_pipe_consumer_handle));
468 if (!dispatcher.get()) 478 if (!dispatcher.get())
469 return MOJO_RESULT_INVALID_ARGUMENT; 479 return MOJO_RESULT_INVALID_ARGUMENT;
470 480
471 return dispatcher->EndReadData(num_bytes_read); 481 return dispatcher->EndReadData(num_bytes_read);
472 } 482 }
473 483
474 CoreImpl::CoreImpl()
475 : next_handle_(MOJO_HANDLE_INVALID + 1) {
476 }
477
478 CoreImpl::~CoreImpl() {
479 // This should usually not be reached (the singleton lives forever), except in
480 // tests.
481 }
482
483 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) { 484 scoped_refptr<Dispatcher> CoreImpl::GetDispatcher(MojoHandle handle) {
484 if (handle == MOJO_HANDLE_INVALID) 485 if (handle == MOJO_HANDLE_INVALID)
485 return NULL; 486 return NULL;
486 487
487 base::AutoLock locker(handle_table_lock_); 488 base::AutoLock locker(handle_table_lock_);
488 HandleTableMap::iterator it = handle_table_.find(handle); 489 HandleTableMap::iterator it = handle_table_.find(handle);
489 if (it == handle_table_.end()) 490 if (it == handle_table_.end())
490 return NULL; 491 return NULL;
491 492
492 return it->second.dispatcher; 493 return it->second.dispatcher;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be 563 // |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be
563 // destroyed, but this would still be required if the waiter were in TLS.) 564 // destroyed, but this would still be required if the waiter were in TLS.)
564 for (i = 0; i < num_added; i++) 565 for (i = 0; i < num_added; i++)
565 dispatchers[i]->RemoveWaiter(&waiter); 566 dispatchers[i]->RemoveWaiter(&waiter);
566 567
567 return rv; 568 return rv;
568 } 569 }
569 570
570 } // namespace system 571 } // namespace system
571 } // namespace mojo 572 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/core_impl.h ('k') | mojo/system/core_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698