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

Side by Side Diff: mojo/system/message_pipe_dispatcher.cc

Issue 588193004: Mojo: Have |ProxyMessagePipeEndpoint|s constructed with a |ChannelEndpoint|. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « mojo/system/message_pipe_dispatcher.h ('k') | mojo/system/message_pipe_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/system/message_pipe_dispatcher.h" 5 #include "mojo/system/message_pipe_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/system/channel.h" 8 #include "mojo/system/channel.h"
9 #include "mojo/system/channel_endpoint.h" 9 #include "mojo/system/channel_endpoint.h"
10 #include "mojo/system/constants.h" 10 #include "mojo/system/constants.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 message_pipe_ = message_pipe; 77 message_pipe_ = message_pipe;
78 port_ = port; 78 port_ = port;
79 } 79 }
80 80
81 Dispatcher::Type MessagePipeDispatcher::GetType() const { 81 Dispatcher::Type MessagePipeDispatcher::GetType() const {
82 return kTypeMessagePipe; 82 return kTypeMessagePipe;
83 } 83 }
84 84
85 // static 85 // static
86 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> > 86 scoped_refptr<MessagePipeDispatcher>
87 MessagePipeDispatcher::CreateRemoteMessagePipe() { 87 MessagePipeDispatcher::CreateRemoteMessagePipe(
88 scoped_refptr<MessagePipe> message_pipe(MessagePipe::CreateLocalProxy()); 88 scoped_refptr<ChannelEndpoint>* channel_endpoint) {
89 scoped_refptr<MessagePipe> message_pipe(
90 MessagePipe::CreateLocalProxy(channel_endpoint));
89 scoped_refptr<MessagePipeDispatcher> dispatcher( 91 scoped_refptr<MessagePipeDispatcher> dispatcher(
90 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); 92 new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions));
91 dispatcher->Init(message_pipe, 0); 93 dispatcher->Init(message_pipe, 0);
92 94 return dispatcher;
93 return std::make_pair(dispatcher, message_pipe);
94 } 95 }
95 96
96 // static 97 // static
97 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize( 98 scoped_refptr<MessagePipeDispatcher> MessagePipeDispatcher::Deserialize(
98 Channel* channel, 99 Channel* channel,
99 const void* source, 100 const void* source,
100 size_t size) { 101 size_t size) {
101 if (size != sizeof(SerializedMessagePipeDispatcher)) { 102 if (size != sizeof(SerializedMessagePipeDispatcher)) {
102 LOG(ERROR) << "Invalid serialized message pipe dispatcher"; 103 LOG(ERROR) << "Invalid serialized message pipe dispatcher";
103 return scoped_refptr<MessagePipeDispatcher>(); 104 return scoped_refptr<MessagePipeDispatcher>();
104 } 105 }
105 106
106 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> > 107 scoped_refptr<ChannelEndpoint> channel_endpoint;
107 remote_message_pipe = CreateRemoteMessagePipe(); 108 scoped_refptr<MessagePipeDispatcher> dispatcher =
109 CreateRemoteMessagePipe(&channel_endpoint);
108 110
109 MessageInTransit::EndpointId remote_id = 111 MessageInTransit::EndpointId remote_id =
110 static_cast<const SerializedMessagePipeDispatcher*>(source)->endpoint_id; 112 static_cast<const SerializedMessagePipeDispatcher*>(source)->endpoint_id;
111 if (remote_id == MessageInTransit::kInvalidEndpointId) { 113 if (remote_id == MessageInTransit::kInvalidEndpointId) {
112 // This means that the other end was closed, and there were no messages 114 // This means that the other end was closed, and there were no messages
113 // enqueued for us. 115 // enqueued for us.
114 // TODO(vtl): This is wrong. We should produce a "dead" message pipe 116 // TODO(vtl): This is wrong. We should produce a "dead" message pipe
115 // dispatcher. 117 // dispatcher.
116 NOTIMPLEMENTED(); 118 NOTIMPLEMENTED();
117 return scoped_refptr<MessagePipeDispatcher>(); 119 return scoped_refptr<MessagePipeDispatcher>();
118 } 120 }
119 MessageInTransit::EndpointId local_id = 121 MessageInTransit::EndpointId local_id =
120 channel->AttachEndpoint(make_scoped_refptr( 122 channel->AttachEndpoint(channel_endpoint);
121 new ChannelEndpoint(remote_message_pipe.second.get(), 1)));
122 if (local_id == MessageInTransit::kInvalidEndpointId) { 123 if (local_id == MessageInTransit::kInvalidEndpointId) {
123 LOG(ERROR) << "Failed to deserialize message pipe dispatcher (failed to " 124 LOG(ERROR) << "Failed to deserialize message pipe dispatcher (failed to "
124 "attach; remote ID = " << remote_id << ")"; 125 "attach; remote ID = " << remote_id << ")";
125 return scoped_refptr<MessagePipeDispatcher>(); 126 return scoped_refptr<MessagePipeDispatcher>();
126 } 127 }
127 DVLOG(2) << "Deserializing message pipe dispatcher (remote ID = " << remote_id 128 DVLOG(2) << "Deserializing message pipe dispatcher (remote ID = " << remote_id
128 << ", new local ID = " << local_id << ")"; 129 << ", new local ID = " << local_id << ")";
129 130
130 if (!channel->RunMessagePipeEndpoint(local_id, remote_id)) { 131 if (!channel->RunMessagePipeEndpoint(local_id, remote_id)) {
131 // In general, this shouldn't fail, since we generated |local_id| locally. 132 // In general, this shouldn't fail, since we generated |local_id| locally.
132 NOTREACHED(); 133 NOTREACHED();
133 return scoped_refptr<MessagePipeDispatcher>(); 134 return scoped_refptr<MessagePipeDispatcher>();
134 } 135 }
135 136
136 // TODO(vtl): FIXME -- Need some error handling here. 137 // TODO(vtl): FIXME -- Need some error handling here.
137 channel->RunRemoteMessagePipeEndpoint(local_id, remote_id); 138 channel->RunRemoteMessagePipeEndpoint(local_id, remote_id);
138 return remote_message_pipe.first; 139 return dispatcher;
139 } 140 }
140 141
141 MessagePipeDispatcher::~MessagePipeDispatcher() { 142 MessagePipeDispatcher::~MessagePipeDispatcher() {
142 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. 143 // |Close()|/|CloseImplNoLock()| should have taken care of the pipe.
143 DCHECK(!message_pipe_.get()); 144 DCHECK(!message_pipe_.get());
144 } 145 }
145 146
146 MessagePipe* MessagePipeDispatcher::GetMessagePipeNoLock() const { 147 MessagePipe* MessagePipeDispatcher::GetMessagePipeNoLock() const {
147 lock().AssertAcquired(); 148 lock().AssertAcquired();
148 return message_pipe_.get(); 149 return message_pipe_.get();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // MessagePipeDispatcherTransport ---------------------------------------------- 275 // MessagePipeDispatcherTransport ----------------------------------------------
275 276
276 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( 277 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport(
277 DispatcherTransport transport) 278 DispatcherTransport transport)
278 : DispatcherTransport(transport) { 279 : DispatcherTransport(transport) {
279 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe); 280 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe);
280 } 281 }
281 282
282 } // namespace system 283 } // namespace system
283 } // namespace mojo 284 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/message_pipe_dispatcher.h ('k') | mojo/system/message_pipe_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698