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

Side by Side Diff: mojo/edk/test/mojo_test_base.cc

Issue 2227553002: Support mojo connections between unrelated peer processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/edk/test/mojo_test_base.h ('k') | mojo/edk/test/multiprocess_test_helper.h » ('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 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 26 matching lines...) Expand all
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::MakeUnique<ClientController>( 46 clients_.push_back(base::MakeUnique<ClientController>(
47 client_name, this, process_error_callback_)); 47 client_name, this, process_error_callback_, launch_type_));
48 return *clients_.back(); 48 return *clients_.back();
49 } 49 }
50 50
51 MojoTestBase::ClientController::ClientController( 51 MojoTestBase::ClientController::ClientController(
52 const std::string& client_name, 52 const std::string& client_name,
53 MojoTestBase* test, 53 MojoTestBase* test,
54 const ProcessErrorCallback& process_error_callback) { 54 const ProcessErrorCallback& process_error_callback,
55 LaunchType launch_type) {
55 #if !defined(OS_IOS) 56 #if !defined(OS_IOS)
56 #if defined(OS_MACOSX) 57 #if defined(OS_MACOSX)
57 // This lock needs to be held while launching the child because the Mach port 58 // This lock needs to be held while launching the child because the Mach port
58 // broker only allows task ports to be received from known child processes. 59 // broker only allows task ports to be received from known child processes.
59 // However, it can only know the child process's pid after the child has 60 // However, it can only know the child process's pid after the child has
60 // launched. To prevent a race where the child process sends its task port 61 // launched. To prevent a race where the child process sends its task port
61 // before the pid has been registered, the lock needs to be held over both 62 // before the pid has been registered, the lock needs to be held over both
62 // launch and child pid registration. 63 // launch and child pid registration.
63 base::AutoLock lock(g_mach_broker->GetLock()); 64 base::AutoLock lock(g_mach_broker->GetLock());
64 #endif 65 #endif
65 helper_.set_process_error_callback(process_error_callback); 66 helper_.set_process_error_callback(process_error_callback);
66 pipe_ = helper_.StartChild(client_name); 67 pipe_ = helper_.StartChild(client_name, launch_type);
67 #if defined(OS_MACOSX) 68 #if defined(OS_MACOSX)
68 g_mach_broker->AddPlaceholderForPid(helper_.test_child().Handle()); 69 g_mach_broker->AddPlaceholderForPid(helper_.test_child().Handle());
69 #endif 70 #endif
70 #endif 71 #endif
71 } 72 }
72 73
73 MojoTestBase::ClientController::~ClientController() { 74 MojoTestBase::ClientController::~ClientController() {
74 CHECK(was_shutdown_) 75 CHECK(was_shutdown_)
75 << "Test clients should be waited on explicitly with WaitForShutdown()."; 76 << "Test clients should be waited on explicitly with WaitForShutdown().";
76 } 77 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), 303 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
303 MOJO_RESULT_OK); 304 MOJO_RESULT_OK);
304 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); 305 CHECK_EQ(num_bytes, static_cast<uint32_t>(size));
305 306
306 return std::string(buffer.data(), buffer.size()); 307 return std::string(buffer.data(), buffer.size());
307 } 308 }
308 309
309 } // namespace test 310 } // namespace test
310 } // namespace edk 311 } // namespace edk
311 } // namespace mojo 312 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/test/mojo_test_base.h ('k') | mojo/edk/test/multiprocess_test_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698