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

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: Remove stray mark. 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"
10 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/path_service.h" 13 #include "base/path_service.h"
12 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.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"
19 #include "content/common/mojo/current_thread_loader.h"
17 #include "content/common/mojo/mojo_shell_connection_impl.h" 20 #include "content/common/mojo/mojo_shell_connection_impl.h"
18 #include "content/common/mojo/static_loader.h" 21 #include "content/common/mojo/static_loader.h"
19 #include "content/common/process_control.mojom.h" 22 #include "content/common/process_control.mojom.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"
28 #include "content/public/common/content_switches.h"
25 #include "content/public/common/service_registry.h" 29 #include "content/public/common/service_registry.h"
26 #include "mojo/public/cpp/bindings/interface_request.h" 30 #include "mojo/public/cpp/bindings/interface_request.h"
27 #include "mojo/public/cpp/bindings/string.h" 31 #include "mojo/public/cpp/bindings/string.h"
28 #include "mojo/services/catalog/factory.h" 32 #include "mojo/services/catalog/factory.h"
29 #include "mojo/services/catalog/store.h" 33 #include "mojo/services/catalog/store.h"
30 #include "mojo/shell/connect_params.h" 34 #include "mojo/shell/connect_params.h"
31 #include "mojo/shell/loader.h" 35 #include "mojo/shell/loader.h"
32 #include "mojo/shell/native_runner.h" 36 #include "mojo/shell/native_runner.h"
33 #include "mojo/shell/public/cpp/identity.h" 37 #include "mojo/shell/public/cpp/identity.h"
34 #include "mojo/shell/public/cpp/shell_client.h" 38 #include "mojo/shell/public/cpp/shell_client.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Thread-safe proxy providing access to the shell context from any thread. 157 // Thread-safe proxy providing access to the shell context from any thread.
154 class MojoShellContext::Proxy { 158 class MojoShellContext::Proxy {
155 public: 159 public:
156 Proxy(MojoShellContext* shell_context) 160 Proxy(MojoShellContext* shell_context)
157 : shell_context_(shell_context), 161 : shell_context_(shell_context),
158 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 162 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
159 163
160 ~Proxy() {} 164 ~Proxy() {}
161 165
162 void ConnectToApplication( 166 void ConnectToApplication(
167 const std::string& user_id,
163 const std::string& name, 168 const std::string& name,
164 const std::string& requestor_name, 169 const std::string& requestor_name,
165 mojo::shell::mojom::InterfaceProviderRequest request, 170 mojo::shell::mojom::InterfaceProviderRequest request,
166 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 171 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
167 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 172 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
168 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { 173 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) {
169 if (shell_context_) { 174 if (shell_context_) {
170 shell_context_->ConnectToApplicationOnOwnThread( 175 shell_context_->ConnectToApplicationOnOwnThread(
171 name, requestor_name, std::move(request), 176 user_id, name, requestor_name, std::move(request),
172 std::move(exposed_services), callback); 177 std::move(exposed_services), callback);
173 } 178 }
174 } else { 179 } else {
175 // |shell_context_| outlives the main MessageLoop, so it's safe for it to 180 // |shell_context_| outlives the main MessageLoop, so it's safe for it to
176 // be unretained here. 181 // be unretained here.
177 task_runner_->PostTask( 182 task_runner_->PostTask(
178 FROM_HERE, 183 FROM_HERE,
179 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, 184 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread,
180 base::Unretained(shell_context_), name, requestor_name, 185 base::Unretained(shell_context_), user_id, name,
181 base::Passed(&request), base::Passed(&exposed_services), 186 requestor_name, base::Passed(&request),
182 callback)); 187 base::Passed(&exposed_services), callback));
183 } 188 }
184 } 189 }
185 190
186 private: 191 private:
187 MojoShellContext* shell_context_; 192 MojoShellContext* shell_context_;
188 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 193 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
189 194
190 DISALLOW_COPY_AND_ASSIGN(Proxy); 195 DISALLOW_COPY_AND_ASSIGN(Proxy);
191 }; 196 };
192 197
193 // static 198 // static
194 base::LazyInstance<scoped_ptr<MojoShellContext::Proxy>> 199 base::LazyInstance<scoped_ptr<MojoShellContext::Proxy>>
195 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; 200 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER;
196 201
197 void MojoShellContext::SetApplicationsForTest( 202 void MojoShellContext::SetApplicationsForTest(
198 const StaticApplicationMap* apps) { 203 const StaticApplicationMap* apps) {
199 g_applications_for_test = apps; 204 g_applications_for_test = apps;
200 } 205 }
201 206
202 MojoShellContext::MojoShellContext() { 207 MojoShellContext::MojoShellContext(
208 scoped_refptr<base::SingleThreadTaskRunner> file_thread,
209 scoped_refptr<base::SingleThreadTaskRunner> db_thread) {
203 proxy_.Get().reset(new Proxy(this)); 210 proxy_.Get().reset(new Proxy(this));
204 211
205 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 212 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
206 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 213 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
207 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory( 214 scoped_ptr<mojo::shell::NativeRunnerFactory> native_runner_factory(
208 new mojo::shell::InProcessNativeRunnerFactory( 215 new mojo::shell::InProcessNativeRunnerFactory(
209 BrowserThread::GetBlockingPool())); 216 BrowserThread::GetBlockingPool()));
210 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr)); 217 catalog_.reset(new catalog::Factory(file_task_runner.get(), nullptr));
211 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory), 218 shell_.reset(new mojo::shell::Shell(std::move(native_runner_factory),
212 catalog_->TakeShellClient())); 219 catalog_->TakeShellClient()));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 shell_->SetLoaderForName( 253 shell_->SetLoaderForName(
247 make_scoped_ptr( 254 make_scoped_ptr(
248 new UtilityProcessLoader(app.second, false /* use_sandbox */)), 255 new UtilityProcessLoader(app.second, false /* use_sandbox */)),
249 app.first); 256 app.first);
250 } 257 }
251 258
252 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 259 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
253 shell_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), "mojo:media"); 260 shell_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), "mojo:media");
254 #endif 261 #endif
255 262
256 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = 263 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
257 base::Bind(&profile::CreateProfileApp); 264 switches::kMojoLocalStorage)) {
258 shell_->SetLoaderForName( 265 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback =
259 make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile"); 266 base::Bind(&profile::CreateProfileApp, file_thread, db_thread);
267 shell_->SetLoaderForName(
michaeln 2016/03/17 22:35:42 SetLoaderForName() used to happen unconditionally
Elliot Glaysher 2016/03/18 19:41:13 Right now, the only caller is local storage and I'
268 make_scoped_ptr(new CurrentThreadLoader(profile_callback)),
269 "mojo:profile");
270 }
260 271
261 if (!IsRunningInMojoShell()) { 272 if (!IsRunningInMojoShell()) {
262 MojoShellConnectionImpl::Create( 273 MojoShellConnectionImpl::Create(
263 shell_->InitInstanceForEmbedder(kBrowserAppName)); 274 shell_->InitInstanceForEmbedder(kBrowserAppName));
264 } 275 }
265 } 276 }
266 277
267 MojoShellContext::~MojoShellContext() { 278 MojoShellContext::~MojoShellContext() {
268 if (!IsRunningInMojoShell()) 279 if (!IsRunningInMojoShell())
269 MojoShellConnectionImpl::Destroy(); 280 MojoShellConnectionImpl::Destroy();
270 } 281 }
271 282
272 // static 283 // static
273 void MojoShellContext::ConnectToApplication( 284 void MojoShellContext::ConnectToApplication(
285 const std::string& user_id,
274 const std::string& name, 286 const std::string& name,
275 const std::string& requestor_name, 287 const std::string& requestor_name,
276 mojo::shell::mojom::InterfaceProviderRequest request, 288 mojo::shell::mojom::InterfaceProviderRequest request,
277 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 289 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
278 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 290 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
279 proxy_.Get()->ConnectToApplication(name, requestor_name, std::move(request), 291 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name,
292 std::move(request),
280 std::move(exposed_services), callback); 293 std::move(exposed_services), callback);
281 } 294 }
282 295
283 void MojoShellContext::ConnectToApplicationOnOwnThread( 296 void MojoShellContext::ConnectToApplicationOnOwnThread(
297 const std::string& user_id,
284 const std::string& name, 298 const std::string& name,
285 const std::string& requestor_name, 299 const std::string& requestor_name,
286 mojo::shell::mojom::InterfaceProviderRequest request, 300 mojo::shell::mojom::InterfaceProviderRequest request,
287 mojo::shell::mojom::InterfaceProviderPtr exposed_services, 301 mojo::shell::mojom::InterfaceProviderPtr exposed_services,
288 const mojo::shell::mojom::Connector::ConnectCallback& callback) { 302 const mojo::shell::mojom::Connector::ConnectCallback& callback) {
289 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams); 303 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams);
290 // TODO(beng): kRootUserID is obviously wrong. 304 mojo::Identity source_id(requestor_name, user_id);
291 mojo::Identity source_id(requestor_name, mojo::shell::mojom::kRootUserID);
292 params->set_source(source_id); 305 params->set_source(source_id);
293 params->set_target(mojo::Identity(name, mojo::shell::mojom::kRootUserID)); 306 params->set_target(mojo::Identity(name, user_id));
294 params->set_remote_interfaces(std::move(request)); 307 params->set_remote_interfaces(std::move(request));
295 params->set_local_interfaces(std::move(exposed_services)); 308 params->set_local_interfaces(std::move(exposed_services));
296 params->set_connect_callback(callback); 309 params->set_connect_callback(callback);
297 shell_->Connect(std::move(params)); 310 shell_->Connect(std::move(params));
298 } 311 }
299 312
300 } // namespace content 313 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698