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

Unified Diff: mojo/edk/system/message_pipe_dispatcher.h

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: mojo/edk/system/message_pipe_dispatcher.h
diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h b/mojo/edk/system/message_pipe_dispatcher.h
similarity index 60%
copy from third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h
copy to mojo/edk/system/message_pipe_dispatcher.h
index 23bb1ed590e2df3f9390735af9747c77a41f6b03..1d42ad4eac9da8667ba3c00fb369b7c688becb87 100644
--- a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h
+++ b/mojo/edk/system/message_pipe_dispatcher.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,21 +6,21 @@
#define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_
#include "base/memory/ref_counted.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
+#include "mojo/edk/system/awakable_list.h"
#include "mojo/edk/system/dispatcher.h"
#include "mojo/edk/system/memory.h"
+#include "mojo/edk/system/raw_channel.h"
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
namespace system {
-class ChannelEndpoint;
-class MessagePipe;
-class MessagePipeDispatcherTransport;
-
// This is the |Dispatcher| implementation for message pipes (created by the
// Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe.
-class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final : public Dispatcher {
+class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final
+ : public Dispatcher, public RawChannel::Delegate {
public:
// The default options to use for |MojoCreateMessagePipe()|. (Real uses
// should obtain this via |ValidateCreateOptions()| with a null |in_options|;
@@ -42,39 +42,28 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final : public Dispatcher {
MojoCreateMessagePipeOptions* out_options);
// Must be called before any other methods. (This method is not thread-safe.)
- void Init(scoped_refptr<MessagePipe> message_pipe,
- unsigned port) MOJO_NOT_THREAD_SAFE;
+ void Init(embedder::ScopedPlatformHandle message_pipe);
// |Dispatcher| public methods:
Type GetType() const override;
- // Creates a |MessagePipe| with a local endpoint (at port 0) and a proxy
- // endpoint, and creates/initializes a |MessagePipeDispatcher| (attached to
- // the message pipe, port 0).
- // TODO(vtl): This currently uses |kDefaultCreateOptions|, which is okay since
- // there aren't any options, but eventually options should be plumbed through.
- static scoped_refptr<MessagePipeDispatcher> CreateRemoteMessagePipe(
- scoped_refptr<ChannelEndpoint>* channel_endpoint);
-
// The "opposite" of |SerializeAndClose()|. (Typically this is called by
// |Dispatcher::Deserialize()|.)
- static scoped_refptr<MessagePipeDispatcher> Deserialize(Channel* channel,
- const void* source,
- size_t size);
+ static scoped_refptr<MessagePipeDispatcher> Deserialize(
+ const void* source,
+ size_t size,
+ embedder::PlatformHandleVector* platform_handles);
private:
- friend class MessagePipeDispatcherTransport;
-
MessagePipeDispatcher();
~MessagePipeDispatcher() override;
- // Gets a dumb pointer to |message_pipe_|. This must be called under the
- // |Dispatcher| lock (that it's a dumb pointer is okay since it's under lock).
- // This is needed when sending handles across processes, where nontrivial,
- // invasive work needs to be done.
- MessagePipe* GetMessagePipeNoLock() const;
- // Similarly for the port.
- unsigned GetPortNoLock() const;
+ void InitWithReadBuffer(embedder::ScopedPlatformHandle message_pipe,
+ char* data,
+ size_t size);
+
+ void InitOnIO();
+ void CloseOnIO();
// |Dispatcher| protected methods:
void CancelAllAwakablesNoLock() override;
@@ -98,41 +87,55 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final : public Dispatcher {
HandleSignalsState* signals_state) override;
void RemoveAwakableImplNoLock(Awakable* awakable,
HandleSignalsState* signals_state) override;
- void StartSerializeImplNoLock(Channel* channel,
- size_t* max_size,
- size_t* max_platform_handles) override
- MOJO_NOT_THREAD_SAFE;
+ void StartSerializeImplNoLock(size_t* max_size,
+ size_t* max_platform_handles) override;
bool EndSerializeAndCloseImplNoLock(
- Channel* channel,
void* destination,
size_t* actual_size,
- embedder::PlatformHandleVector* platform_handles) override
- MOJO_NOT_THREAD_SAFE;
-
- // This will be null if closed.
- scoped_refptr<MessagePipe> message_pipe_ MOJO_GUARDED_BY(mutex());
- unsigned port_ MOJO_GUARDED_BY(mutex());
+ embedder::PlatformHandleVector* platform_handles) override;
+ void TransportStarted() override;
+ void TransportEnded() override;
+
+ // |RawChannel::Delegate methods:
+ void OnReadMessage(
+ const MessageInTransit::View& message_view,
+ embedder::ScopedPlatformHandleVectorPtr platform_handles) override;
+ void OnError(Error error) override;
+
+ // Calls ReleaseHandle and serializes the raw channel. This is split into a
+ // function because it's called in two different ways:
+ // 1) When serializing "live" dispatchers that are passed to MojoWriteMessage,
+ // CreateEquivalentDispatcherAndCloseImplNoLock calls this.
+ // 2) When serializing dispatchers that are attached to deserialized messages
+ // which haven't been consumed by MojoReadMessage, StartSerializeImplNoLock
+ // calls this.
+ void SerializeInternal();
+
+ // Protected by |lock()|:
+ RawChannel* channel_;
+
+ // Queue of incoming messages that we read from RawChannel but haven't been
+ // consumed through MojoReadMessage yet.
+ MessageInTransitQueue message_queue_;
+ // When sending MP, contains serialized message_queue_.
+ bool serialized_;
+ std::vector<char> serialized_message_queue_;
+ std::vector<char> serialized_read_buffer_;
+ embedder::PlatformHandle serialized_platform_handle_;
+ // TODO(jam): stop using this and use shared memory instead since we are
+ // limited to 10K here.
+ AwakableList awakable_list_;
+
+ // if DispatcherTransport crated. must be set before lock() is called to avoid
+ // deadlocks with RawChannel calling us.
+ base::Lock started_transport_;
+
+ bool calling_init_;
+ bool error_;
MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher);
};
-class MessagePipeDispatcherTransport : public DispatcherTransport {
- public:
- explicit MessagePipeDispatcherTransport(DispatcherTransport transport);
-
- MessagePipe* GetMessagePipe() {
- return message_pipe_dispatcher()->GetMessagePipeNoLock();
- }
- unsigned GetPort() { return message_pipe_dispatcher()->GetPortNoLock(); }
-
- private:
- MessagePipeDispatcher* message_pipe_dispatcher() {
- return static_cast<MessagePipeDispatcher*>(dispatcher());
- }
-
- // Copy and assign allowed.
-};
-
} // namespace system
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698