| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "shell/context.h" | 5 #include "shell/context.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "services/tracing/tracing.mojom.h" | 31 #include "services/tracing/tracing.mojom.h" |
| 32 #include "shell/application_manager/application_loader.h" | 32 #include "shell/application_manager/application_loader.h" |
| 33 #include "shell/application_manager/application_manager.h" | 33 #include "shell/application_manager/application_manager.h" |
| 34 #include "shell/command_line_util.h" | 34 #include "shell/command_line_util.h" |
| 35 #include "shell/filename_util.h" | 35 #include "shell/filename_util.h" |
| 36 #include "shell/in_process_native_runner.h" | 36 #include "shell/in_process_native_runner.h" |
| 37 #include "shell/out_of_process_native_runner.h" | 37 #include "shell/out_of_process_native_runner.h" |
| 38 #include "shell/switches.h" | 38 #include "shell/switches.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 | 40 |
| 41 namespace mojo { | |
| 42 namespace shell { | 41 namespace shell { |
| 43 namespace { | 42 namespace { |
| 44 | 43 |
| 45 // Used to ensure we only init once. | 44 // Used to ensure we only init once. |
| 46 class Setup { | 45 class Setup { |
| 47 public: | 46 public: |
| 48 Setup() { | 47 Setup() { |
| 49 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); | 48 mojo::embedder::Init( |
| 49 make_scoped_ptr(new mojo::embedder::SimplePlatformSupport())); |
| 50 } | 50 } |
| 51 | 51 |
| 52 ~Setup() {} | 52 ~Setup() {} |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(Setup); | 55 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 bool ConfigureURLMappings(const base::CommandLine& command_line, | 58 bool ConfigureURLMappings(const base::CommandLine& command_line, |
| 59 Context* context) { | 59 Context* context) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 << ": '" << force_in_process_url << "'is not a valid URL."; | 164 << ": '" << force_in_process_url << "'is not a valid URL."; |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 | 167 |
| 168 NativeRunnerFactory::Options options; | 168 NativeRunnerFactory::Options options; |
| 169 options.force_in_process = true; | 169 options.force_in_process = true; |
| 170 manager->SetNativeOptionsForURL(options, gurl); | 170 manager->SetNativeOptionsForURL(options, gurl); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 class TracingServiceProvider : public ServiceProvider { | 174 class TracingServiceProvider : public mojo::ServiceProvider { |
| 175 public: | 175 public: |
| 176 explicit TracingServiceProvider(InterfaceRequest<ServiceProvider> request) | 176 explicit TracingServiceProvider( |
| 177 mojo::InterfaceRequest<mojo::ServiceProvider> request) |
| 177 : binding_(this, request.Pass()) {} | 178 : binding_(this, request.Pass()) {} |
| 178 ~TracingServiceProvider() override {} | 179 ~TracingServiceProvider() override {} |
| 179 | 180 |
| 180 void ConnectToService(const String& service_name, | 181 void ConnectToService(const mojo::String& service_name, |
| 181 ScopedMessagePipeHandle client_handle) override { | 182 mojo::ScopedMessagePipeHandle client_handle) override { |
| 182 if (service_name == tracing::TraceController::Name_) { | 183 if (service_name == tracing::TraceController::Name_) { |
| 183 new TraceControllerImpl( | 184 new mojo::TraceControllerImpl( |
| 184 MakeRequest<tracing::TraceController>(client_handle.Pass())); | 185 mojo::MakeRequest<tracing::TraceController>(client_handle.Pass())); |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 private: | 189 private: |
| 189 StrongBinding<ServiceProvider> binding_; | 190 mojo::StrongBinding<mojo::ServiceProvider> binding_; |
| 190 | 191 |
| 191 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider); | 192 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider); |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 } // namespace | 195 } // namespace |
| 195 | 196 |
| 196 Context::Context() : application_manager_(this) { | 197 Context::Context() : application_manager_(this) { |
| 197 DCHECK(!base::MessageLoop::current()); | 198 DCHECK(!base::MessageLoop::current()); |
| 198 | 199 |
| 199 // By default assume that the local apps reside alongside the shell. | 200 // By default assume that the local apps reside alongside the shell. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); | 260 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); |
| 260 | 261 |
| 261 // TODO(vtl): Probably these failures should be checked before |Init()|, and | 262 // TODO(vtl): Probably these failures should be checked before |Init()|, and |
| 262 // this function simply shouldn't fail. | 263 // this function simply shouldn't fail. |
| 263 if (!shell_file_root_.is_valid()) | 264 if (!shell_file_root_.is_valid()) |
| 264 return false; | 265 return false; |
| 265 if (!ConfigureURLMappings(command_line, this)) | 266 if (!ConfigureURLMappings(command_line, this)) |
| 266 return false; | 267 return false; |
| 267 | 268 |
| 268 // TODO(vtl): This should be MASTER, not NONE. | 269 // TODO(vtl): This should be MASTER, not NONE. |
| 269 embedder::InitIPCSupport( | 270 mojo::embedder::InitIPCSupport( |
| 270 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, | 271 mojo::embedder::ProcessType::NONE, task_runners_->shell_runner(), this, |
| 271 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); | 272 task_runners_->io_runner(), mojo::embedder::ScopedPlatformHandle()); |
| 272 | 273 |
| 273 scoped_ptr<NativeRunnerFactory> runner_factory; | 274 scoped_ptr<NativeRunnerFactory> runner_factory; |
| 274 if (command_line.HasSwitch(switches::kEnableMultiprocess)) | 275 if (command_line.HasSwitch(switches::kEnableMultiprocess)) |
| 275 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); | 276 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); |
| 276 else | 277 else |
| 277 runner_factory.reset(new InProcessNativeRunnerFactory(this)); | 278 runner_factory.reset(new InProcessNativeRunnerFactory(this)); |
| 278 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); | 279 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); |
| 279 application_manager_.set_native_runner_factory(runner_factory.Pass()); | 280 application_manager_.set_native_runner_factory(runner_factory.Pass()); |
| 280 application_manager_.set_disable_cache( | 281 application_manager_.set_disable_cache( |
| 281 base::CommandLine::ForCurrentProcess()->HasSwitch( | 282 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 282 switches::kDisableCache)); | 283 switches::kDisableCache)); |
| 283 | 284 |
| 284 InitContentHandlers(&application_manager_, command_line); | 285 InitContentHandlers(&application_manager_, command_line); |
| 285 InitNativeOptions(&application_manager_, command_line); | 286 InitNativeOptions(&application_manager_, command_line); |
| 286 | 287 |
| 287 ServiceProviderPtr tracing_service_provider_ptr; | 288 mojo::ServiceProviderPtr tracing_service_provider_ptr; |
| 288 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); | 289 new TracingServiceProvider(mojo::GetProxy(&tracing_service_provider_ptr)); |
| 289 application_manager_.ConnectToApplication( | 290 application_manager_.ConnectToApplication( |
| 290 GURL("mojo:tracing"), GURL(""), nullptr, | 291 GURL("mojo:tracing"), GURL(""), nullptr, |
| 291 tracing_service_provider_ptr.Pass(), base::Closure()); | 292 tracing_service_provider_ptr.Pass(), base::Closure()); |
| 292 | 293 |
| 293 return true; | 294 return true; |
| 294 } | 295 } |
| 295 | 296 |
| 296 void Context::Shutdown() { | 297 void Context::Shutdown() { |
| 297 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); | 298 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); |
| 298 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 299 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 299 task_runners_->shell_runner()); | 300 task_runners_->shell_runner()); |
| 300 embedder::ShutdownIPCSupport(); | 301 mojo::embedder::ShutdownIPCSupport(); |
| 301 // We'll quit when we get OnShutdownComplete(). | 302 // We'll quit when we get OnShutdownComplete(). |
| 302 base::MessageLoop::current()->Run(); | 303 base::MessageLoop::current()->Run(); |
| 303 } | 304 } |
| 304 | 305 |
| 305 GURL Context::ResolveURL(const GURL& url) { | 306 GURL Context::ResolveURL(const GURL& url) { |
| 306 return url_resolver_.ResolveMojoURL(url); | 307 return url_resolver_.ResolveMojoURL(url); |
| 307 } | 308 } |
| 308 | 309 |
| 309 GURL Context::ResolveMappings(const GURL& url) { | 310 GURL Context::ResolveMappings(const GURL& url) { |
| 310 return url_resolver_.ApplyMappings(url); | 311 return url_resolver_.ApplyMappings(url); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void Context::OnShutdownComplete() { | 314 void Context::OnShutdownComplete() { |
| 314 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 315 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 315 task_runners_->shell_runner()); | 316 task_runners_->shell_runner()); |
| 316 base::MessageLoop::current()->Quit(); | 317 base::MessageLoop::current()->Quit(); |
| 317 } | 318 } |
| 318 | 319 |
| 319 void Context::Run(const GURL& url) { | 320 void Context::Run(const GURL& url) { |
| 320 ServiceProviderPtr services; | 321 mojo::ServiceProviderPtr services; |
| 321 ServiceProviderPtr exposed_services; | 322 mojo::ServiceProviderPtr exposed_services; |
| 322 | 323 |
| 323 app_urls_.insert(url); | 324 app_urls_.insert(url); |
| 324 application_manager_.ConnectToApplication( | 325 application_manager_.ConnectToApplication( |
| 325 url, GURL(), GetProxy(&services), exposed_services.Pass(), | 326 url, GURL(), mojo::GetProxy(&services), exposed_services.Pass(), |
| 326 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | 327 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); |
| 327 } | 328 } |
| 328 | 329 |
| 329 void Context::OnApplicationEnd(const GURL& url) { | 330 void Context::OnApplicationEnd(const GURL& url) { |
| 330 if (app_urls_.find(url) != app_urls_.end()) { | 331 if (app_urls_.find(url) != app_urls_.end()) { |
| 331 app_urls_.erase(url); | 332 app_urls_.erase(url); |
| 332 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | 333 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
| 333 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 334 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 334 task_runners_->shell_runner()); | 335 task_runners_->shell_runner()); |
| 335 base::MessageLoop::current()->Quit(); | 336 base::MessageLoop::current()->Quit(); |
| 336 } | 337 } |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 } // namespace shell | 341 } // namespace shell |
| 341 } // namespace mojo | |
| OLD | NEW |