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 "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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "services/service_manager/public/cpp/identity.h" | 28 #include "services/service_manager/public/cpp/identity.h" |
29 #include "services/service_manager/public/cpp/service.h" | 29 #include "services/service_manager/public/cpp/service.h" |
30 #include "services/service_manager/public/cpp/service_context.h" | 30 #include "services/service_manager/public/cpp/service_context.h" |
31 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 31 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
32 #include "services/service_manager/runner/common/switches.h" | 32 #include "services/service_manager/runner/common/switches.h" |
33 #include "services/service_manager/runner/host/child_process_base.h" | 33 #include "services/service_manager/runner/host/child_process_base.h" |
34 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
35 #include "ui/base/ui_base_paths.h" | 35 #include "ui/base/ui_base_paths.h" |
36 #include "ui/base/ui_base_switches.h" | 36 #include "ui/base/ui_base_switches.h" |
37 | 37 |
38 using shell::mojom::ServiceFactory; | 38 using service_manager::mojom::ServiceFactory; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // kProcessType used to identify child processes. | 42 // kProcessType used to identify child processes. |
43 const char* kMashChild = "mash-child"; | 43 const char* kMashChild = "mash-child"; |
44 | 44 |
45 const char kChromeMashServiceName[] = "service:chrome_mash"; | 45 const char kChromeMashServiceName[] = "service:chrome_mash"; |
46 | 46 |
47 const char kChromeMashContentBrowserPackageName[] = | 47 const char kChromeMashContentBrowserPackageName[] = |
48 "chrome_mash_content_browser"; | 48 "chrome_mash_content_browser"; |
(...skipping 20 matching lines...) Expand all Loading... |
69 void InitializeResources() { | 69 void InitializeResources() { |
70 ui::RegisterPathProvider(); | 70 ui::RegisterPathProvider(); |
71 const std::string locale = | 71 const std::string locale = |
72 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 72 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
73 switches::kLang); | 73 switches::kLang); |
74 // This loads the Chrome's resources (chrome_100_percent.pak etc.) | 74 // This loads the Chrome's resources (chrome_100_percent.pak etc.) |
75 ui::ResourceBundle::InitSharedInstanceWithLocale( | 75 ui::ResourceBundle::InitSharedInstanceWithLocale( |
76 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); | 76 locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); |
77 } | 77 } |
78 | 78 |
79 class NativeRunnerDelegateImpl : public shell::NativeRunnerDelegate { | 79 class NativeRunnerDelegateImpl : public service_manager::NativeRunnerDelegate { |
80 public: | 80 public: |
81 NativeRunnerDelegateImpl() {} | 81 NativeRunnerDelegateImpl() {} |
82 ~NativeRunnerDelegateImpl() override {} | 82 ~NativeRunnerDelegateImpl() override {} |
83 | 83 |
84 private: | 84 private: |
85 // shell::NativeRunnerDelegate: | 85 // service_manager::NativeRunnerDelegate: |
86 void AdjustCommandLineArgumentsForTarget( | 86 void AdjustCommandLineArgumentsForTarget( |
87 const shell::Identity& target, | 87 const service_manager::Identity& target, |
88 base::CommandLine* command_line) override { | 88 base::CommandLine* command_line) override { |
89 if (target.name() != content::kBrowserServiceName) { | 89 if (target.name() != content::kBrowserServiceName) { |
90 // If running anything other than the browser process, launch a mash | 90 // If running anything other than the browser process, launch a mash |
91 // child process. The new process will execute MashRunner::RunChild(). | 91 // child process. The new process will execute MashRunner::RunChild(). |
92 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); | 92 command_line->AppendSwitchASCII(switches::kProcessType, kMashChild); |
93 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
94 command_line->AppendArg(switches::kPrefetchArgumentOther); | 94 command_line->AppendArg(switches::kPrefetchArgumentOther); |
95 #endif | 95 #endif |
96 return; | 96 return; |
97 } | 97 } |
(...skipping 22 matching lines...) Expand all Loading... |
120 RunChild(); | 120 RunChild(); |
121 else | 121 else |
122 RunMain(); | 122 RunMain(); |
123 } | 123 } |
124 | 124 |
125 void MashRunner::RunMain() { | 125 void MashRunner::RunMain() { |
126 // TODO(sky): refactor backgroundshell so can supply own context, we | 126 // TODO(sky): refactor backgroundshell so can supply own context, we |
127 // shouldn't we using context as it has a lot of stuff we don't really want | 127 // shouldn't we using context as it has a lot of stuff we don't really want |
128 // in chrome. | 128 // in chrome. |
129 NativeRunnerDelegateImpl native_runner_delegate; | 129 NativeRunnerDelegateImpl native_runner_delegate; |
130 shell::BackgroundShell background_shell; | 130 service_manager::BackgroundShell background_service_manager; |
131 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( | 131 std::unique_ptr<service_manager::BackgroundShell::InitParams> init_params( |
132 new shell::BackgroundShell::InitParams); | 132 new service_manager::BackgroundShell::InitParams); |
133 init_params->native_runner_delegate = &native_runner_delegate; | 133 init_params->native_runner_delegate = &native_runner_delegate; |
134 background_shell.Init(std::move(init_params)); | 134 background_service_manager.Init(std::move(init_params)); |
135 service_.reset(new mash::MashPackagedService); | 135 service_.reset(new mash::MashPackagedService); |
136 service_->set_context(base::MakeUnique<shell::ServiceContext>( | 136 service_->set_context(base::MakeUnique<service_manager::ServiceContext>( |
137 service_.get(), | 137 service_.get(), |
138 background_shell.CreateServiceRequest(kChromeMashServiceName))); | 138 background_service_manager.CreateServiceRequest(kChromeMashServiceName))); |
139 | 139 |
140 // We need to send a sync messages to the Catalog, so we wait for a completed | 140 // We need to send a sync messages to the Catalog, so we wait for a completed |
141 // connection first. | 141 // connection first. |
142 std::unique_ptr<shell::Connection> catalog_connection = | 142 std::unique_ptr<service_manager::Connection> catalog_connection = |
143 service_->connector()->Connect("service:catalog"); | 143 service_->connector()->Connect("service:catalog"); |
144 { | 144 { |
145 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
146 catalog_connection->AddConnectionCompletedClosure(run_loop.QuitClosure()); | 146 catalog_connection->AddConnectionCompletedClosure(run_loop.QuitClosure()); |
147 run_loop.Run(); | 147 run_loop.Run(); |
148 } | 148 } |
149 | 149 |
150 // Synchronously override manifests needed for content process services. | 150 // Synchronously override manifests needed for content process services. |
151 catalog::mojom::CatalogControlPtr catalog_control; | 151 catalog::mojom::CatalogControlPtr catalog_control; |
152 catalog_connection->GetInterface(&catalog_control); | 152 catalog_connection->GetInterface(&catalog_control); |
(...skipping 11 matching lines...) Expand all Loading... |
164 GetPackageManifestPath(kChromeContentUtilityPackageName))); | 164 GetPackageManifestPath(kChromeContentUtilityPackageName))); |
165 | 165 |
166 // Ping mash_session to ensure an instance is brought up | 166 // Ping mash_session to ensure an instance is brought up |
167 service_->connector()->Connect("service:mash_session"); | 167 service_->connector()->Connect("service:mash_session"); |
168 base::RunLoop().Run(); | 168 base::RunLoop().Run(); |
169 } | 169 } |
170 | 170 |
171 void MashRunner::RunChild() { | 171 void MashRunner::RunChild() { |
172 base::i18n::InitializeICU(); | 172 base::i18n::InitializeICU(); |
173 InitializeResources(); | 173 InitializeResources(); |
174 shell::ChildProcessMainWithCallback( | 174 service_manager::ChildProcessMainWithCallback( |
175 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); | 175 base::Bind(&MashRunner::StartChildApp, base::Unretained(this))); |
176 } | 176 } |
177 | 177 |
178 void MashRunner::StartChildApp( | 178 void MashRunner::StartChildApp( |
179 shell::mojom::ServiceRequest service_request) { | 179 service_manager::mojom::ServiceRequest service_request) { |
180 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, | 180 // TODO(sad): Normally, this would be a TYPE_DEFAULT message loop. However, |
181 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is | 181 // TYPE_UI is needed for mojo:ui. But it is not known whether the child app is |
182 // going to be mojo:ui at this point. So always create a TYPE_UI message loop | 182 // going to be mojo:ui at this point. So always create a TYPE_UI message loop |
183 // for now. | 183 // for now. |
184 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 184 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
185 service_.reset(new mash::MashPackagedService); | 185 service_.reset(new mash::MashPackagedService); |
186 service_->set_context(base::MakeUnique<shell::ServiceContext>( | 186 service_->set_context(base::MakeUnique<service_manager::ServiceContext>( |
187 service_.get(), std::move(service_request))); | 187 service_.get(), std::move(service_request))); |
188 base::RunLoop().Run(); | 188 base::RunLoop().Run(); |
189 } | 189 } |
190 | 190 |
191 int MashMain() { | 191 int MashMain() { |
192 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
193 base::RouteStdioToConsole(false); | 193 base::RouteStdioToConsole(false); |
194 #endif | 194 #endif |
195 // TODO(sky): wire this up correctly. | 195 // TODO(sky): wire this up correctly. |
196 logging::LoggingSettings settings; | 196 logging::LoggingSettings settings; |
(...skipping 18 matching lines...) Expand all Loading... |
215 tracing::GetConfigForTraceToConsole(); | 215 tracing::GetConfigForTraceToConsole(); |
216 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 216 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
217 trace_config, | 217 trace_config, |
218 base::trace_event::TraceLog::RECORDING_MODE); | 218 base::trace_event::TraceLog::RECORDING_MODE); |
219 } | 219 } |
220 | 220 |
221 MashRunner mash_runner; | 221 MashRunner mash_runner; |
222 mash_runner.Run(); | 222 mash_runner.Run(); |
223 return 0; | 223 return 0; |
224 } | 224 } |
OLD | NEW |