| 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 #ifndef MOJO_SYSTEM_DISPATCHER_H_ | 5 #ifndef MOJO_SYSTEM_DISPATCHER_H_ |
| 6 #define MOJO_SYSTEM_DISPATCHER_H_ | 6 #define MOJO_SYSTEM_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "mojo/public/c/system/core.h" | 17 #include "mojo/public/c/system/core.h" |
| 18 // TODO(vtl): We need this since we can't forward declare | 18 // TODO(vtl): We need this since we can't forward declare |
| 19 // |RawSharedBuffer::Mapping|. Maybe fix this. | 19 // |RawSharedBuffer::Mapping|. Maybe fix this. |
| 20 #include "mojo/system/raw_shared_buffer.h" | 20 #include "mojo/system/raw_shared_buffer.h" |
| 21 #include "mojo/system/system_impl_export.h" | 21 #include "mojo/system/system_impl_export.h" |
| 22 | 22 |
| 23 namespace mojo { | 23 namespace mojo { |
| 24 namespace system { | 24 namespace system { |
| 25 | 25 |
| 26 class Channel; | 26 class Channel; |
| 27 class CoreImpl; | 27 class CoreImpl; |
| 28 class Dispatcher; | 28 class Dispatcher; |
| 29 class DispatcherTransport; | 29 class DispatcherTransport; |
| 30 class HandleTable; |
| 30 class LocalMessagePipeEndpoint; | 31 class LocalMessagePipeEndpoint; |
| 31 class MessageInTransit; | 32 class MessageInTransit; |
| 32 class ProxyMessagePipeEndpoint; | 33 class ProxyMessagePipeEndpoint; |
| 33 class Waiter; | 34 class Waiter; |
| 34 | 35 |
| 35 namespace test { | 36 namespace test { |
| 36 | 37 |
| 37 // Test helper. We need to declare it here so we can friend it. | 38 // Test helper. We need to declare it here so we can friend it. |
| 38 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport DispatcherTryStartTransport( | 39 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport DispatcherTryStartTransport( |
| 39 Dispatcher* dispatcher); | 40 Dispatcher* dispatcher); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // - |MOJO_RESULT_ALREADY_EXISTS| if |flags| is already satisfied; | 120 // - |MOJO_RESULT_ALREADY_EXISTS| if |flags| is already satisfied; |
| 120 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and | 121 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and |
| 121 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible | 122 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible |
| 122 // that |flags| will ever be satisfied. | 123 // that |flags| will ever be satisfied. |
| 123 MojoResult AddWaiter(Waiter* waiter, | 124 MojoResult AddWaiter(Waiter* waiter, |
| 124 MojoWaitFlags flags, | 125 MojoWaitFlags flags, |
| 125 MojoResult wake_result); | 126 MojoResult wake_result); |
| 126 void RemoveWaiter(Waiter* waiter); | 127 void RemoveWaiter(Waiter* waiter); |
| 127 | 128 |
| 128 // A dispatcher must be put into a special state in order to be sent across a | 129 // A dispatcher must be put into a special state in order to be sent across a |
| 129 // message pipe. Outside of tests, only |CoreImplAccess| is allowed to do | 130 // message pipe. Outside of tests, only |HandleTableAccess| is allowed to do |
| 130 // this, since there are requirements on the handle table (see below). | 131 // this, since there are requirements on the handle table (see below). |
| 131 // | 132 // |
| 132 // In this special state, only a restricted set of operations is allowed. | 133 // In this special state, only a restricted set of operations is allowed. |
| 133 // These are the ones available as |DispatcherTransport| methods. Other | 134 // These are the ones available as |DispatcherTransport| methods. Other |
| 134 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| | 135 // |Dispatcher| methods must not be called until |DispatcherTransport::End()| |
| 135 // has been called. | 136 // has been called. |
| 136 class CoreImplAccess { | 137 class HandleTableAccess { |
| 137 private: | 138 private: |
| 138 friend class CoreImpl; | 139 friend class CoreImpl; |
| 140 friend class HandleTable; |
| 139 // Tests also need this, to avoid needing |CoreImpl|. | 141 // Tests also need this, to avoid needing |CoreImpl|. |
| 140 friend DispatcherTransport test::DispatcherTryStartTransport(Dispatcher*); | 142 friend DispatcherTransport test::DispatcherTryStartTransport(Dispatcher*); |
| 141 | 143 |
| 142 // This must be called under the handle table lock and only if the handle | 144 // This must be called under the handle table lock and only if the handle |
| 143 // table entry is not marked busy. The caller must maintain a reference to | 145 // table entry is not marked busy. The caller must maintain a reference to |
| 144 // |dispatcher| until |DispatcherTransport::End()| is called. | 146 // |dispatcher| until |DispatcherTransport::End()| is called. |
| 145 static DispatcherTransport TryStartTransport(Dispatcher* dispatcher); | 147 static DispatcherTransport TryStartTransport(Dispatcher* dispatcher); |
| 146 }; | 148 }; |
| 147 | 149 |
| 148 // A |MessageInTransit| may serialize dispatchers that are attached to it to a | 150 // A |MessageInTransit| may serialize dispatchers that are attached to it to a |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 295 |
| 294 // This protects the following members as well as any state added by | 296 // This protects the following members as well as any state added by |
| 295 // subclasses. | 297 // subclasses. |
| 296 mutable base::Lock lock_; | 298 mutable base::Lock lock_; |
| 297 bool is_closed_; | 299 bool is_closed_; |
| 298 | 300 |
| 299 DISALLOW_COPY_AND_ASSIGN(Dispatcher); | 301 DISALLOW_COPY_AND_ASSIGN(Dispatcher); |
| 300 }; | 302 }; |
| 301 | 303 |
| 302 // Wrapper around a |Dispatcher| pointer, while it's being processed to be | 304 // Wrapper around a |Dispatcher| pointer, while it's being processed to be |
| 303 // passed in a message pipe. See the comment about |Dispatcher::CoreImplAccess| | 305 // passed in a message pipe. See the comment about |
| 304 // for more details. | 306 // |Dispatcher::HandleTableAccess| for more details. |
| 305 // | 307 // |
| 306 // Note: This class is deliberately "thin" -- no more expensive than a | 308 // Note: This class is deliberately "thin" -- no more expensive than a |
| 307 // |Dispatcher*|. | 309 // |Dispatcher*|. |
| 308 class MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport { | 310 class MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport { |
| 309 public: | 311 public: |
| 310 DispatcherTransport() : dispatcher_(NULL) {} | 312 DispatcherTransport() : dispatcher_(NULL) {} |
| 311 | 313 |
| 312 void End(); | 314 void End(); |
| 313 | 315 |
| 314 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } | 316 Dispatcher::Type GetType() const { return dispatcher_->GetType(); } |
| 315 bool IsBusy() const { return dispatcher_->IsBusyNoLock(); } | 317 bool IsBusy() const { return dispatcher_->IsBusyNoLock(); } |
| 316 void Close() { dispatcher_->CloseNoLock(); } | 318 void Close() { dispatcher_->CloseNoLock(); } |
| 317 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndClose() { | 319 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndClose() { |
| 318 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(); | 320 return dispatcher_->CreateEquivalentDispatcherAndCloseNoLock(); |
| 319 } | 321 } |
| 320 | 322 |
| 321 bool is_valid() const { return !!dispatcher_; } | 323 bool is_valid() const { return !!dispatcher_; } |
| 322 | 324 |
| 323 protected: | 325 protected: |
| 324 Dispatcher* dispatcher() { return dispatcher_; } | 326 Dispatcher* dispatcher() { return dispatcher_; } |
| 325 | 327 |
| 326 private: | 328 private: |
| 327 friend class Dispatcher::CoreImplAccess; | 329 friend class Dispatcher::HandleTableAccess; |
| 328 | 330 |
| 329 explicit DispatcherTransport(Dispatcher* dispatcher) | 331 explicit DispatcherTransport(Dispatcher* dispatcher) |
| 330 : dispatcher_(dispatcher) {} | 332 : dispatcher_(dispatcher) {} |
| 331 | 333 |
| 332 Dispatcher* dispatcher_; | 334 Dispatcher* dispatcher_; |
| 333 | 335 |
| 334 // Copy and assign allowed. | 336 // Copy and assign allowed. |
| 335 }; | 337 }; |
| 336 | 338 |
| 337 } // namespace system | 339 } // namespace system |
| 338 } // namespace mojo | 340 } // namespace mojo |
| 339 | 341 |
| 340 #endif // MOJO_SYSTEM_DISPATCHER_H_ | 342 #endif // MOJO_SYSTEM_DISPATCHER_H_ |
| OLD | NEW |