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

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

Issue 728133002: Update mojo sdk to rev e01f9a49449381a5eb430c1fd88bf2cae73ec35a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android + ios gyp fixes Created 6 years, 1 month 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/dispatcher.h ('k') | mojo/edk/system/dispatcher_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/edk/system/dispatcher.h" 5 #include "mojo/edk/system/dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/edk/system/constants.h" 8 #include "mojo/edk/system/configuration.h"
9 #include "mojo/edk/system/message_pipe_dispatcher.h" 9 #include "mojo/edk/system/message_pipe_dispatcher.h"
10 #include "mojo/edk/system/platform_handle_dispatcher.h" 10 #include "mojo/edk/system/platform_handle_dispatcher.h"
11 #include "mojo/edk/system/shared_buffer_dispatcher.h" 11 #include "mojo/edk/system/shared_buffer_dispatcher.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace system { 14 namespace system {
15 15
16 namespace test { 16 namespace test {
17 17
18 // TODO(vtl): Maybe this should be defined in a test-only file instead. 18 // TODO(vtl): Maybe this should be defined in a test-only file instead.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 // static 53 // static
54 bool Dispatcher::TransportDataAccess::EndSerializeAndClose( 54 bool Dispatcher::TransportDataAccess::EndSerializeAndClose(
55 Dispatcher* dispatcher, 55 Dispatcher* dispatcher,
56 Channel* channel, 56 Channel* channel,
57 void* destination, 57 void* destination,
58 size_t* actual_size, 58 size_t* actual_size,
59 embedder::PlatformHandleVector* platform_handles) { 59 embedder::PlatformHandleVector* platform_handles) {
60 DCHECK(dispatcher); 60 DCHECK(dispatcher);
61 return dispatcher->EndSerializeAndClose( 61 return dispatcher->EndSerializeAndClose(channel, destination, actual_size,
62 channel, destination, actual_size, platform_handles); 62 platform_handles);
63 } 63 }
64 64
65 // static 65 // static
66 scoped_refptr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize( 66 scoped_refptr<Dispatcher> Dispatcher::TransportDataAccess::Deserialize(
67 Channel* channel, 67 Channel* channel,
68 int32_t type, 68 int32_t type,
69 const void* source, 69 const void* source,
70 size_t size, 70 size_t size,
71 embedder::PlatformHandleVector* platform_handles) { 71 embedder::PlatformHandleVector* platform_handles) {
72 switch (static_cast<int32_t>(type)) { 72 switch (static_cast<int32_t>(type)) {
73 case kTypeUnknown: 73 case kTypeUnknown:
74 DVLOG(2) << "Deserializing invalid handle"; 74 DVLOG(2) << "Deserializing invalid handle";
75 return scoped_refptr<Dispatcher>(); 75 return nullptr;
76 case kTypeMessagePipe: 76 case kTypeMessagePipe:
77 return scoped_refptr<Dispatcher>( 77 return scoped_refptr<Dispatcher>(
78 MessagePipeDispatcher::Deserialize(channel, source, size)); 78 MessagePipeDispatcher::Deserialize(channel, source, size));
79 case kTypeDataPipeProducer: 79 case kTypeDataPipeProducer:
80 case kTypeDataPipeConsumer: 80 case kTypeDataPipeConsumer:
81 // TODO(vtl): Implement. 81 // TODO(vtl): Implement.
82 LOG(WARNING) << "Deserialization of dispatcher type " << type 82 LOG(WARNING) << "Deserialization of dispatcher type " << type
83 << " not supported"; 83 << " not supported";
84 return scoped_refptr<Dispatcher>(); 84 return nullptr;
85 case kTypeSharedBuffer: 85 case kTypeSharedBuffer:
86 return scoped_refptr<Dispatcher>(SharedBufferDispatcher::Deserialize( 86 return scoped_refptr<Dispatcher>(SharedBufferDispatcher::Deserialize(
87 channel, source, size, platform_handles)); 87 channel, source, size, platform_handles));
88 case kTypePlatformHandle: 88 case kTypePlatformHandle:
89 return scoped_refptr<Dispatcher>(PlatformHandleDispatcher::Deserialize( 89 return scoped_refptr<Dispatcher>(PlatformHandleDispatcher::Deserialize(
90 channel, source, size, platform_handles)); 90 channel, source, size, platform_handles));
91 } 91 }
92 LOG(WARNING) << "Unknown dispatcher type " << type; 92 LOG(WARNING) << "Unknown dispatcher type " << type;
93 return scoped_refptr<Dispatcher>(); 93 return nullptr;
94 } 94 }
95 95
96 MojoResult Dispatcher::Close() { 96 MojoResult Dispatcher::Close() {
97 base::AutoLock locker(lock_); 97 base::AutoLock locker(lock_);
98 if (is_closed_) 98 if (is_closed_)
99 return MOJO_RESULT_INVALID_ARGUMENT; 99 return MOJO_RESULT_INVALID_ARGUMENT;
100 100
101 CloseNoLock(); 101 CloseNoLock();
102 return MOJO_RESULT_OK; 102 return MOJO_RESULT_OK;
103 } 103 }
104 104
105 MojoResult Dispatcher::WriteMessage( 105 MojoResult Dispatcher::WriteMessage(
106 UserPointer<const void> bytes, 106 UserPointer<const void> bytes,
107 uint32_t num_bytes, 107 uint32_t num_bytes,
108 std::vector<DispatcherTransport>* transports, 108 std::vector<DispatcherTransport>* transports,
109 MojoWriteMessageFlags flags) { 109 MojoWriteMessageFlags flags) {
110 DCHECK(!transports || (transports->size() > 0 && 110 DCHECK(!transports ||
111 transports->size() < kMaxMessageNumHandles)); 111 (transports->size() > 0 &&
112 transports->size() < GetConfiguration().max_message_num_handles));
112 113
113 base::AutoLock locker(lock_); 114 base::AutoLock locker(lock_);
114 if (is_closed_) 115 if (is_closed_)
115 return MOJO_RESULT_INVALID_ARGUMENT; 116 return MOJO_RESULT_INVALID_ARGUMENT;
116 117
117 return WriteMessageImplNoLock(bytes, num_bytes, transports, flags); 118 return WriteMessageImplNoLock(bytes, num_bytes, transports, flags);
118 } 119 }
119 120
120 MojoResult Dispatcher::ReadMessage(UserPointer<void> bytes, 121 MojoResult Dispatcher::ReadMessage(UserPointer<void> bytes,
121 UserPointer<uint32_t> num_bytes, 122 UserPointer<uint32_t> num_bytes,
122 DispatcherVector* dispatchers, 123 DispatcherVector* dispatchers,
123 uint32_t* num_dispatchers, 124 uint32_t* num_dispatchers,
124 MojoReadMessageFlags flags) { 125 MojoReadMessageFlags flags) {
125 DCHECK(!num_dispatchers || *num_dispatchers == 0 || 126 DCHECK(!num_dispatchers || *num_dispatchers == 0 ||
126 (dispatchers && dispatchers->empty())); 127 (dispatchers && dispatchers->empty()));
127 128
128 base::AutoLock locker(lock_); 129 base::AutoLock locker(lock_);
129 if (is_closed_) 130 if (is_closed_)
130 return MOJO_RESULT_INVALID_ARGUMENT; 131 return MOJO_RESULT_INVALID_ARGUMENT;
131 132
132 return ReadMessageImplNoLock( 133 return ReadMessageImplNoLock(bytes, num_bytes, dispatchers, num_dispatchers,
133 bytes, num_bytes, dispatchers, num_dispatchers, flags); 134 flags);
134 } 135 }
135 136
136 MojoResult Dispatcher::WriteData(UserPointer<const void> elements, 137 MojoResult Dispatcher::WriteData(UserPointer<const void> elements,
137 UserPointer<uint32_t> num_bytes, 138 UserPointer<uint32_t> num_bytes,
138 MojoWriteDataFlags flags) { 139 MojoWriteDataFlags flags) {
139 base::AutoLock locker(lock_); 140 base::AutoLock locker(lock_);
140 if (is_closed_) 141 if (is_closed_)
141 return MOJO_RESULT_INVALID_ARGUMENT; 142 return MOJO_RESULT_INVALID_ARGUMENT;
142 143
143 return WriteDataImplNoLock(elements, num_bytes, flags); 144 return WriteDataImplNoLock(elements, num_bytes, flags);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // shouldn't be in |Core|'s handle table. 467 // shouldn't be in |Core|'s handle table.
467 is_closed_ = true; 468 is_closed_ = true;
468 469
469 #if !defined(NDEBUG) 470 #if !defined(NDEBUG)
470 // See the comment above |EndSerializeAndCloseImplNoLock()|. In brief: Locking 471 // See the comment above |EndSerializeAndCloseImplNoLock()|. In brief: Locking
471 // isn't actually needed, but we need to satisfy assertions (which we don't 472 // isn't actually needed, but we need to satisfy assertions (which we don't
472 // want to remove or weaken). 473 // want to remove or weaken).
473 base::AutoLock locker(lock_); 474 base::AutoLock locker(lock_);
474 #endif 475 #endif
475 476
476 return EndSerializeAndCloseImplNoLock( 477 return EndSerializeAndCloseImplNoLock(channel, destination, actual_size,
477 channel, destination, actual_size, platform_handles); 478 platform_handles);
478 } 479 }
479 480
480 // DispatcherTransport --------------------------------------------------------- 481 // DispatcherTransport ---------------------------------------------------------
481 482
482 void DispatcherTransport::End() { 483 void DispatcherTransport::End() {
483 DCHECK(dispatcher_); 484 DCHECK(dispatcher_);
484 dispatcher_->lock_.Release(); 485 dispatcher_->lock_.Release();
485 dispatcher_ = nullptr; 486 dispatcher_ = nullptr;
486 } 487 }
487 488
488 } // namespace system 489 } // namespace system
489 } // namespace mojo 490 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher.h ('k') | mojo/edk/system/dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698