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

Side by Side Diff: ipc/ipc_message_pipe_reader.cc

Issue 2301123004: Mojo Channel: Fix deferred proxy dispatch; support paused channels (Closed)
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "ipc/ipc_message_pipe_reader.h" 5 #include "ipc/ipc_message_pipe_reader.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "ipc/ipc_channel_mojo.h" 18 #include "ipc/ipc_channel_mojo.h"
19 #include "mojo/public/cpp/bindings/message.h" 19 #include "mojo/public/cpp/bindings/message.h"
20 20
21 namespace IPC { 21 namespace IPC {
22 namespace internal { 22 namespace internal {
23 23
24 namespace {
25
26 // Used by Send() to capture a serialized Channel::Receive message.
27 class MessageSerializer : public mojo::MessageReceiverWithResponder {
28 public:
29 MessageSerializer() {}
30 ~MessageSerializer() override {}
31
32 mojo::Message* message() { return &message_; }
33
34 private:
35 // mojo::MessageReceiverWithResponder
36 bool Accept(mojo::Message* message) override {
37 message_ = std::move(*message);
38 return true;
39 }
40
41 bool AcceptWithResponder(mojo::Message* message,
42 mojo::MessageReceiver* responder) override {
43 NOTREACHED();
44 return false;
45 }
46
47 mojo::Message message_;
48
49 DISALLOW_COPY_AND_ASSIGN(MessageSerializer);
50 };
51
52 } // namespace
53
54 MessagePipeReader::MessagePipeReader( 24 MessagePipeReader::MessagePipeReader(
55 mojo::MessagePipeHandle pipe, 25 mojo::MessagePipeHandle pipe,
56 mojom::ChannelAssociatedPtr sender, 26 mojom::ChannelAssociatedPtr sender,
57 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver, 27 mojo::AssociatedInterfaceRequest<mojom::Channel> receiver,
58 MessagePipeReader::Delegate* delegate) 28 MessagePipeReader::Delegate* delegate)
59 : delegate_(delegate), 29 : delegate_(delegate),
60 sender_(std::move(sender)), 30 sender_(std::move(sender)),
61 binding_(this, std::move(receiver)), 31 binding_(this, std::move(receiver)),
62 sender_interface_id_(sender_.interface_id()),
63 sender_pipe_(pipe) { 32 sender_pipe_(pipe) {
64 sender_.set_connection_error_handler( 33 sender_.set_connection_error_handler(
65 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this), 34 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
66 MOJO_RESULT_FAILED_PRECONDITION)); 35 MOJO_RESULT_FAILED_PRECONDITION));
67 binding_.set_connection_error_handler( 36 binding_.set_connection_error_handler(
68 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this), 37 base::Bind(&MessagePipeReader::OnPipeError, base::Unretained(this),
69 MOJO_RESULT_FAILED_PRECONDITION)); 38 MOJO_RESULT_FAILED_PRECONDITION));
70 } 39 }
71 40
72 MessagePipeReader::~MessagePipeReader() { 41 MessagePipeReader::~MessagePipeReader() {
(...skipping 17 matching lines...) Expand all
90 MojoResult result = MOJO_RESULT_OK; 59 MojoResult result = MOJO_RESULT_OK;
91 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles); 60 result = ChannelMojo::ReadFromMessageAttachmentSet(message.get(), &handles);
92 if (result != MOJO_RESULT_OK) 61 if (result != MOJO_RESULT_OK)
93 return false; 62 return false;
94 63
95 std::vector<uint8_t> data(message->size()); 64 std::vector<uint8_t> data(message->size());
96 std::copy(reinterpret_cast<const uint8_t*>(message->data()), 65 std::copy(reinterpret_cast<const uint8_t*>(message->data()),
97 reinterpret_cast<const uint8_t*>(message->data()) + message->size(), 66 reinterpret_cast<const uint8_t*>(message->data()) + message->size(),
98 data.data()); 67 data.data());
99 68
100 MessageSerializer serializer; 69 if (!sender_)
101 mojom::ChannelProxy proxy(&serializer); 70 return false;
102 proxy.Receive(data, std::move(handles));
103 mojo::Message* mojo_message = serializer.message();
104 71
105 size_t num_handles = mojo_message->handles()->size(); 72 sender_->Receive(data, std::move(handles));
106 DCHECK_LE(num_handles, std::numeric_limits<uint32_t>::max());
107
108 mojo_message->set_interface_id(sender_interface_id_);
109 result = mojo::WriteMessageNew(sender_pipe_, mojo_message->TakeMojoMessage(),
110 MOJO_WRITE_MESSAGE_FLAG_NONE);
111 73
112 DVLOG(4) << "Send " << message->type() << ": " << message->size(); 74 DVLOG(4) << "Send " << message->type() << ": " << message->size();
113 return result == MOJO_RESULT_OK; 75 return true;
114 } 76 }
115 77
116 void MessagePipeReader::GetRemoteInterface( 78 void MessagePipeReader::GetRemoteInterface(
117 const std::string& name, 79 const std::string& name,
118 mojo::ScopedInterfaceEndpointHandle handle) { 80 mojo::ScopedInterfaceEndpointHandle handle) {
119 if (!sender_.is_bound()) 81 if (!sender_.is_bound())
120 return; 82 return;
121 mojom::GenericInterfaceAssociatedRequest request; 83 mojom::GenericInterfaceAssociatedRequest request;
122 request.Bind(std::move(handle)); 84 request.Bind(std::move(handle));
123 sender_->GetAssociatedInterface(name, std::move(request)); 85 sender_->GetAssociatedInterface(name, std::move(request));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 127
166 Close(); 128 Close();
167 129
168 // NOTE: The delegate call below may delete |this|. 130 // NOTE: The delegate call below may delete |this|.
169 if (delegate_) 131 if (delegate_)
170 delegate_->OnPipeError(); 132 delegate_->OnPipeError();
171 } 133 }
172 134
173 } // namespace internal 135 } // namespace internal
174 } // namespace IPC 136 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698