Chromium Code Reviews| Index: mojo/edk/system/dispatcher.h |
| diff --git a/mojo/edk/system/dispatcher.h b/mojo/edk/system/dispatcher.h |
| index 8bdff2834cf0ffca91d1372d57311e8730140aee..ffbab53cda007e42894f8133495a56bc053b294c 100644 |
| --- a/mojo/edk/system/dispatcher.h |
| +++ b/mojo/edk/system/dispatcher.h |
| @@ -11,6 +11,8 @@ |
| #include <ostream> |
| #include <vector> |
| +#include "base/callback.h" |
| +#include "base/containers/stack_container.h" |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -39,6 +41,29 @@ using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; |
| class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
| : public base::RefCountedThreadSafe<Dispatcher> { |
| public: |
| + using WatchCallback = |
| + base::Callback<void(MojoResult, MojoHandleSignalsState)>; |
| + |
| + // Context associated with a single EDK request. |
| + class RequestContext { |
| + public: |
| + static const size_t kFinalizersStackBufferSize = 4; |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
Shouldn't these be private?
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
Done
|
| + using FinalizerList = |
| + base::StackVector<base::Closure, kFinalizersStackBufferSize>; |
| + |
| + RequestContext(); |
| + ~RequestContext(); |
| + |
| + // Adds |callback| to the context's list of finalizers. These are called |
| + // when the context is destroyed, at a time when no EDK locks are held. |
| + void AddFinalizer(const base::Closure& callback); |
|
Anand Mistry (off Chromium)
2016/02/29 12:03:35
Hmm... Since you're already making an effort to av
Ken Rockot(use gerrit already)
2016/02/29 20:59:06
I agree, base::Callback is overkill. To support re
|
| + |
| + private: |
| + FinalizerList finalizers_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RequestContext); |
| + }; |
| + |
| struct DispatcherInTransit { |
| DispatcherInTransit(); |
| ~DispatcherInTransit(); |
| @@ -62,7 +87,18 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
| // All Dispatchers must minimally implement these methods. |
| virtual Type GetType() const = 0; |
| - virtual MojoResult Close() = 0; |
| + virtual MojoResult Close(RequestContext* request_context) = 0; |
| + |
| + ///////////// Watch API //////////////////// |
| + |
| + // NOTE: The Dispatcher implementation MUST NOT hold any locks at any point |
| + // during which it chooses to run |callback|. |
| + virtual MojoResult Watch(MojoHandleSignals signals, |
| + const WatchCallback& callback, |
| + uintptr_t context, |
| + RequestContext* request_context); |
| + |
| + virtual MojoResult CancelWatch(uintptr_t context); |
| ///////////// Message pipe API ///////////// |
| @@ -70,13 +106,15 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
| uint32_t num_bytes, |
| const DispatcherInTransit* dispatchers, |
| uint32_t num_dispatchers, |
| - MojoWriteMessageFlags flags); |
| + MojoWriteMessageFlags flags, |
| + RequestContext* request_context); |
| virtual MojoResult ReadMessage(void* bytes, |
| uint32_t* num_bytes, |
| MojoHandle* handles, |
| uint32_t* num_handles, |
| - MojoReadMessageFlags flags); |
| + MojoReadMessageFlags flags, |
| + RequestContext* request_context); |
| ///////////// Shared buffer API ///////////// |
| @@ -207,16 +245,16 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher |
| // Does whatever is necessary to begin transit of the dispatcher. This |
| // should return |true| if transit is OK, or false if the underlying resource |
| // is deemed busy by the implementation. |
| - virtual bool BeginTransit(); |
| + virtual bool BeginTransit(RequestContext* request_context); |
| // Does whatever is necessary to complete transit of the dispatcher, including |
| // closure. This is only called upon successfully transmitting an outgoing |
| // message containing this serialized dispatcher. |
| - virtual void CompleteTransitAndClose(); |
| + virtual void CompleteTransitAndClose(RequestContext* request_context); |
| // Does whatever is necessary to cancel transit of the dispatcher. The |
| // dispatcher should remain in a working state and resume normal operation. |
| - virtual void CancelTransit(); |
| + virtual void CancelTransit(RequestContext* request_context); |
| // Deserializes a specific dispatcher type from an incoming message. |
| static scoped_refptr<Dispatcher> Deserialize( |