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

Side by Side Diff: chrome/app/mash/mash_runner.cc

Issue 2576233002: Consolidating the mojo NativeRunner functionality. (Closed)
Patch Set: Merged mojo_runner_host_unittests in service_manager_unittests Created 4 years 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 | « no previous file | chrome/test/base/mojo_test_connector.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 "chrome/app/mash/mash_runner.h" 5 #include "chrome/app/mash/mash_runner.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 14 matching lines...) Expand all
25 #include "components/tracing/common/trace_to_console.h" 25 #include "components/tracing/common/trace_to_console.h"
26 #include "components/tracing/common/tracing_switches.h" 26 #include "components/tracing/common/tracing_switches.h"
27 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
28 #include "content/public/common/service_names.mojom.h" 28 #include "content/public/common/service_names.mojom.h"
29 #include "mash/package/mash_packaged_service.h" 29 #include "mash/package/mash_packaged_service.h"
30 #include "mash/session/public/interfaces/constants.mojom.h" 30 #include "mash/session/public/interfaces/constants.mojom.h"
31 #include "mojo/public/cpp/bindings/binding_set.h" 31 #include "mojo/public/cpp/bindings/binding_set.h"
32 #include "services/catalog/public/interfaces/catalog.mojom.h" 32 #include "services/catalog/public/interfaces/catalog.mojom.h"
33 #include "services/catalog/public/interfaces/constants.mojom.h" 33 #include "services/catalog/public/interfaces/constants.mojom.h"
34 #include "services/service_manager/background/background_service_manager.h" 34 #include "services/service_manager/background/background_service_manager.h"
35 #include "services/service_manager/native_runner_delegate.h"
36 #include "services/service_manager/public/cpp/connector.h" 35 #include "services/service_manager/public/cpp/connector.h"
37 #include "services/service_manager/public/cpp/identity.h" 36 #include "services/service_manager/public/cpp/identity.h"
38 #include "services/service_manager/public/cpp/service.h" 37 #include "services/service_manager/public/cpp/service.h"
39 #include "services/service_manager/public/cpp/service_context.h" 38 #include "services/service_manager/public/cpp/service_context.h"
40 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h" 39 #include "services/service_manager/public/cpp/standalone_service/standalone_serv ice.h"
41 #include "services/service_manager/public/interfaces/service_factory.mojom.h" 40 #include "services/service_manager/public/interfaces/service_factory.mojom.h"
42 #include "services/service_manager/runner/common/client_util.h" 41 #include "services/service_manager/runner/common/client_util.h"
43 #include "services/service_manager/runner/common/switches.h" 42 #include "services/service_manager/runner/common/switches.h"
44 #include "services/service_manager/runner/init.h" 43 #include "services/service_manager/runner/init.h"
45 #include "services/service_manager/standalone/context.h" 44 #include "services/service_manager/standalone/context.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 void InitializeResources() { 79 void InitializeResources() {
81 ui::RegisterPathProvider(); 80 ui::RegisterPathProvider();
82 const std::string locale = 81 const std::string locale =
83 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 82 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
84 switches::kLang); 83 switches::kLang);
85 // This loads the Chrome's resources (chrome_100_percent.pak etc.) 84 // This loads the Chrome's resources (chrome_100_percent.pak etc.)
86 ui::ResourceBundle::InitSharedInstanceWithLocale( 85 ui::ResourceBundle::InitSharedInstanceWithLocale(
87 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); 86 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
88 } 87 }
89 88
90 class NativeRunnerDelegateImpl : public service_manager::NativeRunnerDelegate { 89 class ServiceProcessLauncherDelegateImpl
90 : public service_manager::ServiceProcessLauncher::Delegate {
91 public: 91 public:
92 NativeRunnerDelegateImpl() {} 92 ServiceProcessLauncherDelegateImpl() {}
93 ~NativeRunnerDelegateImpl() override {} 93 ~ServiceProcessLauncherDelegateImpl() override {}
94 94
95 private: 95 private:
96 // service_manager::NativeRunnerDelegate: 96 // service_manager::ServiceProcessLauncher::Delegate:
97 void AdjustCommandLineArgumentsForTarget( 97 void AdjustCommandLineArgumentsForTarget(
98 const service_manager::Identity& target, 98 const service_manager::Identity& target,
99 base::CommandLine* command_line) override { 99 base::CommandLine* command_line) override {
100 if (target.name() == kChromeMashServiceName || 100 if (target.name() == kChromeMashServiceName ||
101 target.name() == content::mojom::kBrowserServiceName) { 101 target.name() == content::mojom::kBrowserServiceName) {
102 base::FilePath exe_path; 102 base::FilePath exe_path;
103 base::PathService::Get(base::FILE_EXE, &exe_path); 103 base::PathService::Get(base::FILE_EXE, &exe_path);
104 command_line->SetProgram(exe_path); 104 command_line->SetProgram(exe_path);
105 } 105 }
106 if (target.name() != content::mojom::kBrowserServiceName) { 106 if (target.name() != content::mojom::kBrowserServiceName) {
107 // If running anything other than the browser process, launch a mash 107 // If running anything other than the browser process, launch a mash
108 // child process. The new process will execute MashRunner::RunChild(). 108 // child process. The new process will execute MashRunner::RunChild().
109 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); 109 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild);
110 #if defined(OS_WIN) 110 #if defined(OS_WIN)
111 command_line->AppendArg(switches::kPrefetchArgumentOther); 111 command_line->AppendArg(switches::kPrefetchArgumentOther);
112 #endif 112 #endif
113 return; 113 return;
114 } 114 }
115 115
116 // When launching the browser process, ensure that we don't inherit the 116 // When launching the browser process, ensure that we don't inherit the
117 // --mash flag so it proceeds with the normal content/browser startup path. 117 // --mash flag so it proceeds with the normal content/browser startup path.
118 // Eliminate all copies in case the developer passed more than one. 118 // Eliminate all copies in case the developer passed more than one.
119 base::CommandLine::StringVector new_argv; 119 base::CommandLine::StringVector new_argv;
120 for (const base::CommandLine::StringType& arg : command_line->argv()) { 120 for (const base::CommandLine::StringType& arg : command_line->argv()) {
121 if (arg != FILE_PATH_LITERAL("--mash")) 121 if (arg != FILE_PATH_LITERAL("--mash"))
122 new_argv.push_back(arg); 122 new_argv.push_back(arg);
123 } 123 }
124 *command_line = base::CommandLine(new_argv); 124 *command_line = base::CommandLine(new_argv);
125 } 125 }
126 126
127 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); 127 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl);
128 }; 128 };
129 129
130 } // namespace 130 } // namespace
131 131
132 MashRunner::MashRunner() {} 132 MashRunner::MashRunner() {}
133 133
134 MashRunner::~MashRunner() {} 134 MashRunner::~MashRunner() {}
135 135
136 int MashRunner::Run() { 136 int MashRunner::Run() {
137 if (IsChild()) 137 if (IsChild())
138 return RunChild(); 138 return RunChild();
139 RunMain(); 139 RunMain();
140 return 0; 140 return 0;
141 } 141 }
142 142
143 void MashRunner::RunMain() { 143 void MashRunner::RunMain() {
144 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( 144 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(
145 service_manager::kThreadPoolMaxThreads); 145 service_manager::kThreadPoolMaxThreads);
146 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); 146 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
147 147
148 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we 148 // TODO(sky): refactor BackgroundServiceManager so can supply own context, we
149 // shouldn't we using context as it has a lot of stuff we don't really want 149 // shouldn't we using context as it has a lot of stuff we don't really want
150 // in chrome. 150 // in chrome.
151 NativeRunnerDelegateImpl native_runner_delegate; 151 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate;
152 service_manager::BackgroundServiceManager background_service_manager; 152 service_manager::BackgroundServiceManager background_service_manager;
153 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams> 153 std::unique_ptr<service_manager::BackgroundServiceManager::InitParams>
154 init_params(new service_manager::BackgroundServiceManager::InitParams); 154 init_params(new service_manager::BackgroundServiceManager::InitParams);
155 init_params->native_runner_delegate = &native_runner_delegate; 155 init_params->service_process_launcher_delegate =
156 &service_process_launcher_delegate;
156 background_service_manager.Init(std::move(init_params)); 157 background_service_manager.Init(std::move(init_params));
157 context_.reset(new service_manager::ServiceContext( 158 context_.reset(new service_manager::ServiceContext(
158 base::MakeUnique<mash::MashPackagedService>(), 159 base::MakeUnique<mash::MashPackagedService>(),
159 background_service_manager.CreateServiceRequest(kChromeMashServiceName))); 160 background_service_manager.CreateServiceRequest(kChromeMashServiceName)));
160 161
161 // We need to send a sync messages to the Catalog, so we wait for a completed 162 // We need to send a sync messages to the Catalog, so we wait for a completed
162 // connection first. 163 // connection first.
163 std::unique_ptr<service_manager::Connection> catalog_connection = 164 std::unique_ptr<service_manager::Connection> catalog_connection =
164 context_->connector()->Connect(catalog::mojom::kServiceName); 165 context_->connector()->Connect(catalog::mojom::kServiceName);
165 { 166 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) { 259 command_line->GetSwitchValueASCII(switches::kWaitForDebugger)) {
259 return; 260 return;
260 } 261 }
261 262
262 // Include the pid as logging may not have been initialized yet (the pid 263 // Include the pid as logging may not have been initialized yet (the pid
263 // printed out by logging is wrong). 264 // printed out by logging is wrong).
264 LOG(WARNING) << "waiting for debugger to attach for service " << service_name 265 LOG(WARNING) << "waiting for debugger to attach for service " << service_name
265 << " pid=" << base::Process::Current().Pid(); 266 << " pid=" << base::Process::Current().Pid();
266 base::debug::WaitForDebugger(120, true); 267 base::debug::WaitForDebugger(120, true);
267 } 268 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/base/mojo_test_connector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698