| 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/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" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
| 22 #include "content/public/browser/utility_process_host.h" | 24 #include "content/public/browser/utility_process_host.h" |
| 23 #include "content/public/browser/utility_process_host_client.h" | 25 #include "content/public/browser/utility_process_host_client.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Thread-safe proxy providing access to the shell context from any thread. | 153 // Thread-safe proxy providing access to the shell context from any thread. |
| 152 class MojoShellContext::Proxy { | 154 class MojoShellContext::Proxy { |
| 153 public: | 155 public: |
| 154 Proxy(MojoShellContext* shell_context) | 156 Proxy(MojoShellContext* shell_context) |
| 155 : shell_context_(shell_context), | 157 : shell_context_(shell_context), |
| 156 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 158 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 157 | 159 |
| 158 ~Proxy() {} | 160 ~Proxy() {} |
| 159 | 161 |
| 160 void ConnectToApplication( | 162 void ConnectToApplication( |
| 163 uint32_t user_id, |
| 161 const std::string& name, | 164 const std::string& name, |
| 162 const std::string& requestor_name, | 165 const std::string& requestor_name, |
| 163 mojo::shell::mojom::InterfaceProviderRequest request, | 166 mojo::shell::mojom::InterfaceProviderRequest request, |
| 164 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 167 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 165 const mojo::shell::mojom::Connector::ConnectCallback& callback) { | 168 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 166 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { | 169 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { |
| 167 if (shell_context_) { | 170 if (shell_context_) { |
| 168 shell_context_->ConnectToApplicationOnOwnThread( | 171 shell_context_->ConnectToApplicationOnOwnThread( |
| 169 name, requestor_name, std::move(request), | 172 user_id, name, requestor_name, std::move(request), |
| 170 std::move(exposed_services), callback); | 173 std::move(exposed_services), callback); |
| 171 } | 174 } |
| 172 } else { | 175 } else { |
| 173 // |shell_context_| outlives the main MessageLoop, so it's safe for it to | 176 // |shell_context_| outlives the main MessageLoop, so it's safe for it to |
| 174 // be unretained here. | 177 // be unretained here. |
| 175 task_runner_->PostTask( | 178 task_runner_->PostTask( |
| 176 FROM_HERE, | 179 FROM_HERE, |
| 177 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, | 180 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, |
| 178 base::Unretained(shell_context_), name, requestor_name, | 181 base::Unretained(shell_context_), user_id, name, |
| 179 base::Passed(&request), base::Passed(&exposed_services), | 182 requestor_name, base::Passed(&request), |
| 180 callback)); | 183 base::Passed(&exposed_services), callback)); |
| 181 } | 184 } |
| 182 } | 185 } |
| 183 | 186 |
| 184 private: | 187 private: |
| 185 MojoShellContext* shell_context_; | 188 MojoShellContext* shell_context_; |
| 186 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 189 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 187 | 190 |
| 188 DISALLOW_COPY_AND_ASSIGN(Proxy); | 191 DISALLOW_COPY_AND_ASSIGN(Proxy); |
| 189 }; | 192 }; |
| 190 | 193 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 make_scoped_ptr( | 247 make_scoped_ptr( |
| 245 new UtilityProcessLoader(app.second, false /* use_sandbox */)), | 248 new UtilityProcessLoader(app.second, false /* use_sandbox */)), |
| 246 app.first); | 249 app.first); |
| 247 } | 250 } |
| 248 | 251 |
| 249 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 252 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
| 250 application_manager_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), | 253 application_manager_->SetLoaderForName(make_scoped_ptr(new GpuProcessLoader), |
| 251 "mojo:media"); | 254 "mojo:media"); |
| 252 #endif | 255 #endif |
| 253 | 256 |
| 257 base::Callback<scoped_ptr<mojo::ShellClient>()> leveldb_callback = |
| 258 base::Bind(&leveldb::CreateLevelDBApp); |
| 259 application_manager_->SetLoaderForName( |
| 260 make_scoped_ptr(new StaticLoader(leveldb_callback)), |
| 261 "mojo:leveldb"); |
| 262 |
| 254 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = | 263 base::Callback<scoped_ptr<mojo::ShellClient>()> profile_callback = |
| 255 base::Bind(&profile::CreateProfileApp); | 264 base::Bind(&profile::CreateProfileApp); |
| 256 application_manager_->SetLoaderForName( | 265 application_manager_->SetLoaderForName( |
| 257 make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile"); | 266 make_scoped_ptr(new StaticLoader(profile_callback)), "mojo:profile"); |
| 258 | 267 |
| 259 if (!IsRunningInMojoShell()) { | 268 if (!IsRunningInMojoShell()) { |
| 260 MojoShellConnectionImpl::Create( | 269 MojoShellConnectionImpl::Create( |
| 261 application_manager_->InitInstanceForEmbedder(kBrowserAppName)); | 270 application_manager_->InitInstanceForEmbedder(kBrowserAppName)); |
| 262 } | 271 } |
| 263 } | 272 } |
| 264 | 273 |
| 265 MojoShellContext::~MojoShellContext() { | 274 MojoShellContext::~MojoShellContext() { |
| 266 if (!IsRunningInMojoShell()) | 275 if (!IsRunningInMojoShell()) |
| 267 MojoShellConnectionImpl::Destroy(); | 276 MojoShellConnectionImpl::Destroy(); |
| 268 } | 277 } |
| 269 | 278 |
| 270 // static | 279 // static |
| 271 void MojoShellContext::ConnectToApplication( | 280 void MojoShellContext::ConnectToApplication( |
| 272 const std::string& name, | 281 const std::string& name, |
| 273 const std::string& requestor_name, | 282 const std::string& requestor_name, |
| 274 mojo::shell::mojom::InterfaceProviderRequest request, | 283 mojo::shell::mojom::InterfaceProviderRequest request, |
| 275 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 284 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 276 const mojo::shell::mojom::Connector::ConnectCallback& callback) { | 285 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 277 proxy_.Get()->ConnectToApplication(name, requestor_name, std::move(request), | 286 proxy_.Get()->ConnectToApplication( |
| 278 std::move(exposed_services), callback); | 287 mojo::shell::mojom::Connector::kUserInherit, |
| 288 name, requestor_name, std::move(request), |
| 289 std::move(exposed_services), callback); |
| 290 } |
| 291 |
| 292 // static |
| 293 void MojoShellContext::ConnectToApplicationWithUserId( |
| 294 uint32_t user_id, |
| 295 const std::string& name, |
| 296 const std::string& requestor_name, |
| 297 mojo::shell::mojom::InterfaceProviderRequest request, |
| 298 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 299 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 300 proxy_.Get()->ConnectToApplication( |
| 301 user_id, name, requestor_name, std::move(request), |
| 302 std::move(exposed_services), callback); |
| 279 } | 303 } |
| 280 | 304 |
| 281 void MojoShellContext::ConnectToApplicationOnOwnThread( | 305 void MojoShellContext::ConnectToApplicationOnOwnThread( |
| 306 uint32_t user_id, |
| 282 const std::string& name, | 307 const std::string& name, |
| 283 const std::string& requestor_name, | 308 const std::string& requestor_name, |
| 284 mojo::shell::mojom::InterfaceProviderRequest request, | 309 mojo::shell::mojom::InterfaceProviderRequest request, |
| 285 mojo::shell::mojom::InterfaceProviderPtr exposed_services, | 310 mojo::shell::mojom::InterfaceProviderPtr exposed_services, |
| 286 const mojo::shell::mojom::Connector::ConnectCallback& callback) { | 311 const mojo::shell::mojom::Connector::ConnectCallback& callback) { |
| 287 scoped_ptr<mojo::shell::ConnectParams> params(new mojo::shell::ConnectParams); | 312 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 | 313 // TODO(beng): We need to set a permissive filter here temporarily because |
| 290 // content is known as a bogus system: name that the application | 314 // content is known as a bogus system: name that the application |
| 291 // manager doesn't understand. | 315 // manager doesn't understand. |
| 292 mojo::shell::Identity source_id( | 316 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()); | 317 source_id.set_filter(mojo::shell::GetPermissiveCapabilityFilter()); |
| 295 params->set_source(source_id); | 318 params->set_source(source_id); |
| 296 params->set_target(mojo::shell::Identity( | 319 params->set_target(mojo::shell::Identity( |
| 297 name, std::string(), mojo::shell::mojom::Connector::kUserRoot)); | 320 name, std::string(), user_id)); |
| 298 params->set_remote_interfaces(std::move(request)); | 321 params->set_remote_interfaces(std::move(request)); |
| 299 params->set_local_interfaces(std::move(exposed_services)); | 322 params->set_local_interfaces(std::move(exposed_services)); |
| 300 params->set_connect_callback(callback); | 323 params->set_connect_callback(callback); |
| 301 application_manager_->Connect(std::move(params)); | 324 application_manager_->Connect(std::move(params)); |
| 302 } | 325 } |
| 303 | 326 |
| 304 } // namespace content | 327 } // namespace content |
| OLD | NEW |