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

Side by Side Diff: chrome/test/base/mojo_test_connector.cc

Issue 2695803004: Make browser process a singleton service (Closed)
Patch Set: . Created 3 years, 10 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 | « chrome/test/BUILD.gn ('k') | content/BUILD.gn » ('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 "chrome/test/base/mojo_test_connector.h" 5 #include "chrome/test/base/mojo_test_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "content/public/common/service_names.mojom.h"
18 #include "content/public/test/test_launcher.h" 19 #include "content/public/test/test_launcher.h"
19 #include "mojo/edk/embedder/embedder.h" 20 #include "mojo/edk/embedder/embedder.h"
20 #include "mojo/edk/embedder/pending_process_connection.h" 21 #include "mojo/edk/embedder/pending_process_connection.h"
21 #include "mojo/edk/embedder/platform_channel_pair.h" 22 #include "mojo/edk/embedder/platform_channel_pair.h"
22 #include "mojo/edk/embedder/scoped_ipc_support.h" 23 #include "mojo/edk/embedder/scoped_ipc_support.h"
23 #include "mojo/public/cpp/bindings/interface_request.h" 24 #include "mojo/public/cpp/bindings/interface_request.h"
24 #include "services/catalog/store.h" 25 #include "services/catalog/store.h"
25 #include "services/service_manager/background/background_service_manager.h" 26 #include "services/service_manager/background/background_service_manager.h"
26 #include "services/service_manager/public/cpp/connector.h" 27 #include "services/service_manager/public/cpp/connector.h"
27 #include "services/service_manager/public/cpp/service.h" 28 #include "services/service_manager/public/cpp/service.h"
28 #include "services/service_manager/public/cpp/service_context.h" 29 #include "services/service_manager/public/cpp/service_context.h"
29 #include "services/service_manager/runner/common/client_util.h" 30 #include "services/service_manager/runner/common/client_util.h"
30 #include "services/service_manager/runner/common/switches.h" 31 #include "services/service_manager/runner/common/switches.h"
31 #include "services/service_manager/runner/host/service_process_launcher.h" 32 #include "services/service_manager/runner/host/service_process_launcher.h"
32 #include "services/service_manager/service_manager.h" 33 #include "services/service_manager/service_manager.h"
33 #include "services/service_manager/switches.h" 34 #include "services/service_manager/switches.h"
34 35
35 namespace { 36 namespace {
36 37
37 const char kTestRunnerName[] = "mash_browser_tests"; 38 const char kTestRunnerName[] = "mash_browser_tests";
38 const char kTestName[] = "content_browser";
39 39
40 // State created per test to register a client process with the background 40 // State created per test to register a client process with the background
41 // service manager. 41 // service manager.
42 class MojoTestState : public content::TestState { 42 class MojoTestState : public content::TestState {
43 public: 43 public:
44 explicit MojoTestState( 44 explicit MojoTestState(
45 service_manager::BackgroundServiceManager* background_service_manager) 45 service_manager::BackgroundServiceManager* background_service_manager)
46 : background_service_manager_(background_service_manager), 46 : background_service_manager_(background_service_manager),
47 weak_factory_(this) {} 47 weak_factory_(this) {}
48 ~MojoTestState() override {} 48 ~MojoTestState() override {}
(...skipping 16 matching lines...) Expand all
65 #elif defined(OS_POSIX) 65 #elif defined(OS_POSIX)
66 test_launch_options->fds_to_remap = &handle_passing_info_; 66 test_launch_options->fds_to_remap = &handle_passing_info_;
67 #else 67 #else
68 #error "Unsupported" 68 #error "Unsupported"
69 #endif 69 #endif
70 service_manager::mojom::ServicePtr service = 70 service_manager::mojom::ServicePtr service =
71 service_manager::PassServiceRequestOnCommandLine(&process_connection_, 71 service_manager::PassServiceRequestOnCommandLine(&process_connection_,
72 command_line); 72 command_line);
73 73
74 background_service_manager_->RegisterService( 74 background_service_manager_->RegisterService(
75 service_manager::Identity( 75 service_manager::Identity(content::mojom::kPackagedServicesServiceName,
76 kTestName, service_manager::mojom::kRootUserID), 76 service_manager::mojom::kRootUserID),
77 std::move(service), 77 std::move(service),
78 service_manager::mojom::PIDReceiverRequest(&pid_receiver_)); 78 service_manager::mojom::PIDReceiverRequest(&pid_receiver_));
79 79
80 // ChildProcessLaunched may be called on an arbitrary thread, so track the 80 // ChildProcessLaunched may be called on an arbitrary thread, so track the
81 // current TaskRunner and post back to it when we want to send the PID. 81 // current TaskRunner and post back to it when we want to send the PID.
82 main_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 82 main_task_runner_ = base::ThreadTaskRunnerHandle::Get();
83 } 83 }
84 84
85 private: 85 private:
86 // content::TestState: 86 // content::TestState:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 : public service_manager::ServiceProcessLauncher::Delegate { 137 : public service_manager::ServiceProcessLauncher::Delegate {
138 public: 138 public:
139 ServiceProcessLauncherDelegateImpl() {} 139 ServiceProcessLauncherDelegateImpl() {}
140 ~ServiceProcessLauncherDelegateImpl() override {} 140 ~ServiceProcessLauncherDelegateImpl() override {}
141 141
142 private: 142 private:
143 // service_manager::ServiceProcessLauncherDelegate: 143 // service_manager::ServiceProcessLauncherDelegate:
144 void AdjustCommandLineArgumentsForTarget( 144 void AdjustCommandLineArgumentsForTarget(
145 const service_manager::Identity& target, 145 const service_manager::Identity& target,
146 base::CommandLine* command_line) override { 146 base::CommandLine* command_line) override {
147 if (target.name() != kTestName) { 147 if (target.name() != content::mojom::kPackagedServicesServiceName) {
148 if (target.name() == kTestRunnerName) { 148 if (target.name() == kTestRunnerName) {
149 RemoveMashFromBrowserTests(command_line); 149 RemoveMashFromBrowserTests(command_line);
150 command_line->SetProgram( 150 command_line->SetProgram(
151 base::CommandLine::ForCurrentProcess()->GetProgram()); 151 base::CommandLine::ForCurrentProcess()->GetProgram());
152 } 152 }
153 command_line->AppendSwitch(MojoTestConnector::kMashApp); 153 command_line->AppendSwitch(MojoTestConnector::kMashApp);
154 return; 154 return;
155 } 155 }
156 156
157 base::CommandLine::StringVector argv(command_line->argv()); 157 base::CommandLine::StringVector argv(command_line->argv());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 MojoTestConnector::~MojoTestConnector() {} 203 MojoTestConnector::~MojoTestConnector() {}
204 204
205 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( 205 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest(
206 base::CommandLine* command_line, 206 base::CommandLine* command_line,
207 base::TestLauncher::LaunchOptions* test_launch_options) { 207 base::TestLauncher::LaunchOptions* test_launch_options) {
208 auto test_state = 208 auto test_state =
209 base::MakeUnique<MojoTestState>(&background_service_manager_); 209 base::MakeUnique<MojoTestState>(&background_service_manager_);
210 test_state->Init(command_line, test_launch_options); 210 test_state->Init(command_line, test_launch_options);
211 return test_state; 211 return test_state;
212 } 212 }
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | content/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698