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

Side by Side Diff: mojo/edk/system/child_broker.cc

Issue 1529303004: Convert Pass()→std::move() in mojo/edk/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/edk/js/tests/js_to_cpp_tests.cc ('k') | mojo/edk/system/child_broker_host.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/edk/system/child_broker.h" 5 #include "mojo/edk/system/child_broker.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "mojo/edk/embedder/embedder_internal.h" 11 #include "mojo/edk/embedder/embedder_internal.h"
10 #include "mojo/edk/embedder/platform_channel_pair.h" 12 #include "mojo/edk/embedder/platform_channel_pair.h"
11 #include "mojo/edk/system/broker_messages.h" 13 #include "mojo/edk/system/broker_messages.h"
12 #include "mojo/edk/system/message_pipe_dispatcher.h" 14 #include "mojo/edk/system/message_pipe_dispatcher.h"
13 15
14 namespace mojo { 16 namespace mojo {
15 namespace edk { 17 namespace edk {
16 18
17 ChildBroker* ChildBroker::GetInstance() { 19 ChildBroker* ChildBroker::GetInstance() {
18 return base::Singleton< 20 return base::Singleton<
19 ChildBroker, base::LeakySingletonTraits<ChildBroker>>::get(); 21 ChildBroker, base::LeakySingletonTraits<ChildBroker>>::get();
20 } 22 }
21 23
22 void ChildBroker::SetChildBrokerHostHandle(ScopedPlatformHandle handle) { 24 void ChildBroker::SetChildBrokerHostHandle(ScopedPlatformHandle handle) {
23 ScopedPlatformHandle parent_async_channel_handle; 25 ScopedPlatformHandle parent_async_channel_handle;
24 #if defined(OS_POSIX) 26 #if defined(OS_POSIX)
25 parent_async_channel_handle = handle.Pass(); 27 parent_async_channel_handle = std::move(handle);
26 #else 28 #else
27 // On Windows we have two pipes to the parent. The first is for the token 29 // On Windows we have two pipes to the parent. The first is for the token
28 // exchange for creating and passing handles, since the child needs the 30 // exchange for creating and passing handles, since the child needs the
29 // parent's help if it is sandboxed. The second is the same as POSIX, which is 31 // parent's help if it is sandboxed. The second is the same as POSIX, which is
30 // used for multiplexing related messages. So on Windows, we send the second 32 // used for multiplexing related messages. So on Windows, we send the second
31 // pipe as the first string over the first one. 33 // pipe as the first string over the first one.
32 parent_sync_channel_ = handle.Pass(); 34 parent_sync_channel_ = handle.Pass();
33 35
34 HANDLE parent_handle = INVALID_HANDLE_VALUE; 36 HANDLE parent_handle = INVALID_HANDLE_VALUE;
35 DWORD bytes_read = 0; 37 DWORD bytes_read = 0;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 pending_inprocess_connects_[pipe_id] = message_pipe; 114 pending_inprocess_connects_[pipe_id] = message_pipe;
113 return; 115 return;
114 } 116 }
115 // Both ends of the message pipe are in the same process. 117 // Both ends of the message pipe are in the same process.
116 // First, tell the browser side that to remove its bookkeeping for a pending 118 // First, tell the browser side that to remove its bookkeeping for a pending
117 // connect, since it'll never get the other side. 119 // connect, since it'll never get the other side.
118 120
119 data.type = CANCEL_CONNECT_MESSAGE_PIPE; 121 data.type = CANCEL_CONNECT_MESSAGE_PIPE;
120 scoped_ptr<MessageInTransit> message(new MessageInTransit( 122 scoped_ptr<MessageInTransit> message(new MessageInTransit(
121 MessageInTransit::Type::MESSAGE, sizeof(data), &data)); 123 MessageInTransit::Type::MESSAGE, sizeof(data), &data));
122 WriteAsyncMessage(message.Pass()); 124 WriteAsyncMessage(std::move(message));
123 125
124 if (!in_process_pipes_channel1_) { 126 if (!in_process_pipes_channel1_) {
125 ScopedPlatformHandle server_handle, client_handle; 127 ScopedPlatformHandle server_handle, client_handle;
126 #if defined(OS_WIN) 128 #if defined(OS_WIN)
127 CreatePlatformChannelPairNoLock(&server_handle, &client_handle); 129 CreatePlatformChannelPairNoLock(&server_handle, &client_handle);
128 #else 130 #else
129 PlatformChannelPair channel_pair; 131 PlatformChannelPair channel_pair;
130 server_handle = channel_pair.PassServerHandle(); 132 server_handle = channel_pair.PassServerHandle();
131 client_handle = channel_pair.PassClientHandle(); 133 client_handle = channel_pair.PassClientHandle();
132 #endif 134 #endif
133 in_process_pipes_channel1_ = new RoutedRawChannel( 135 in_process_pipes_channel1_ = new RoutedRawChannel(
134 server_handle.Pass(), 136 std::move(server_handle),
135 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this))); 137 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
136 in_process_pipes_channel2_ = new RoutedRawChannel( 138 in_process_pipes_channel2_ = new RoutedRawChannel(
137 client_handle.Pass(), 139 std::move(client_handle),
138 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this))); 140 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
139 } 141 }
140 142
141 AttachMessagePipe(pending_connects_[pipe_id], pipe_id, 143 AttachMessagePipe(pending_connects_[pipe_id], pipe_id,
142 in_process_pipes_channel1_); 144 in_process_pipes_channel1_);
143 AttachMessagePipe(message_pipe, pipe_id, in_process_pipes_channel2_); 145 AttachMessagePipe(message_pipe, pipe_id, in_process_pipes_channel2_);
144 pending_connects_.erase(pipe_id); 146 pending_connects_.erase(pipe_id);
145 return; 147 return;
146 } 148 }
147 149
148 data.type = CONNECT_MESSAGE_PIPE; 150 data.type = CONNECT_MESSAGE_PIPE;
149 scoped_ptr<MessageInTransit> message(new MessageInTransit( 151 scoped_ptr<MessageInTransit> message(new MessageInTransit(
150 MessageInTransit::Type::MESSAGE, sizeof(data), &data)); 152 MessageInTransit::Type::MESSAGE, sizeof(data), &data));
151 pending_connects_[pipe_id] = message_pipe; 153 pending_connects_[pipe_id] = message_pipe;
152 WriteAsyncMessage(message.Pass()); 154 WriteAsyncMessage(std::move(message));
153 } 155 }
154 156
155 void ChildBroker::CloseMessagePipe( 157 void ChildBroker::CloseMessagePipe(
156 uint64_t pipe_id, MessagePipeDispatcher* message_pipe) { 158 uint64_t pipe_id, MessagePipeDispatcher* message_pipe) {
157 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()); 159 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
158 CHECK(connected_pipes_.find(message_pipe) != connected_pipes_.end()); 160 CHECK(connected_pipes_.find(message_pipe) != connected_pipes_.end());
159 connected_pipes_[message_pipe]->RemoveRoute(pipe_id); 161 connected_pipes_[message_pipe]->RemoveRoute(pipe_id);
160 connected_pipes_.erase(message_pipe); 162 connected_pipes_.erase(message_pipe);
161 } 163 }
162 164
(...skipping 21 matching lines...) Expand all
184 if (type == CONNECT_TO_PROCESS) { 186 if (type == CONNECT_TO_PROCESS) {
185 DCHECK_EQ(platform_handles->size(), 1u); 187 DCHECK_EQ(platform_handles->size(), 1u);
186 ScopedPlatformHandle handle((*platform_handles.get())[0]); 188 ScopedPlatformHandle handle((*platform_handles.get())[0]);
187 (*platform_handles.get())[0] = PlatformHandle(); 189 (*platform_handles.get())[0] = PlatformHandle();
188 190
189 const ConnectToProcessMessage* message = 191 const ConnectToProcessMessage* message =
190 static_cast<const ConnectToProcessMessage*>(message_view.bytes()); 192 static_cast<const ConnectToProcessMessage*>(message_view.bytes());
191 193
192 CHECK(channels_.find(message->process_id) == channels_.end()); 194 CHECK(channels_.find(message->process_id) == channels_.end());
193 channels_[message->process_id] = new RoutedRawChannel( 195 channels_[message->process_id] = new RoutedRawChannel(
194 handle.Pass(), 196 std::move(handle),
195 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this))); 197 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
196 } else if (type == PEER_PIPE_CONNECTED) { 198 } else if (type == PEER_PIPE_CONNECTED) {
197 DCHECK(!platform_handles); 199 DCHECK(!platform_handles);
198 const PeerPipeConnectedMessage* message = 200 const PeerPipeConnectedMessage* message =
199 static_cast<const PeerPipeConnectedMessage*>(message_view.bytes()); 201 static_cast<const PeerPipeConnectedMessage*>(message_view.bytes());
200 202
201 uint64_t pipe_id = message->pipe_id; 203 uint64_t pipe_id = message->pipe_id;
202 uint64_t peer_pid = message->process_id; 204 uint64_t peer_pid = message->process_id;
203 205
204 CHECK(pending_connects_.find(pipe_id) != pending_connects_.end()); 206 CHECK(pending_connects_.find(pipe_id) != pending_connects_.end());
(...skipping 25 matching lines...) Expand all
230 channels_.erase(it.first); 232 channels_.erase(it.first);
231 break; 233 break;
232 } 234 }
233 } 235 }
234 } 236 }
235 237
236 void ChildBroker::WriteAsyncMessage(scoped_ptr<MessageInTransit> message) { 238 void ChildBroker::WriteAsyncMessage(scoped_ptr<MessageInTransit> message) {
237 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()); 239 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
238 message->set_route_id(kBrokerRouteId); 240 message->set_route_id(kBrokerRouteId);
239 if (parent_async_channel_) { 241 if (parent_async_channel_) {
240 parent_async_channel_->channel()->WriteMessage(message.Pass()); 242 parent_async_channel_->channel()->WriteMessage(std::move(message));
241 } else { 243 } else {
242 async_channel_queue_.AddMessage(message.Pass()); 244 async_channel_queue_.AddMessage(std::move(message));
243 } 245 }
244 } 246 }
245 247
246 void ChildBroker::InitAsyncChannel( 248 void ChildBroker::InitAsyncChannel(
247 ScopedPlatformHandle parent_async_channel_handle) { 249 ScopedPlatformHandle parent_async_channel_handle) {
248 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread()); 250 DCHECK(internal::g_io_thread_task_runner->RunsTasksOnCurrentThread());
249 251
250 parent_async_channel_ = new RoutedRawChannel( 252 parent_async_channel_ = new RoutedRawChannel(
251 parent_async_channel_handle.Pass() , 253 std::move(parent_async_channel_handle),
252 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this))); 254 base::Bind(&ChildBroker::ChannelDestructed, base::Unretained(this)));
253 parent_async_channel_->AddRoute(kBrokerRouteId, this); 255 parent_async_channel_->AddRoute(kBrokerRouteId, this);
254 while (!async_channel_queue_.IsEmpty()) { 256 while (!async_channel_queue_.IsEmpty()) {
255 parent_async_channel_->channel()->WriteMessage( 257 parent_async_channel_->channel()->WriteMessage(
256 async_channel_queue_.GetMessage()); 258 async_channel_queue_.GetMessage());
257 } 259 }
258 260
259 while (!pending_inprocess_connects_.empty()) { 261 while (!pending_inprocess_connects_.empty()) {
260 ConnectMessagePipe(pending_inprocess_connects_.begin()->first, 262 ConnectMessagePipe(pending_inprocess_connects_.begin()->first,
261 pending_inprocess_connects_.begin()->second); 263 pending_inprocess_connects_.begin()->second);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (WriteAndReadResponse(&message, handles, response_size)) { 324 if (WriteAndReadResponse(&message, handles, response_size)) {
323 server->reset(PlatformHandle(handles[0])); 325 server->reset(PlatformHandle(handles[0]));
324 client->reset(PlatformHandle(handles[1])); 326 client->reset(PlatformHandle(handles[1]));
325 } 327 }
326 } 328 }
327 329
328 #endif 330 #endif
329 331
330 } // namespace edk 332 } // namespace edk
331 } // namespace mojo 333 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/js/tests/js_to_cpp_tests.cc ('k') | mojo/edk/system/child_broker_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698