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

Side by Side Diff: ipc/ipc_channel_mojo.cc

Issue 2316963005: Reworks Channel pausing behavior (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
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_mojo_unittest.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 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_channel_mojo.h" 5 #include "ipc/ipc_channel_mojo.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // ChannelMojo from a different thread. 275 // ChannelMojo from a different thread.
276 bootstrap_ = 276 bootstrap_ =
277 MojoBootstrap::Create(std::move(handle), mode, this, ipc_task_runner); 277 MojoBootstrap::Create(std::move(handle), mode, this, ipc_task_runner);
278 } 278 }
279 279
280 ChannelMojo::~ChannelMojo() { 280 ChannelMojo::~ChannelMojo() {
281 Close(); 281 Close();
282 } 282 }
283 283
284 bool ChannelMojo::Connect() { 284 bool ChannelMojo::Connect() {
285 if (!ConnectPaused())
286 return false;
287
288 Unpause(true);
289 return true;
290 }
291
292 bool ChannelMojo::ConnectPaused() {
293 WillConnect(); 285 WillConnect();
294 286
295 DCHECK(!task_runner_); 287 DCHECK(!task_runner_);
296 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 288 task_runner_ = base::ThreadTaskRunnerHandle::Get();
297 DCHECK(!message_reader_); 289 DCHECK(!message_reader_);
298 290
299 bootstrap_->Connect(); 291 bootstrap_->Connect();
300 return true; 292 return true;
301 } 293 }
302 294
295 void ChannelMojo::Pause() {
296 bootstrap_->Pause();
297 }
298
303 void ChannelMojo::Unpause(bool flush) { 299 void ChannelMojo::Unpause(bool flush) {
304 bootstrap_->Start(); 300 bootstrap_->Unpause();
305
306 // Ensure that no matter what messages have been queued so far, the first
307 // message we send is always the peer PID.
308 DCHECK(message_reader_);
309 message_reader_->sender()->SetPeerPid(GetSelfPID());
310
311 if (flush) 301 if (flush)
312 Flush(); 302 Flush();
313 } 303 }
314 304
315 void ChannelMojo::Flush() { 305 void ChannelMojo::Flush() {
316 bootstrap_->Flush(); 306 bootstrap_->Flush();
317 } 307 }
318 308
319 void ChannelMojo::Close() { 309 void ChannelMojo::Close() {
320 // NOTE: The MessagePipeReader's destructor may re-enter this function. Use 310 // NOTE: The MessagePipeReader's destructor may re-enter this function. Use
321 // caution when changing this method. 311 // caution when changing this method.
322 std::unique_ptr<internal::MessagePipeReader> reader = 312 std::unique_ptr<internal::MessagePipeReader> reader =
323 std::move(message_reader_); 313 std::move(message_reader_);
324 reader.reset(); 314 reader.reset();
325 315
326 base::AutoLock lock(associated_interface_lock_); 316 base::AutoLock lock(associated_interface_lock_);
327 associated_interfaces_.clear(); 317 associated_interfaces_.clear();
328 } 318 }
329 319
330 // MojoBootstrap::Delegate implementation 320 // MojoBootstrap::Delegate implementation
331 void ChannelMojo::OnPipesAvailable(mojom::ChannelAssociatedPtr sender, 321 void ChannelMojo::OnPipesAvailable(mojom::ChannelAssociatedPtr sender,
332 mojom::ChannelAssociatedRequest receiver) { 322 mojom::ChannelAssociatedRequest receiver) {
323 sender->SetPeerPid(GetSelfPID());
333 message_reader_.reset(new internal::MessagePipeReader( 324 message_reader_.reset(new internal::MessagePipeReader(
334 pipe_, std::move(sender), std::move(receiver), this)); 325 pipe_, std::move(sender), std::move(receiver), this));
335 } 326 }
336 327
337 void ChannelMojo::OnPipeError() { 328 void ChannelMojo::OnPipeError() {
338 DCHECK(task_runner_); 329 DCHECK(task_runner_);
339 if (task_runner_->RunsTasksOnCurrentThread()) { 330 if (task_runner_->RunsTasksOnCurrentThread()) {
340 listener_->OnChannelError(); 331 listener_->OnChannelError();
341 } else { 332 } else {
342 task_runner_->PostTask( 333 task_runner_->PostTask(
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 495 }
505 496
506 void ChannelMojo::GetGenericRemoteAssociatedInterface( 497 void ChannelMojo::GetGenericRemoteAssociatedInterface(
507 const std::string& name, 498 const std::string& name,
508 mojo::ScopedInterfaceEndpointHandle handle) { 499 mojo::ScopedInterfaceEndpointHandle handle) {
509 if (message_reader_) 500 if (message_reader_)
510 message_reader_->GetRemoteInterface(name, std::move(handle)); 501 message_reader_->GetRemoteInterface(name, std::move(handle));
511 } 502 }
512 503
513 } // namespace IPC 504 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_mojo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698