| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mojo_test_base.h" | 5 #include "mojo/edk/test/mojo_test_base.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "mojo/edk/embedder/embedder.h" | 10 #include "mojo/edk/embedder/embedder.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 CHECK(g_mach_broker->Init()); | 36 CHECK(g_mach_broker->Init()); |
| 37 SetMachPortProvider(g_mach_broker); | 37 SetMachPortProvider(g_mach_broker); |
| 38 } | 38 } |
| 39 #endif | 39 #endif |
| 40 } | 40 } |
| 41 | 41 |
| 42 MojoTestBase::~MojoTestBase() {} | 42 MojoTestBase::~MojoTestBase() {} |
| 43 | 43 |
| 44 MojoTestBase::ClientController& MojoTestBase::StartClient( | 44 MojoTestBase::ClientController& MojoTestBase::StartClient( |
| 45 const std::string& client_name) { | 45 const std::string& client_name) { |
| 46 clients_.push_back(base::WrapUnique(new ClientController(client_name, this))); | 46 clients_.push_back(base::MakeUnique<ClientController>( |
| 47 client_name, this, process_error_callback_)); |
| 47 return *clients_.back(); | 48 return *clients_.back(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 MojoTestBase::ClientController::ClientController(const std::string& client_name, | 51 MojoTestBase::ClientController::ClientController( |
| 51 MojoTestBase* test) { | 52 const std::string& client_name, |
| 53 MojoTestBase* test, |
| 54 const ProcessErrorCallback& process_error_callback) { |
| 52 #if !defined(OS_IOS) | 55 #if !defined(OS_IOS) |
| 53 #if defined(OS_MACOSX) | 56 #if defined(OS_MACOSX) |
| 54 // This lock needs to be held while launching the child because the Mach port | 57 // This lock needs to be held while launching the child because the Mach port |
| 55 // broker only allows task ports to be received from known child processes. | 58 // broker only allows task ports to be received from known child processes. |
| 56 // However, it can only know the child process's pid after the child has | 59 // However, it can only know the child process's pid after the child has |
| 57 // launched. To prevent a race where the child process sends its task port | 60 // launched. To prevent a race where the child process sends its task port |
| 58 // before the pid has been registered, the lock needs to be held over both | 61 // before the pid has been registered, the lock needs to be held over both |
| 59 // launch and child pid registration. | 62 // launch and child pid registration. |
| 60 base::AutoLock lock(g_mach_broker->GetLock()); | 63 base::AutoLock lock(g_mach_broker->GetLock()); |
| 61 #endif | 64 #endif |
| 65 helper_.set_process_error_callback(process_error_callback); |
| 62 pipe_ = helper_.StartChild(client_name); | 66 pipe_ = helper_.StartChild(client_name); |
| 63 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
| 64 g_mach_broker->AddPlaceholderForPid(helper_.test_child().Handle()); | 68 g_mach_broker->AddPlaceholderForPid(helper_.test_child().Handle()); |
| 65 #endif | 69 #endif |
| 66 #endif | 70 #endif |
| 67 } | 71 } |
| 68 | 72 |
| 69 MojoTestBase::ClientController::~ClientController() { | 73 MojoTestBase::ClientController::~ClientController() { |
| 70 CHECK(was_shutdown_) | 74 CHECK(was_shutdown_) |
| 71 << "Test clients should be waited on explicitly with WaitForShutdown()."; | 75 << "Test clients should be waited on explicitly with WaitForShutdown()."; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), | 302 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), |
| 299 MOJO_RESULT_OK); | 303 MOJO_RESULT_OK); |
| 300 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); | 304 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); |
| 301 | 305 |
| 302 return std::string(buffer.data(), buffer.size()); | 306 return std::string(buffer.data(), buffer.size()); |
| 303 } | 307 } |
| 304 | 308 |
| 305 } // namespace test | 309 } // namespace test |
| 306 } // namespace edk | 310 } // namespace edk |
| 307 } // namespace mojo | 311 } // namespace mojo |
| OLD | NEW |