Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/mojo/mojo_shell_context.h" | 5 #include "content/browser/mojo/mojo_shell_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "components/profile_service/profile_app.h" | 16 #include "components/profile_service/profile_app.h" |
| 17 #include "content/browser/gpu/gpu_process_host.h" | 17 #include "content/browser/gpu/gpu_process_host.h" |
| 18 #include "content/common/gpu_process_launch_causes.h" | 18 #include "content/common/gpu_process_launch_causes.h" |
| 19 #include "content/common/mojo/current_thread_loader.h" | 19 #include "content/common/mojo/current_thread_loader.h" |
| 20 #include "content/common/mojo/mojo_shell_connection_impl.h" | 20 #include "content/common/mojo/mojo_shell_connection_impl.h" |
| 21 #include "content/common/mojo/static_loader.h" | 21 #include "content/common/mojo/static_loader.h" |
| 22 #include "content/common/process_control.mojom.h" | 22 #include "content/common/process_control.mojom.h" |
| 23 #include "content/grit/content_resources.h" | |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/content_browser_client.h" | 25 #include "content/public/browser/content_browser_client.h" |
| 25 #include "content/public/browser/utility_process_host.h" | 26 #include "content/public/browser/utility_process_host.h" |
| 26 #include "content/public/browser/utility_process_host_client.h" | 27 #include "content/public/browser/utility_process_host_client.h" |
| 27 #include "content/public/common/content_client.h" | 28 #include "content/public/common/content_client.h" |
| 28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/common/service_registry.h" | 30 #include "content/public/common/service_registry.h" |
| 30 #include "mojo/public/cpp/bindings/interface_request.h" | 31 #include "mojo/public/cpp/bindings/interface_request.h" |
| 31 #include "mojo/public/cpp/bindings/string.h" | 32 #include "mojo/public/cpp/bindings/string.h" |
| 32 #include "mojo/services/catalog/factory.h" | 33 #include "mojo/services/catalog/factory.h" |
| 34 #include "mojo/services/catalog/manifest_provider.h" | |
| 33 #include "mojo/services/catalog/store.h" | 35 #include "mojo/services/catalog/store.h" |
| 34 #include "mojo/shell/connect_params.h" | 36 #include "mojo/shell/connect_params.h" |
| 35 #include "mojo/shell/loader.h" | 37 #include "mojo/shell/loader.h" |
| 36 #include "mojo/shell/native_runner.h" | 38 #include "mojo/shell/native_runner.h" |
| 37 #include "mojo/shell/public/cpp/identity.h" | 39 #include "mojo/shell/public/cpp/identity.h" |
| 38 #include "mojo/shell/public/cpp/shell_client.h" | 40 #include "mojo/shell/public/cpp/shell_client.h" |
| 39 #include "mojo/shell/public/interfaces/connector.mojom.h" | 41 #include "mojo/shell/public/interfaces/connector.mojom.h" |
| 40 #include "mojo/shell/runner/host/in_process_native_runner.h" | 42 #include "mojo/shell/runner/host/in_process_native_runner.h" |
| 41 | 43 |
| 42 namespace content { | 44 namespace content { |
| 43 | 45 |
| 44 namespace { | 46 namespace { |
| 45 | 47 |
| 46 const char kBrowserAppName[] = "exe:chrome"; | |
| 47 | |
| 48 // An extra set of apps to register on initialization, if set by a test. | 48 // An extra set of apps to register on initialization, if set by a test. |
| 49 const MojoShellContext::StaticApplicationMap* g_applications_for_test; | 49 const MojoShellContext::StaticApplicationMap* g_applications_for_test; |
| 50 | 50 |
| 51 void StartUtilityProcessOnIOThread( | 51 void StartUtilityProcessOnIOThread( |
| 52 mojo::InterfaceRequest<mojom::ProcessControl> request, | 52 mojo::InterfaceRequest<mojom::ProcessControl> request, |
| 53 const base::string16& process_name, | 53 const base::string16& process_name, |
| 54 bool use_sandbox) { | 54 bool use_sandbox) { |
| 55 UtilityProcessHost* process_host = | 55 UtilityProcessHost* process_host = |
| 56 UtilityProcessHost::Create(nullptr, nullptr); | 56 UtilityProcessHost::Create(nullptr, nullptr); |
| 57 process_host->SetName(process_name); | 57 process_host->SetName(process_name); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 BrowserThread::PostTask( | 148 BrowserThread::PostTask( |
| 149 BrowserThread::IO, FROM_HERE, | 149 BrowserThread::IO, FROM_HERE, |
| 150 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); | 150 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
| 151 process_control->LoadApplication(name, std::move(request), | 151 process_control->LoadApplication(name, std::move(request), |
| 152 base::Bind(&OnApplicationLoaded, name)); | 152 base::Bind(&OnApplicationLoaded, name)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); | 155 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 std::string GetStringResource(int id) { | |
| 159 return GetContentClient()->GetDataResourceBytes(id)->front_as<char>(); | |
| 160 } | |
| 161 | |
| 158 } // namespace | 162 } // namespace |
| 159 | 163 |
| 164 // A ManifestProvider which resolves application names to builtin manifest | |
| 165 // resources for the catalog service to consume. | |
| 166 class MojoShellContext::BuiltinManifestProvider | |
| 167 : public catalog::ManifestProvider { | |
| 168 public: | |
| 169 BuiltinManifestProvider() {} | |
| 170 ~BuiltinManifestProvider() override {} | |
| 171 | |
| 172 private: | |
| 173 // catalog::ManifestProvider: | |
| 174 bool GetApplicationManifest(const base::StringPiece& name, | |
| 175 std::string* manifest_contents) override { | |
| 176 if (name == "mojo:catalog") { | |
| 177 *manifest_contents = GetStringResource(IDR_MOJO_CATALOG_MANIFEST); | |
| 178 return true; | |
| 179 } else if (name == "exe:content_browser") { | |
|
Ben Goodger (Google)
2016/03/30 22:27:50
this isn't affected if the embedder provides a dif
Ken Rockot(use gerrit already)
2016/03/31 18:55:48
If the embedder provides a different app name, the
| |
| 180 *manifest_contents = GetStringResource(IDR_MOJO_CONTENT_BROWSER_MANIFEST); | |
| 181 return true; | |
| 182 } else if (name == "exe:content_renderer") { | |
| 183 *manifest_contents = | |
| 184 GetStringResource(IDR_MOJO_CONTENT_RENDERER_MANIFEST); | |
| 185 return true; | |
| 186 } | |
| 187 | |
| 188 return GetContentClient()->browser()->GetMojoApplicationManifest( | |
| 189 name, manifest_contents); | |
| 190 } | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); | |
| 193 }; | |
| 194 | |
| 160 // Thread-safe proxy providing access to the shell context from any thread. | 195 // Thread-safe proxy providing access to the shell context from any thread. |
| 161 class MojoShellContext::Proxy { | 196 class MojoShellContext::Proxy { |
| 162 public: | 197 public: |
| 163 Proxy(MojoShellContext* shell_context) | 198 Proxy(MojoShellContext* shell_context) |
| 164 : shell_context_(shell_context), | 199 : shell_context_(shell_context), |
| 165 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 200 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 166 | 201 |
| 167 ~Proxy() {} | 202 ~Proxy() {} |
| 168 | 203 |
| 169 void ConnectToApplication( | 204 void ConnectToApplication( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 MojoShellContext::MojoShellContext( | 245 MojoShellContext::MojoShellContext( |
| 211 scoped_refptr<base::SingleThreadTaskRunner> file_thread, | 246 scoped_refptr<base::SingleThreadTaskRunner> file_thread, |
| 212 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { | 247 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { |
| 213 proxy_.Get().reset(new Proxy(this)); | 248 proxy_.Get().reset(new Proxy(this)); |
| 214 | 249 |
| 215 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = | 250 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = |
| 216 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 251 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
| 217 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( | 252 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( |
| 218 new mojo::shell::InProcessNativeRunnerFactory( | 253 new mojo::shell::InProcessNativeRunnerFactory( |
| 219 BrowserThread::GetBlockingPool())); | 254 BrowserThread::GetBlockingPool())); |
| 220 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr)); | 255 manifest_provider_.reset(new BuiltinManifestProvider); |
| 256 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr, | |
| 257 manifest_provider_.get())); | |
| 221 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), | 258 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), |
| 222 catalog_->TakeShellClient())); | 259 catalog_->TakeShellClient())); |
| 223 | 260 |
| 224 shell_->set_default_loader( | 261 shell_->set_default_loader( |
| 225 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); | 262 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); |
| 226 | 263 |
| 227 StaticApplicationMap apps; | 264 StaticApplicationMap apps; |
| 228 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 265 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
| 229 if (g_applications_for_test) { | 266 if (g_applications_for_test) { |
| 230 // Add testing apps to the map, potentially overwriting whatever the | 267 // Add testing apps to the map, potentially overwriting whatever the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 switches::kMojoLocalStorage)) { | 304 switches::kMojoLocalStorage)) { |
| 268 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = | 305 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = |
| 269 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); | 306 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); |
| 270 shell_->SetLoaderForName( | 307 shell_->SetLoaderForName( |
| 271 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), | 308 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), |
| 272 "mojo:profile"); | 309 "mojo:profile"); |
| 273 } | 310 } |
| 274 | 311 |
| 275 if (!IsRunningInMojoShell()) { | 312 if (!IsRunningInMojoShell()) { |
| 276 const bool is_external = false; | 313 const bool is_external = false; |
| 277 MojoShellConnection::Create( | 314 std::string app_name = |
| 278 shell_->InitInstanceForEmbedder(kBrowserAppName), is_external); | 315 GetContentClient()->browser()->GetPackagedMojoApplicationName(); |
| 316 if (!app_name.empty()) { | |
| 317 MojoShellConnection::Create( | |
| 318 shell_->InitInstanceForEmbedder(app_name), is_external); | |
| 319 } | |
| 279 } | 320 } |
| 280 } | 321 } |
| 281 | 322 |
| 282 MojoShellContext::~MojoShellContext() { | 323 MojoShellContext::~MojoShellContext() { |
| 283 if (!IsRunningInMojoShell()) | 324 if (!IsRunningInMojoShell()) |
| 284 MojoShellConnectionImpl::Destroy(); | 325 MojoShellConnectionImpl::Destroy(); |
| 285 } | 326 } |
| 286 | 327 |
| 287 // static | 328 // static |
| 288 void MojoShellContext::ConnectToApplication( | 329 void MojoShellContext::ConnectToApplication( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 308 mojo::Identity source_id(requestor_name, user_id); | 349 mojo::Identity source_id(requestor_name, user_id); |
| 309 params->set_source(source_id); | 350 params->set_source(source_id); |
| 310 params->set_target(mojo::Identity(name, user_id)); | 351 params->set_target(mojo::Identity(name, user_id)); |
| 311 params->set_remote_interfaces(std::move(request)); | 352 params->set_remote_interfaces(std::move(request)); |
| 312 params->set_local_interfaces(std::move(exposed_services)); | 353 params->set_local_interfaces(std::move(exposed_services)); |
| 313 params->set_connect_callback(callback); | 354 params->set_connect_callback(callback); |
| 314 shell_->Connect(std::move(params)); | 355 shell_->Connect(std::move(params)); |
| 315 } | 356 } |
| 316 | 357 |
| 317 } // namespace content | 358 } // namespace content |
| OLD | NEW |