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

Side by Side Diff: content/browser/mojo/mojo_shell_context.cc

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 | « content/browser/mojo/mojo_shell_context.h ('k') | content/browser/mojo_shell_browsertest.cc » ('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 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 <unordered_map> 7 #include <unordered_map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 void OnApplicationLoaded(const std::string& name, bool success) { 68 void OnApplicationLoaded(const std::string& name, bool success) {
69 if (!success) 69 if (!success)
70 LOG(ERROR) << "Failed to launch Mojo application for " << name; 70 LOG(ERROR) << "Failed to launch Mojo application for " << name;
71 } 71 }
72 72
73 // This launches a utility process and forwards the Load request the 73 // This launches a utility process and forwards the Load request the
74 // mojom::ProcessControl service there. The utility process is sandboxed iff 74 // mojom::ProcessControl service there. The utility process is sandboxed iff
75 // |use_sandbox| is true. 75 // |use_sandbox| is true.
76 class UtilityProcessLoader : public mojo::shell::Loader { 76 class UtilityProcessLoader : public shell::Loader {
77 public: 77 public:
78 UtilityProcessLoader(const base::string16& process_name, bool use_sandbox) 78 UtilityProcessLoader(const base::string16& process_name, bool use_sandbox)
79 : process_name_(process_name), use_sandbox_(use_sandbox) {} 79 : process_name_(process_name), use_sandbox_(use_sandbox) {}
80 ~UtilityProcessLoader() override {} 80 ~UtilityProcessLoader() override {}
81 81
82 private: 82 private:
83 // mojo::shell::Loader: 83 // shell::Loader:
84 void Load(const std::string& name, 84 void Load(const std::string& name,
85 mojo::shell::mojom::ShellClientRequest request) override { 85 shell::mojom::ShellClientRequest request) override {
86 mojom::ProcessControlPtr process_control; 86 mojom::ProcessControlPtr process_control;
87 auto process_request = mojo::GetProxy(&process_control); 87 auto process_request = mojo::GetProxy(&process_control);
88 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 88 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
89 base::Bind(&StartUtilityProcessOnIOThread, 89 base::Bind(&StartUtilityProcessOnIOThread,
90 base::Passed(&process_request), 90 base::Passed(&process_request),
91 process_name_, use_sandbox_)); 91 process_name_, use_sandbox_));
92 process_control->LoadApplication(name, std::move(request), 92 process_control->LoadApplication(name, std::move(request),
93 base::Bind(&OnApplicationLoaded, name)); 93 base::Bind(&OnApplicationLoaded, name));
94 } 94 }
95 95
(...skipping 18 matching lines...) Expand all
114 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual 114 // TODO(xhwang): It's possible that |process_host| is non-null, but the actual
115 // process is dead. In that case, |request| will be dropped and application 115 // process is dead. In that case, |request| will be dropped and application
116 // load requests through mojom::ProcessControl will also fail. Make sure we 116 // load requests through mojom::ProcessControl will also fail. Make sure we
117 // handle 117 // handle
118 // these cases correctly. 118 // these cases correctly.
119 process_host->GetServiceRegistry()->ConnectToRemoteService( 119 process_host->GetServiceRegistry()->ConnectToRemoteService(
120 std::move(request)); 120 std::move(request));
121 } 121 }
122 122
123 // Forwards the load request to the GPU process. 123 // Forwards the load request to the GPU process.
124 class GpuProcessLoader : public mojo::shell::Loader { 124 class GpuProcessLoader : public shell::Loader {
125 public: 125 public:
126 GpuProcessLoader() {} 126 GpuProcessLoader() {}
127 ~GpuProcessLoader() override {} 127 ~GpuProcessLoader() override {}
128 128
129 private: 129 private:
130 // mojo::shell::Loader: 130 // shell::Loader:
131 void Load(const std::string& name, 131 void Load(const std::string& name,
132 mojo::shell::mojom::ShellClientRequest request) override { 132 shell::mojom::ShellClientRequest request) override {
133 mojom::ProcessControlPtr process_control; 133 mojom::ProcessControlPtr process_control;
134 auto process_request = mojo::GetProxy(&process_control); 134 auto process_request = mojo::GetProxy(&process_control);
135 BrowserThread::PostTask( 135 BrowserThread::PostTask(
136 BrowserThread::IO, FROM_HERE, 136 BrowserThread::IO, FROM_HERE,
137 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request))); 137 base::Bind(&RequestGpuProcessControl, base::Passed(&process_request)));
138 process_control->LoadApplication(name, std::move(request), 138 process_control->LoadApplication(name, std::move(request),
139 base::Bind(&OnApplicationLoaded, name)); 139 base::Bind(&OnApplicationLoaded, name));
140 } 140 }
141 141
142 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader); 142 DISALLOW_COPY_AND_ASSIGN(GpuProcessLoader);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 Proxy(MojoShellContext* shell_context) 181 Proxy(MojoShellContext* shell_context)
182 : shell_context_(shell_context), 182 : shell_context_(shell_context),
183 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 183 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
184 184
185 ~Proxy() {} 185 ~Proxy() {}
186 186
187 void ConnectToApplication( 187 void ConnectToApplication(
188 const std::string& user_id, 188 const std::string& user_id,
189 const std::string& name, 189 const std::string& name,
190 const std::string& requestor_name, 190 const std::string& requestor_name,
191 mojo::shell::mojom::InterfaceProviderRequest request, 191 shell::mojom::InterfaceProviderRequest request,
192 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 192 shell::mojom::InterfaceProviderPtr exposed_services,
193 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 193 const shell::mojom::Connector::ConnectCallback& callback) {
194 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { 194 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) {
195 if (shell_context_) { 195 if (shell_context_) {
196 shell_context_->ConnectToApplicationOnOwnThread( 196 shell_context_->ConnectToApplicationOnOwnThread(
197 user_id, name, requestor_name, std::move(request), 197 user_id, name, requestor_name, std::move(request),
198 std::move(exposed_services), callback); 198 std::move(exposed_services), callback);
199 } 199 }
200 } else { 200 } else {
201 // |shell_context_| outlives the main MessageLoop, so it's safe for it to 201 // |shell_context_| outlives the main MessageLoop, so it's safe for it to
202 // be unretained here. 202 // be unretained here.
203 task_runner_->PostTask( 203 task_runner_->PostTask(
(...skipping 19 matching lines...) Expand all
223 void MojoShellContext::SetApplicationsForTest( 223 void MojoShellContext::SetApplicationsForTest(
224 const StaticApplicationMap* apps) { 224 const StaticApplicationMap* apps) {
225 g_applications_for_test = apps; 225 g_applications_for_test = apps;
226 } 226 }
227 227
228 MojoShellContext::MojoShellContext() { 228 MojoShellContext::MojoShellContext() {
229 proxy_.Get().reset(new Proxy(this)); 229 proxy_.Get().reset(new Proxy(this));
230 230
231 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 231 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
232 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 232 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
233 std::unique_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( 233 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory(
234 new mojo::shell::InProcessNativeRunnerFactory( 234 new shell::InProcessNativeRunnerFactory(
235 BrowserThread::GetBlockingPool())); 235 BrowserThread::GetBlockingPool()));
236 236
237 manifest_provider_.reset(new BuiltinManifestProvider); 237 manifest_provider_.reset(new BuiltinManifestProvider);
238 manifest_provider_->AddManifestResource(kBrowserMojoApplicationName, 238 manifest_provider_->AddManifestResource(kBrowserMojoApplicationName,
239 IDR_MOJO_CONTENT_BROWSER_MANIFEST); 239 IDR_MOJO_CONTENT_BROWSER_MANIFEST);
240 manifest_provider_->AddManifestResource(kRendererMojoApplicationName, 240 manifest_provider_->AddManifestResource(kRendererMojoApplicationName,
241 IDR_MOJO_CONTENT_RENDERER_MANIFEST); 241 IDR_MOJO_CONTENT_RENDERER_MANIFEST);
242 manifest_provider_->AddManifestResource("mojo:catalog", 242 manifest_provider_->AddManifestResource("mojo:catalog",
243 IDR_MOJO_CATALOG_MANIFEST); 243 IDR_MOJO_CATALOG_MANIFEST);
244 manifest_provider_->AddManifestResource(user_service::kUserServiceName, 244 manifest_provider_->AddManifestResource(user_service::kUserServiceName,
245 IDR_MOJO_PROFILE_MANIFEST); 245 IDR_MOJO_PROFILE_MANIFEST);
246 246
247 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr, 247 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr,
248 manifest_provider_.get())); 248 manifest_provider_.get()));
249 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), 249 shell_.reset(new shell::Shell(std::move(native_runner_factory),
250 catalog_->TakeShellClient())); 250 catalog_->TakeShellClient()));
251 251
252 StaticApplicationMap apps; 252 StaticApplicationMap apps;
253 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 253 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
254 if (g_applications_for_test) { 254 if (g_applications_for_test) {
255 // Add testing apps to the map, potentially overwriting whatever the 255 // Add testing apps to the map, potentially overwriting whatever the
256 // browser client registered. 256 // browser client registered.
257 for (const auto& entry : *g_applications_for_test) 257 for (const auto& entry : *g_applications_for_test)
258 apps[entry.first] = entry.second; 258 apps[entry.first] = entry.second;
259 } 259 }
260 for (const auto& entry : apps) { 260 for (const auto& entry : apps) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 MojoShellContext::~MojoShellContext() { 297 MojoShellContext::~MojoShellContext() {
298 if (!IsRunningInMojoShell()) 298 if (!IsRunningInMojoShell())
299 MojoShellConnectionImpl::Destroy(); 299 MojoShellConnectionImpl::Destroy();
300 } 300 }
301 301
302 // static 302 // static
303 void MojoShellContext::ConnectToApplication( 303 void MojoShellContext::ConnectToApplication(
304 const std::string& user_id, 304 const std::string& user_id,
305 const std::string& name, 305 const std::string& name,
306 const std::string& requestor_name, 306 const std::string& requestor_name,
307 mojo::shell::mojom::InterfaceProviderRequest request, 307 shell::mojom::InterfaceProviderRequest request,
308 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 308 shell::mojom::InterfaceProviderPtr exposed_services,
309 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 309 const shell::mojom::Connector::ConnectCallback& callback) {
310 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, 310 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name,
311 std::move(request), 311 std::move(request),
312 std::move(exposed_services), callback); 312 std::move(exposed_services), callback);
313 } 313 }
314 314
315 void MojoShellContext::ConnectToApplicationOnOwnThread( 315 void MojoShellContext::ConnectToApplicationOnOwnThread(
316 const std::string& user_id, 316 const std::string& user_id,
317 const std::string& name, 317 const std::string& name,
318 const std::string& requestor_name, 318 const std::string& requestor_name,
319 mojo::shell::mojom::InterfaceProviderRequest request, 319 shell::mojom::InterfaceProviderRequest request,
320 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 320 shell::mojom::InterfaceProviderPtr exposed_services,
321 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 321 const shell::mojom::Connector::ConnectCallback& callback) {
322 std::unique_ptr<mojo::shell::ConnectParams> params( 322 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
323 new mojo::shell::ConnectParams); 323 shell::Identity source_id(requestor_name, user_id);
324 mojo::Identity source_id(requestor_name, user_id);
325 params->set_source(source_id); 324 params->set_source(source_id);
326 params->set_target(mojo::Identity(name, user_id)); 325 params->set_target(shell::Identity(name, user_id));
327 params->set_remote_interfaces(std::move(request)); 326 params->set_remote_interfaces(std::move(request));
328 params->set_local_interfaces(std::move(exposed_services)); 327 params->set_local_interfaces(std::move(exposed_services));
329 params->set_connect_callback(callback); 328 params->set_connect_callback(callback);
330 shell_->Connect(std::move(params)); 329 shell_->Connect(std::move(params));
331 } 330 }
332 331
333 } // namespace content 332 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/mojo_shell_context.h ('k') | content/browser/mojo_shell_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698