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

Unified Diff: chrome/test/base/mojo_test_connector.cc

Issue 2737353003: Update MojoTestConnection Service Registration (Closed)
Patch Set: Minimize filter to test arc startup crash Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/buildbot/filters/mash.browser_tests.filter » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/base/mojo_test_connector.cc
diff --git a/chrome/test/base/mojo_test_connector.cc b/chrome/test/base/mojo_test_connector.cc
index fcbb99885f8e4c2abb2d735ab700834d3a3d638c..da87cdad625609c595195d4abc41afde42f51389 100644
--- a/chrome/test/base/mojo_test_connector.cc
+++ b/chrome/test/base/mojo_test_connector.cc
@@ -67,15 +67,11 @@ class MojoTestState : public content::TestState {
#else
#error "Unsupported"
#endif
- service_manager::mojom::ServicePtr service =
- service_manager::PassServiceRequestOnCommandLine(&process_connection_,
- command_line);
- background_service_manager_->RegisterService(
- service_manager::Identity(content::mojom::kPackagedServicesServiceName,
- service_manager::mojom::kRootUserID),
- std::move(service),
- service_manager::mojom::PIDReceiverRequest(&pid_receiver_));
+ // Create the pipe token, as it must be passed to children processes via the
+ // command line.
+ service_ = service_manager::PassServiceRequestOnCommandLine(
+ &process_connection_, command_line);
// ChildProcessLaunched may be called on an arbitrary thread, so track the
// current TaskRunner and post back to it when we want to send the PID.
@@ -91,13 +87,22 @@ class MojoTestState : public content::TestState {
handle,
mojo::edk::ConnectionParams(platform_channel_->PassServerHandle()));
- main_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&MojoTestState::SetPID, weak_factory_.GetWeakPtr(), pid));
+ main_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&MojoTestState::SetupService,
+ weak_factory_.GetWeakPtr(), pid));
}
// Called on the main thread only.
- void SetPID(base::ProcessId pid) {
+ // This registers the services needed for the test. This is not done until
+ // after ChildProcessLaunched as previous test runs will tear down existing
+ // connections.
+ void SetupService(base::ProcessId pid) {
+ background_service_manager_->RegisterService(
+ service_manager::Identity(content::mojom::kPackagedServicesServiceName,
+ service_manager::mojom::kRootUserID),
+ std::move(service_),
+ service_manager::mojom::PIDReceiverRequest(&pid_receiver_));
+
DCHECK(pid_receiver_.is_bound());
pid_receiver_->SetPID(pid);
pid_receiver_.reset();
@@ -106,6 +111,11 @@ class MojoTestState : public content::TestState {
mojo::edk::PendingProcessConnection process_connection_;
service_manager::BackgroundServiceManager* const background_service_manager_;
+ // The ServicePtr must be created before child process launch so that the pipe
+ // can be set on the command line. It is held until SetupService is called at
+ // which point |background_service_manager_| takes over ownership.
+ service_manager::mojom::ServicePtr service_;
+
// NOTE: HandlePassingInformation must remain valid through process launch,
// hence it lives here instead of within Init()'s stack.
mojo::edk::HandlePassingInformation handle_passing_info_;
« no previous file with comments | « no previous file | testing/buildbot/filters/mash.browser_tests.filter » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698