| OLD | NEW |
| 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/test/scoped_ipc_support.h" | 5 #include "mojo/edk/test/scoped_ipc_support.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/edk/embedder/embedder.h" | 8 #include "mojo/edk/embedder/embedder.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 namespace test { | 11 namespace test { |
| 12 | 12 |
| 13 ScopedIPCSupport::ScopedIPCSupport( | 13 namespace internal { |
| 14 scoped_refptr<base::TaskRunner> io_thread_task_runner) | 14 |
| 15 : io_thread_task_runner_(io_thread_task_runner), | 15 ScopedIPCSupportBase::ScopedIPCSupportBase( |
| 16 embedder::ProcessType process_type, |
| 17 embedder::ProcessDelegate* process_delegate, |
| 18 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
| 19 embedder::ScopedPlatformHandle platform_handle) |
| 20 : io_thread_task_runner_(io_thread_task_runner.Pass()), |
| 16 event_(true, false) { // Manual reset. | 21 event_(true, false) { // Manual reset. |
| 17 // Note: Run delegate methods on the I/O thread. | 22 // Note: Run delegate methods on the I/O thread. |
| 18 embedder::InitIPCSupport(embedder::ProcessType::NONE, io_thread_task_runner, | 23 embedder::InitIPCSupport(process_type, io_thread_task_runner_, |
| 19 this, io_thread_task_runner, | 24 process_delegate, io_thread_task_runner_, |
| 20 embedder::ScopedPlatformHandle()); | 25 platform_handle.Pass()); |
| 21 } | 26 } |
| 22 | 27 |
| 23 ScopedIPCSupport::~ScopedIPCSupport() { | 28 ScopedIPCSupportBase::~ScopedIPCSupportBase() { |
| 24 if (base::MessageLoop::current() && | 29 if (base::MessageLoop::current() && |
| 25 base::MessageLoop::current()->task_runner() == io_thread_task_runner_) { | 30 base::MessageLoop::current()->task_runner() == io_thread_task_runner_) { |
| 26 embedder::ShutdownIPCSupportOnIOThread(); | 31 embedder::ShutdownIPCSupportOnIOThread(); |
| 27 } else { | 32 } else { |
| 28 embedder::ShutdownIPCSupport(); | 33 embedder::ShutdownIPCSupport(); |
| 29 event_.Wait(); | 34 event_.Wait(); |
| 30 } | 35 } |
| 31 } | 36 } |
| 32 | 37 |
| 38 void ScopedIPCSupportBase::OnShutdownCompleteImpl() { |
| 39 event_.Signal(); |
| 40 } |
| 41 |
| 42 } // namespace internal |
| 43 |
| 44 ScopedIPCSupport::ScopedIPCSupport( |
| 45 scoped_refptr<base::TaskRunner> io_thread_task_runner) |
| 46 : ScopedIPCSupportBase(embedder::ProcessType::NONE, |
| 47 this, |
| 48 io_thread_task_runner.Pass(), |
| 49 embedder::ScopedPlatformHandle()) { |
| 50 } |
| 51 |
| 52 ScopedIPCSupport::~ScopedIPCSupport() { |
| 53 } |
| 54 |
| 33 void ScopedIPCSupport::OnShutdownComplete() { | 55 void ScopedIPCSupport::OnShutdownComplete() { |
| 34 event_.Signal(); | 56 OnShutdownCompleteImpl(); |
| 57 } |
| 58 |
| 59 ScopedMasterIPCSupport::ScopedMasterIPCSupport( |
| 60 scoped_refptr<base::TaskRunner> io_thread_task_runner) |
| 61 : ScopedIPCSupportBase(embedder::ProcessType::MASTER, |
| 62 this, |
| 63 io_thread_task_runner.Pass(), |
| 64 embedder::ScopedPlatformHandle()) { |
| 65 } |
| 66 |
| 67 ScopedMasterIPCSupport::ScopedMasterIPCSupport( |
| 68 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
| 69 base::Callback<void(embedder::SlaveInfo slave_info)> on_slave_disconnect) |
| 70 : ScopedIPCSupportBase(embedder::ProcessType::MASTER, |
| 71 this, |
| 72 io_thread_task_runner.Pass(), |
| 73 embedder::ScopedPlatformHandle()), |
| 74 on_slave_disconnect_(on_slave_disconnect) { |
| 75 } |
| 76 |
| 77 ScopedMasterIPCSupport::~ScopedMasterIPCSupport() { |
| 78 } |
| 79 |
| 80 void ScopedMasterIPCSupport::OnShutdownComplete() { |
| 81 OnShutdownCompleteImpl(); |
| 82 } |
| 83 |
| 84 void ScopedMasterIPCSupport::OnSlaveDisconnect(embedder::SlaveInfo slave_info) { |
| 85 if (!on_slave_disconnect_.is_null()) |
| 86 on_slave_disconnect_.Run(slave_info); |
| 87 } |
| 88 |
| 89 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( |
| 90 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
| 91 embedder::ScopedPlatformHandle platform_handle) |
| 92 : ScopedIPCSupportBase(embedder::ProcessType::SLAVE, |
| 93 this, |
| 94 io_thread_task_runner.Pass(), |
| 95 platform_handle.Pass()) { |
| 96 } |
| 97 |
| 98 ScopedSlaveIPCSupport::ScopedSlaveIPCSupport( |
| 99 scoped_refptr<base::TaskRunner> io_thread_task_runner, |
| 100 embedder::ScopedPlatformHandle platform_handle, |
| 101 base::Closure on_master_disconnect) |
| 102 : ScopedIPCSupportBase(embedder::ProcessType::SLAVE, |
| 103 this, |
| 104 io_thread_task_runner.Pass(), |
| 105 platform_handle.Pass()), |
| 106 on_master_disconnect_(on_master_disconnect) { |
| 107 } |
| 108 |
| 109 ScopedSlaveIPCSupport::~ScopedSlaveIPCSupport() { |
| 110 } |
| 111 |
| 112 void ScopedSlaveIPCSupport::OnShutdownComplete() { |
| 113 OnShutdownCompleteImpl(); |
| 114 } |
| 115 |
| 116 void ScopedSlaveIPCSupport::OnMasterDisconnect() { |
| 117 if (!on_master_disconnect_.is_null()) |
| 118 on_master_disconnect_.Run(); |
| 35 } | 119 } |
| 36 | 120 |
| 37 } // namespace test | 121 } // namespace test |
| 38 } // namespace mojo | 122 } // namespace mojo |
| OLD | NEW |