| 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 using mojo::ServiceProvider; |
| 42 using mojo::ServiceProviderPtr; |
| 43 |
| 41 namespace shell { | 44 namespace shell { |
| 42 namespace { | 45 namespace { |
| 43 | 46 |
| 44 // Used to ensure we only init once. | 47 // Used to ensure we only init once. |
| 45 class Setup { | 48 class Setup { |
| 46 public: | 49 public: |
| 47 Setup() { | 50 Setup() { |
| 48 mojo::embedder::Init( | 51 mojo::embedder::Init( |
| 49 make_scoped_ptr(new mojo::embedder::SimplePlatformSupport())); | 52 make_scoped_ptr(new mojo::embedder::SimplePlatformSupport())); |
| 50 } | 53 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 << ": '" << force_in_process_url << "'is not a valid URL."; | 167 << ": '" << force_in_process_url << "'is not a valid URL."; |
| 165 return; | 168 return; |
| 166 } | 169 } |
| 167 | 170 |
| 168 NativeRunnerFactory::Options options; | 171 NativeRunnerFactory::Options options; |
| 169 options.force_in_process = true; | 172 options.force_in_process = true; |
| 170 manager->SetNativeOptionsForURL(options, gurl); | 173 manager->SetNativeOptionsForURL(options, gurl); |
| 171 } | 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 class TracingServiceProvider : public mojo::ServiceProvider { | 177 class TracingServiceProvider : public ServiceProvider { |
| 175 public: | 178 public: |
| 176 explicit TracingServiceProvider( | 179 explicit TracingServiceProvider( |
| 177 mojo::InterfaceRequest<mojo::ServiceProvider> request) | 180 mojo::InterfaceRequest<ServiceProvider> request) |
| 178 : binding_(this, request.Pass()) {} | 181 : binding_(this, request.Pass()) {} |
| 179 ~TracingServiceProvider() override {} | 182 ~TracingServiceProvider() override {} |
| 180 | 183 |
| 181 void ConnectToService(const mojo::String& service_name, | 184 void ConnectToService(const mojo::String& service_name, |
| 182 mojo::ScopedMessagePipeHandle client_handle) override { | 185 mojo::ScopedMessagePipeHandle client_handle) override { |
| 183 if (service_name == tracing::TraceController::Name_) { | 186 if (service_name == tracing::TraceController::Name_) { |
| 184 new mojo::TraceControllerImpl( | 187 new mojo::TraceControllerImpl( |
| 185 mojo::MakeRequest<tracing::TraceController>(client_handle.Pass())); | 188 mojo::MakeRequest<tracing::TraceController>(client_handle.Pass())); |
| 186 } | 189 } |
| 187 } | 190 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 runner_factory.reset(new InProcessNativeRunnerFactory(this)); | 281 runner_factory.reset(new InProcessNativeRunnerFactory(this)); |
| 279 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); | 282 application_manager_.set_blocking_pool(task_runners_->blocking_pool()); |
| 280 application_manager_.set_native_runner_factory(runner_factory.Pass()); | 283 application_manager_.set_native_runner_factory(runner_factory.Pass()); |
| 281 application_manager_.set_disable_cache( | 284 application_manager_.set_disable_cache( |
| 282 base::CommandLine::ForCurrentProcess()->HasSwitch( | 285 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 283 switches::kDisableCache)); | 286 switches::kDisableCache)); |
| 284 | 287 |
| 285 InitContentHandlers(&application_manager_, command_line); | 288 InitContentHandlers(&application_manager_, command_line); |
| 286 InitNativeOptions(&application_manager_, command_line); | 289 InitNativeOptions(&application_manager_, command_line); |
| 287 | 290 |
| 288 mojo::ServiceProviderPtr tracing_service_provider_ptr; | 291 ServiceProviderPtr tracing_service_provider_ptr; |
| 289 new TracingServiceProvider(mojo::GetProxy(&tracing_service_provider_ptr)); | 292 new TracingServiceProvider(mojo::GetProxy(&tracing_service_provider_ptr)); |
| 290 application_manager_.ConnectToApplication( | 293 application_manager_.ConnectToApplication( |
| 291 GURL("mojo:tracing"), GURL(""), nullptr, | 294 GURL("mojo:tracing"), GURL(""), nullptr, |
| 292 tracing_service_provider_ptr.Pass(), base::Closure()); | 295 tracing_service_provider_ptr.Pass(), base::Closure()); |
| 293 | 296 |
| 294 return true; | 297 return true; |
| 295 } | 298 } |
| 296 | 299 |
| 297 void Context::Shutdown() { | 300 void Context::Shutdown() { |
| 298 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); | 301 TRACE_EVENT0("mojo_shell", "Context::Shutdown"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 311 return url_resolver_.ApplyMappings(url); | 314 return url_resolver_.ApplyMappings(url); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void Context::OnShutdownComplete() { | 317 void Context::OnShutdownComplete() { |
| 315 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 318 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 316 task_runners_->shell_runner()); | 319 task_runners_->shell_runner()); |
| 317 base::MessageLoop::current()->Quit(); | 320 base::MessageLoop::current()->Quit(); |
| 318 } | 321 } |
| 319 | 322 |
| 320 void Context::Run(const GURL& url) { | 323 void Context::Run(const GURL& url) { |
| 321 mojo::ServiceProviderPtr services; | 324 ServiceProviderPtr services; |
| 322 mojo::ServiceProviderPtr exposed_services; | 325 ServiceProviderPtr exposed_services; |
| 323 | 326 |
| 324 app_urls_.insert(url); | 327 app_urls_.insert(url); |
| 325 application_manager_.ConnectToApplication( | 328 application_manager_.ConnectToApplication( |
| 326 url, GURL(), mojo::GetProxy(&services), exposed_services.Pass(), | 329 url, GURL(), mojo::GetProxy(&services), exposed_services.Pass(), |
| 327 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); | 330 base::Bind(&Context::OnApplicationEnd, base::Unretained(this), url)); |
| 328 } | 331 } |
| 329 | 332 |
| 330 void Context::OnApplicationEnd(const GURL& url) { | 333 void Context::OnApplicationEnd(const GURL& url) { |
| 331 if (app_urls_.find(url) != app_urls_.end()) { | 334 if (app_urls_.find(url) != app_urls_.end()) { |
| 332 app_urls_.erase(url); | 335 app_urls_.erase(url); |
| 333 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { | 336 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) { |
| 334 DCHECK_EQ(base::MessageLoop::current()->task_runner(), | 337 DCHECK_EQ(base::MessageLoop::current()->task_runner(), |
| 335 task_runners_->shell_runner()); | 338 task_runners_->shell_runner()); |
| 336 base::MessageLoop::current()->Quit(); | 339 base::MessageLoop::current()->Quit(); |
| 337 } | 340 } |
| 338 } | 341 } |
| 339 } | 342 } |
| 340 | 343 |
| 341 } // namespace shell | 344 } // namespace shell |
| OLD | NEW |