OLD | NEW |
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 Loading... |
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)) { |
(...skipping 27 matching lines...) Expand all Loading... |
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 Loading... |
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 |
OLD | NEW |