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" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "mojo/shell/native_runner.h" | 36 #include "mojo/shell/native_runner.h" |
37 #include "mojo/shell/public/cpp/identity.h" | 37 #include "mojo/shell/public/cpp/identity.h" |
38 #include "mojo/shell/public/cpp/shell_client.h" | 38 #include "mojo/shell/public/cpp/shell_client.h" |
39 #include "mojo/shell/public/interfaces/connector.mojom.h" | 39 #include "mojo/shell/public/interfaces/connector.mojom.h" |
40 #include "mojo/shell/runner/host/in_process_native_runner.h" | 40 #include "mojo/shell/runner/host/in_process_native_runner.h" |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
45 | 45 |
46 const char kBrowserAppName[] = "exe:chrome"; | |
47 | |
48 // An extra set of apps to register on initialization, if set by a test. | 46 // An extra set of apps to register on initialization, if set by a test. |
49 const MojoShellContext::StaticApplicationMap* g_applications_for_test; | 47 const MojoShellContext::StaticApplicationMap* g_applications_for_test; |
50 | 48 |
51 void StartUtilityProcessOnIOThread( | 49 void StartUtilityProcessOnIOThread( |
52 mojo::InterfaceRequest<mojom::ProcessControl> request, | 50 mojo::InterfaceRequest<mojom::ProcessControl> request, |
53 const base::string16& process_name, | 51 const base::string16& process_name, |
54 bool use_sandbox) { | 52 bool use_sandbox) { |
55 UtilityProcessHost* process_host = | 53 UtilityProcessHost* process_host = |
56 UtilityProcessHost::Create(nullptr, nullptr); | 54 UtilityProcessHost::Create(nullptr, nullptr); |
57 process_host->SetName(process_name); | 55 process_host->SetName(process_name); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); | 148 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); |
151 process_control->LoadApplication(name, std::move(request), | 149 process_control->LoadApplication(name, std::move(request), |
152 base::Bind(&OnApplicationLoaded, name)); | 150 base::Bind(&OnApplicationLoaded, name)); |
153 } | 151 } |
154 | 152 |
155 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); | 153 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); |
156 }; | 154 }; |
157 | 155 |
158 } // namespace | 156 } // namespace |
159 | 157 |
| 158 // A Catalog::Delegate which resolves application names to builtin manifest |
| 159 // resources for the catalog service to consume. |
| 160 class MojoShellContext::ManifestResolver : public catalog::Catalog::Delegate { |
| 161 public: |
| 162 ManifestResolver() {} |
| 163 ~ManifestResolver() override {} |
| 164 |
| 165 private: |
| 166 // catalog::Catalog::Delegate: |
| 167 bool GetApplicationManifest(const base::StringPiece& name, |
| 168 std::string* manifest_contents) override { |
| 169 return GetContentClient()->browser()->GetMojoApplicationManifest( |
| 170 name, manifest_contents); |
| 171 } |
| 172 |
| 173 DISALLOW_COPY_AND_ASSIGN(ManifestResolver); |
| 174 }; |
| 175 |
160 // Thread-safe proxy providing access to the shell context from any thread. | 176 // Thread-safe proxy providing access to the shell context from any thread. |
161 class MojoShellContext::Proxy { | 177 class MojoShellContext::Proxy { |
162 public: | 178 public: |
163 Proxy(MojoShellContext* shell_context) | 179 Proxy(MojoShellContext* shell_context) |
164 : shell_context_(shell_context), | 180 : shell_context_(shell_context), |
165 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 181 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
166 | 182 |
167 ~Proxy() {} | 183 ~Proxy() {} |
168 | 184 |
169 void ConnectToApplication( | 185 void ConnectToApplication( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 MojoShellContext::MojoShellContext( | 226 MojoShellContext::MojoShellContext( |
211 scoped_refptr<base::SingleThreadTaskRunner> file_thread, | 227 scoped_refptr<base::SingleThreadTaskRunner> file_thread, |
212 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { | 228 scoped_refptr<base::SingleThreadTaskRunner> db_thread) { |
213 proxy_.Get().reset(new Proxy(this)); | 229 proxy_.Get().reset(new Proxy(this)); |
214 | 230 |
215 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = | 231 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = |
216 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); | 232 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); |
217 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( | 233 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( |
218 new mojo::shell::InProcessNativeRunnerFactory( | 234 new mojo::shell::InProcessNativeRunnerFactory( |
219 BrowserThread::GetBlockingPool())); | 235 BrowserThread::GetBlockingPool())); |
220 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr)); | 236 builtin_resolver_.reset(new ManifestResolver); |
| 237 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr, |
| 238 builtin_resolver_.get())); |
221 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), | 239 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), |
222 catalog_->TakeShellClient())); | 240 catalog_->TakeShellClient())); |
223 | 241 |
224 shell_->set_default_loader( | 242 shell_->set_default_loader( |
225 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); | 243 scoped_ptr<mojo::shell::Loader>(new DefaultLoader)); |
226 | 244 |
227 StaticApplicationMap apps; | 245 StaticApplicationMap apps; |
228 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 246 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); |
229 if (g_applications_for_test) { | 247 if (g_applications_for_test) { |
230 // Add testing apps to the map, potentially overwriting whatever the | 248 // 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)) { | 285 switches::kMojoLocalStorage)) { |
268 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = | 286 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = |
269 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); | 287 base::Bind(&profile::CreateProfileApp, file_thread, db_thread); |
270 shell_->SetLoaderForName( | 288 shell_->SetLoaderForName( |
271 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), | 289 make_scoped_ptr(new CurrentThreadLoader(profile_callback)), |
272 "mojo:profile"); | 290 "mojo:profile"); |
273 } | 291 } |
274 | 292 |
275 if (!IsRunningInMojoShell()) { | 293 if (!IsRunningInMojoShell()) { |
276 const bool is_external = false; | 294 const bool is_external = false; |
277 MojoShellConnection::Create( | 295 std::string app_name = |
278 shell_->InitInstanceForEmbedder(kBrowserAppName), is_external); | 296 GetContentClient()->browser()->GetPackagedMojoApplicationName(); |
| 297 if (!app_name.empty()) { |
| 298 MojoShellConnection::Create( |
| 299 shell_->InitInstanceForEmbedder(app_name), is_external); |
| 300 } |
279 } | 301 } |
280 } | 302 } |
281 | 303 |
282 MojoShellContext::~MojoShellContext() { | 304 MojoShellContext::~MojoShellContext() { |
283 if (!IsRunningInMojoShell()) | 305 if (!IsRunningInMojoShell()) |
284 MojoShellConnectionImpl::Destroy(); | 306 MojoShellConnectionImpl::Destroy(); |
285 } | 307 } |
286 | 308 |
287 // static | 309 // static |
288 void MojoShellContext::ConnectToApplication( | 310 void MojoShellContext::ConnectToApplication( |
(...skipping 19 matching lines...) Expand all Loading... |
308 mojo::Identity source_id(requestor_name, user_id); | 330 mojo::Identity source_id(requestor_name, user_id); |
309 params->set_source(source_id); | 331 params->set_source(source_id); |
310 params->set_target(mojo::Identity(name, user_id)); | 332 params->set_target(mojo::Identity(name, user_id)); |
311 params->set_remote_interfaces(std::move(request)); | 333 params->set_remote_interfaces(std::move(request)); |
312 params->set_local_interfaces(std::move(exposed_services)); | 334 params->set_local_interfaces(std::move(exposed_services)); |
313 params->set_connect_callback(callback); | 335 params->set_connect_callback(callback); |
314 shell_->Connect(std::move(params)); | 336 shell_->Connect(std::move(params)); |
315 } | 337 } |
316 | 338 |
317 } // namespace content | 339 } // namespace content |
OLD | NEW |