Index: third_party/mojo/src/mojo/edk/system/data_pipe.h |
diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe.h b/third_party/mojo/src/mojo/edk/system/data_pipe.h |
index dfac644d537ba282f2974aeead1aabaef7028273..8096e011844ca362ca9ccdb821654bca18b84d73 100644 |
--- a/third_party/mojo/src/mojo/edk/system/data_pipe.h |
+++ b/third_party/mojo/src/mojo/edk/system/data_pipe.h |
@@ -9,10 +9,10 @@ |
#include "base/compiler_specific.h" |
#include "base/macros.h" |
-#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/synchronization/lock.h" |
#include "mojo/edk/embedder/platform_handle_vector.h" |
+#include "mojo/edk/system/channel_endpoint_client.h" |
#include "mojo/edk/system/handle_signals_state.h" |
#include "mojo/edk/system/memory.h" |
#include "mojo/edk/system/system_impl_export.h" |
@@ -25,7 +25,9 @@ namespace system { |
class Awakable; |
class AwakableList; |
class Channel; |
+class ChannelEndpoint; |
class DataPipeImpl; |
+class MessageInTransitQueue; |
// |DataPipe| is a base class for secondary objects implementing data pipes, |
// similar to |MessagePipe| (see the explanatory comment in core.cc). It is |
@@ -33,8 +35,7 @@ class DataPipeImpl; |
// Its subclasses implement the three cases: local producer and consumer, local |
// producer and remote consumer, and remote producer and local consumer. This |
// class is thread-safe. |
-class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
- : public base::RefCountedThreadSafe<DataPipe> { |
+class MOJO_SYSTEM_IMPL_EXPORT DataPipe : public ChannelEndpointClient { |
public: |
// The default options for |MojoCreateDataPipe()|. (Real uses should obtain |
// this via |ValidateCreateOptions()| with a null |in_options|; this is |
@@ -58,6 +59,45 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
static DataPipe* CreateLocal( |
const MojoCreateDataPipeOptions& validated_options); |
+ // Creates a data pipe with a remote producer and a local consumer, using an |
+ // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking |
+ // |message_queue|'s contents as already-received incoming messages. If |
+ // |channel_endpoint| is null, this will create a "half-open" data pipe (with |
+ // only the consumer open). Note that this may fail, in which case it returns |
+ // null. |
+ static DataPipe* CreateRemoteProducerFromExisting( |
+ const MojoCreateDataPipeOptions& validated_options, |
+ MessageInTransitQueue* message_queue, |
+ ChannelEndpoint* channel_endpoint); |
+ |
+ // Creates a data pipe with a local producer and a remote consumer, using an |
+ // existing |ChannelEndpoint| (whose |ReplaceClient()| it'll call) and taking |
+ // |message_queue|'s contents as already-received incoming messages |
+ // (|message_queue| may be null). If |channel_endpoint| is null, this will |
+ // create a "half-open" data pipe (with only the producer open). Note that |
+ // this may fail, in which case it returns null. |
+ static DataPipe* CreateRemoteConsumerFromExisting( |
+ const MojoCreateDataPipeOptions& validated_options, |
+ size_t consumer_num_bytes, |
+ MessageInTransitQueue* message_queue, |
+ ChannelEndpoint* channel_endpoint); |
+ |
+ // Used by |DataPipeProducerDispatcher::Deserialize()|. Returns true on |
+ // success (in which case, |*data_pipe| is set appropriately) and false on |
+ // failure (in which case |*data_pipe| may or may not be set to null). |
+ static bool ProducerDeserialize(Channel* channel, |
+ const void* source, |
+ size_t size, |
+ scoped_refptr<DataPipe>* data_pipe); |
+ |
+ // Used by |DataPipeConsumerDispatcher::Deserialize()|. Returns true on |
+ // success (in which case, |*data_pipe| is set appropriately) and false on |
+ // failure (in which case |*data_pipe| may or may not be set to null). |
+ static bool ConsumerDeserialize(Channel* channel, |
+ const void* source, |
+ size_t size, |
+ scoped_refptr<DataPipe>* data_pipe); |
+ |
// These are called by the producer dispatcher to implement its methods of |
// corresponding names. |
void ProducerCancelAllAwakables(); |
@@ -120,6 +160,14 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
// The following are only to be used by |DataPipeImpl| (and its subclasses): |
+ // Replaces |impl_| with |new_impl| (which must not be null). For use when |
+ // serializing data pipe dispatchers (i.e., in |ProducerEndSerialize()| and |
+ // |ConsumerEndSerialize()|). Returns the old value of |impl_| (in case the |
+ // caller needs to manage its lifetime). |
+ scoped_ptr<DataPipeImpl> ReplaceImplNoLock(scoped_ptr<DataPipeImpl> new_impl); |
+ void SetProducerClosedNoLock(); |
+ void SetConsumerClosedNoLock(); |
+ |
void ProducerCloseNoLock(); |
void ConsumerCloseNoLock(); |
@@ -127,10 +175,6 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
const MojoCreateDataPipeOptions& validated_options() const { |
return validated_options_; |
} |
- bool may_discard() const { |
- return (validated_options_.flags & |
- MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD); |
- } |
size_t element_num_bytes() const { |
return validated_options_.element_num_bytes; |
} |
@@ -174,8 +218,6 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
} |
private: |
- friend class base::RefCountedThreadSafe<DataPipe>; |
- |
// |validated_options| should be the output of |ValidateOptions()|. In |
// particular: |struct_size| is ignored (so |validated_options| must be the |
// current version of the struct) and |capacity_num_bytes| must be nonzero. |
@@ -190,11 +232,18 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
scoped_ptr<DataPipeImpl> impl); |
virtual ~DataPipe(); |
+ // |ChannelEndpointClient| implementation: |
+ bool OnReadMessage(unsigned port, MessageInTransit* message) override; |
+ void OnDetachFromChannel(unsigned port) override; |
+ |
void AwakeProducerAwakablesForStateChangeNoLock( |
const HandleSignalsState& new_producer_state); |
void AwakeConsumerAwakablesForStateChangeNoLock( |
const HandleSignalsState& new_consumer_state); |
+ void SetProducerClosed(); |
+ void SetConsumerClosed(); |
+ |
bool has_local_producer_no_lock() const { |
lock_.AssertAcquired(); |
return !!producer_awakable_list_; |
@@ -204,7 +253,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe |
return !!consumer_awakable_list_; |
} |
- MSVC_SUPPRESS_WARNING(4324) // Suppress an alignment warning on 64-bit MSVC. |
+ MSVC_SUPPRESS_WARNING(4324) |
const MojoCreateDataPipeOptions validated_options_; |
mutable base::Lock lock_; // Protects the following members. |