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

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

Issue 1737933002: mojo leveldb: Get profile and leveldb connected to DOMStorageContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keeping up with the ToT Created 4 years, 9 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h"
9 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/path_service.h" 12 #include "base/path_service.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "components/leveldb/leveldb_app.h"
14 #include "components/profile_service/profile_app.h" 16 #include "components/profile_service/profile_app.h"
15 #include "content/browser/gpu/gpu_process_host.h" 17 #include "content/browser/gpu/gpu_process_host.h"
16 #include "content/common/gpu/gpu_process_launch_causes.h" 18 #include "content/common/gpu/gpu_process_launch_causes.h"
17 #include "content/common/mojo/mojo_shell_connection_impl.h" 19 #include "content/common/mojo/mojo_shell_connection_impl.h"
18 #include "content/common/mojo/static_loader.h" 20 #include "content/common/mojo/static_loader.h"
19 #include "content/common/process_control.mojom.h" 21 #include "content/common/process_control.mojom.h"
22 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/content_browser_client.h" 24 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/utility_process_host.h" 25 #include "content/public/browser/utility_process_host.h"
23 #include "content/public/browser/utility_process_host_client.h" 26 #include "content/public/browser/utility_process_host_client.h"
24 #include "content/public/common/content_client.h" 27 #include "content/public/common/content_client.h"
25 #include "content/public/common/service_registry.h" 28 #include "content/public/common/service_registry.h"
26 #include "mojo/public/cpp/bindings/interface_request.h" 29 #include "mojo/public/cpp/bindings/interface_request.h"
27 #include "mojo/public/cpp/bindings/string.h" 30 #include "mojo/public/cpp/bindings/string.h"
28 #include "mojo/shell/connect_params.h" 31 #include "mojo/shell/connect_params.h"
29 #include "mojo/shell/identity.h" 32 #include "mojo/shell/identity.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Thread-safe proxy providing access to the shell context from any thread. 154 // Thread-safe proxy providing access to the shell context from any thread.
152 class MojoShellContext::Proxy { 155 class MojoShellContext::Proxy {
153 public: 156 public:
154 Proxy(MojoShellContext* shell_context) 157 Proxy(MojoShellContext* shell_context)
155 : shell_context_(shell_context), 158 : shell_context_(shell_context),
156 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 159 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
157 160
158 ~Proxy() {} 161 ~Proxy() {}
159 162
160 void ConnectToApplication( 163 void ConnectToApplication(
164 uint32_t user_id,
161 const std::string& name, 165 const std::string& name,
162 const std::string& requestor_name, 166 const std::string& requestor_name,
163 mojo::shell::mojom::InterfaceProviderRequest request, 167 mojo::shell::mojom::InterfaceProviderRequest request,
164 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 168 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
165 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 169 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
166 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { 170 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) {
167 if (shell_context_) { 171 if (shell_context_) {
168 shell_context_->ConnectToApplicationOnOwnThread( 172 shell_context_->ConnectToApplicationOnOwnThread(
169 name, requestor_name, std::move(request), 173 user_id, name, requestor_name, std::move(request),
170 std::move(exposed_services), callback); 174 std::move(exposed_services), callback);
171 } 175 }
172 } else { 176 } else {
173 // |shell_context_| outlives the main MessageLoop, so it's safe for it to 177 // |shell_context_| outlives the main MessageLoop, so it's safe for it to
174 // be unretained here. 178 // be unretained here.
175 task_runner_->PostTask( 179 task_runner_->PostTask(
176 FROM_HERE, 180 FROM_HERE,
177 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, 181 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread,
178 base::Unretained(shell_context_), name, requestor_name, 182 base::Unretained(shell_context_), user_id, name,
179 base::Passed(&request), base::Passed(&exposed_services), 183 requestor_name, base::Passed(&request),
180 callback)); 184 base::Passed(&exposed_services), callback));
181 } 185 }
182 } 186 }
183 187
184 private: 188 private:
185 MojoShellContext* shell_context_; 189 MojoShellContext* shell_context_;
186 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 190 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
187 191
188 DISALLOW_COPY_AND_ASSIGN(Proxy); 192 DISALLOW_COPY_AND_ASSIGN(Proxy);
189 }; 193 };
190 194
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 make_scoped_ptr( 248 make_scoped_ptr(
245 new UtilityProcessLoader(app.second, false /* use_sandbox */)), 249 new UtilityProcessLoader(app.second, false /* use_sandbox */)),
246 app.first); 250 app.first);
247 } 251 }
248 252
249 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 253 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
250 application_manager_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), 254 application_manager_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader),
251 "mojo:media"); 255 "mojo:media");
252 #endif 256 #endif
253 257
258 base::Callback<scoped_ptr<mojo::ShellClient>()> leveldb_callback =
259 base::Bind(&leveldb::CreateLevelDBApp);
260 application_manager_->SetLoaderForName(
261 make_scoped_ptr(new StaticLoader(leveldb_callback)),
262 "mojo:leveldb");
263
254 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = 264 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback =
255 base::Bind(&profile::CreateProfileApp); 265 base::Bind(&profile::CreateProfileApp);
256 application_manager_->SetLoaderForName( 266 application_manager_->SetLoaderForName(
257 make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile"); 267 make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile");
258 268
259 if (!IsRunningInMojoShell()) { 269 if (!IsRunningInMojoShell()) {
260 MojoShellConnectionImpl::Create( 270 MojoShellConnectionImpl::Create(
261 application_manager_->InitInstanceForEmbedder(kBrowserAppName)); 271 application_manager_->InitInstanceForEmbedder(kBrowserAppName));
262 } 272 }
263 } 273 }
264 274
265 MojoShellContext::~MojoShellContext() { 275 MojoShellContext::~MojoShellContext() {
266 if (!IsRunningInMojoShell()) 276 if (!IsRunningInMojoShell())
267 MojoShellConnectionImpl::Destroy(); 277 MojoShellConnectionImpl::Destroy();
268 } 278 }
269 279
270 // static 280 // static
271 void MojoShellContext::ConnectToApplication( 281 void MojoShellContext::ConnectToApplication(
272 const std::string& name, 282 const std::string& name,
273 const std::string& requestor_name, 283 const std::string& requestor_name,
274 mojo::shell::mojom::InterfaceProviderRequest request, 284 mojo::shell::mojom::InterfaceProviderRequest request,
275 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 285 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
276 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 286 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
277 proxy_.Get()->ConnectToApplication(name, requestor_name, std::move(request), 287 // TODO(beng): kUserRoot is obviously wrong.
278 std::move(exposed_services), callback); 288 proxy_.Get()->ConnectToApplication(
289 mojo::shell::mojom::Connector::kUserRoot,
Ben Goodger (Google) 2016/03/04 20:50:49 this should be kUserInherit. Then the shell will f
290 name, requestor_name, std::move(request),
291 std::move(exposed_services), callback);
292 }
293
294 // static
295 void MojoShellContext::ConnectToApplicationWithContext(
296 BrowserContext* context,
Ben Goodger (Google) 2016/03/04 20:50:49 rather than introduce knowledge of BrowserContext
297 const std::string& name,
298 const std::string& requestor_name,
299 mojo::shell::mojom::InterfaceProviderRequest request,
300 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
301 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
302 uint32_t user_id = BrowserContext::GetMojoUserIdFor(context);
303 proxy_.Get()->ConnectToApplication(
304 user_id, name, requestor_name, std::move(request),
305 std::move(exposed_services), callback);
279 } 306 }
280 307
281 void MojoShellContext::ConnectToApplicationOnOwnThread( 308 void MojoShellContext::ConnectToApplicationOnOwnThread(
309 uint32_t user_id,
282 const std::string& name, 310 const std::string& name,
283 const std::string& requestor_name, 311 const std::string& requestor_name,
284 mojo::shell::mojom::InterfaceProviderRequest request, 312 mojo::shell::mojom::InterfaceProviderRequest request,
285 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 313 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
286 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 314 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
287 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams); 315 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams);
288 // TODO(beng): kUserRoot is obviously wrong.
289 // TODO(beng): We need to set a permissive filter here temporarily because 316 // TODO(beng): We need to set a permissive filter here temporarily because
290 // content is known as a bogus system: name that the application 317 // content is known as a bogus system: name that the application
291 // manager doesn't understand. 318 // manager doesn't understand.
292 mojo::shell::Identity source_id( 319 mojo::shell::Identity source_id(requestor_name, std::string(), user_id);
293 requestor_name, std::string(), mojo::shell::mojom::Connector::kUserRoot);
294 source_id.set_filter(mojo::shell::GetPermissiveCapabilityFilter()); 320 source_id.set_filter(mojo::shell::GetPermissiveCapabilityFilter());
295 params->set_source(source_id); 321 params->set_source(source_id);
296 params->set_target(mojo::shell::Identity( 322 params->set_target(mojo::shell::Identity(
297 name, std::string(), mojo::shell::mojom::Connector::kUserRoot)); 323 name, std::string(), user_id));
298 params->set_remote_interfaces(std::move(request)); 324 params->set_remote_interfaces(std::move(request));
299 params->set_local_interfaces(std::move(exposed_services)); 325 params->set_local_interfaces(std::move(exposed_services));
300 params->set_connect_callback(callback); 326 params->set_connect_callback(callback);
301 application_manager_->Connect(std::move(params)); 327 application_manager_->Connect(std::move(params));
302 } 328 }
303 329
304 } // namespace content 330 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698