summaryrefslogtreecommitdiffstats
path: root/ipc/mojo/ipc_message_pipe_reader.h
diff options
context:
space:
mode:
authorsammc <sammc@chromium.org>2016-03-07 14:38:04 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-07 22:39:37 +0000
commite4d0abd0d7fdd7b62aef9d151b8d4c05062ab4c9 (patch)
tree50ffc0f3c0190bdb17678a34b3202332b793c08f /ipc/mojo/ipc_message_pipe_reader.h
parent407d2458d1294dd019b6aec72aba33e4777bad37 (diff)
downloadchromium_src-e4d0abd0d7fdd7b62aef9d151b8d4c05062ab4c9.zip
chromium_src-e4d0abd0d7fdd7b62aef9d151b8d4c05062ab4c9.tar.gz
chromium_src-e4d0abd0d7fdd7b62aef9d151b8d4c05062ab4c9.tar.bz2
Change IPC::ChannelMojo to use associated interfaces.
BUG=579813 Review URL: https://codereview.chromium.org/1669493005 Cr-Commit-Position: refs/heads/master@{#379669}
Diffstat (limited to 'ipc/mojo/ipc_message_pipe_reader.h')
-rw-r--r--ipc/mojo/ipc_message_pipe_reader.h61
1 files changed, 19 insertions, 42 deletions
diff --git a/ipc/mojo/ipc_message_pipe_reader.h b/ipc/mojo/ipc_message_pipe_reader.h
index 3758123..7120fc60 100644
--- a/ipc/mojo/ipc_message_pipe_reader.h
+++ b/ipc/mojo/ipc_message_pipe_reader.h
@@ -16,7 +16,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_checker.h"
#include "ipc/ipc_message.h"
+#include "ipc/mojo/ipc.mojom.h"
#include "mojo/public/c/environment/async_waiter.h"
+#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/system/core.h"
namespace IPC {
@@ -40,11 +42,11 @@ class AsyncHandleWaiter;
// be called on any thread. All |Delegate| functions will be called on the IO
// thread.
//
-class MessagePipeReader {
+class MessagePipeReader : public mojom::Channel {
public:
class Delegate {
public:
- virtual void OnMessageReceived(Message& message) = 0;
+ virtual void OnMessageReceived(const Message& message) = 0;
virtual void OnPipeClosed(MessagePipeReader* reader) = 0;
virtual void OnPipeError(MessagePipeReader* reader) = 0;
};
@@ -65,60 +67,35 @@ class MessagePipeReader {
};
// Both parameters must be non-null.
- // Build a reader that reads messages from |handle| and lets |delegate| know.
- // Note that MessagePipeReader doesn't delete |delete|.
- MessagePipeReader(mojo::ScopedMessagePipeHandle handle, Delegate* delegate);
- virtual ~MessagePipeReader();
-
- MojoHandle handle() const { return handle_copy_; }
-
- // Returns received bytes.
- const std::vector<char>& data_buffer() const {
- return data_buffer_;
- }
-
- // Delegate received handles ownership. The subclass should take the
- // ownership over in its OnMessageReceived(). They will leak otherwise.
- void TakeHandleBuffer(std::vector<MojoHandle>* handle_buffer) {
- handle_buffer_.swap(*handle_buffer);
- }
+ // Build a reader that reads messages from |receive_handle| and lets
+ // |delegate| know.
+ // Note that MessagePipeReader doesn't delete |delegate|.
+ MessagePipeReader(mojom::ChannelAssociatedPtr sender,
+ mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
+ Delegate* delegate);
+ ~MessagePipeReader() override;
// Close and destroy the MessagePipe.
void Close();
// Close the mesage pipe with notifying the client with the error.
void CloseWithError(MojoResult error);
- void CloseWithErrorLater(MojoResult error);
- void CloseWithErrorIfPending();
// Return true if the MessagePipe is alive.
- bool IsValid() { return pipe_.is_valid(); }
+ bool IsValid() { return sender_; }
bool Send(scoped_ptr<Message> message);
- void ReadMessagesThenWait();
- private:
- void OnMessageReceived();
+ protected:
void OnPipeClosed();
void OnPipeError(MojoResult error);
- MojoResult ReadMessageBytes();
- void PipeIsReady(MojoResult wait_result);
- void ReadAvailableMessages();
-
- std::vector<char> data_buffer_;
- std::vector<MojoHandle> handle_buffer_;
- mojo::ScopedMessagePipeHandle pipe_;
- // Constant copy of the message pipe handle. For use by Send(), which can run
- // concurrently on non-IO threads.
- // TODO(amistry): This isn't quite right because handles can be re-used and
- // using this can run into the ABA problem. Currently, this is highly unlikely
- // because Mojo internally uses an increasing uint32_t as handle values, but
- // this could change. See crbug.com/524894.
- const MojoHandle handle_copy_;
- // |delegate_| and |async_waiter_| are null once the message pipe is closed.
+ private:
+ void Receive(mojom::MessagePtr message) override;
+
+ // |delegate_| is null once the message pipe is closed.
Delegate* delegate_;
- scoped_ptr<AsyncHandleWaiter> async_waiter_;
- base::subtle::Atomic32 pending_send_error_;
+ mojom::ChannelAssociatedPtr sender_;
+ mojo::AssociatedBinding<mojom::Channel> binding_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(MessagePipeReader);