| 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 "mojo/runner/context.h" | 5 #include "mojo/runner/context.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "components/devtools_service/public/cpp/switches.h" | 23 #include "components/devtools_service/public/cpp/switches.h" |
| 24 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" | 24 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h
" |
| 25 #include "mojo/application/public/cpp/application_connection.h" | 25 #include "mojo/application/public/cpp/application_connection.h" |
| 26 #include "mojo/application/public/cpp/application_delegate.h" | 26 #include "mojo/application/public/cpp/application_delegate.h" |
| 27 #include "mojo/application/public/cpp/application_impl.h" | 27 #include "mojo/application/public/cpp/application_impl.h" |
| 28 #include "mojo/common/trace_controller_impl.h" | 28 #include "mojo/common/trace_controller_impl.h" |
| 29 #include "mojo/common/tracing_impl.h" | 29 #include "mojo/common/tracing_impl.h" |
| 30 #include "mojo/edk/embedder/embedder.h" | 30 #include "mojo/edk/embedder/embedder.h" |
| 31 #include "mojo/edk/embedder/simple_platform_support.h" | 31 #include "mojo/edk/embedder/simple_platform_support.h" |
| 32 #include "mojo/fetcher/base_application_fetcher.h" | 32 #include "mojo/package_manager/package_manager_impl.h" |
| 33 #include "mojo/runner/in_process_native_runner.h" | 33 #include "mojo/runner/in_process_native_runner.h" |
| 34 #include "mojo/runner/out_of_process_native_runner.h" | 34 #include "mojo/runner/out_of_process_native_runner.h" |
| 35 #include "mojo/runner/switches.h" | 35 #include "mojo/runner/switches.h" |
| 36 #include "mojo/services/tracing/public/cpp/switches.h" | 36 #include "mojo/services/tracing/public/cpp/switches.h" |
| 37 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" | 37 #include "mojo/services/tracing/public/interfaces/tracing.mojom.h" |
| 38 #include "mojo/shell/application_loader.h" | 38 #include "mojo/shell/application_loader.h" |
| 39 #include "mojo/shell/connect_to_application_params.h" | 39 #include "mojo/shell/connect_to_application_params.h" |
| 40 #include "mojo/shell/query_util.h" | 40 #include "mojo/shell/query_util.h" |
| 41 #include "mojo/shell/switches.h" | 41 #include "mojo/shell/switches.h" |
| 42 #include "mojo/util/filename_util.h" | 42 #include "mojo/util/filename_util.h" |
| 43 #include "url/gurl.h" | 43 #include "url/gurl.h" |
| 44 | 44 |
| 45 namespace mojo { | 45 namespace mojo { |
| 46 namespace runner { | 46 namespace runner { |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // Used to ensure we only init once. | 49 // Used to ensure we only init once. |
| 50 class Setup { | 50 class Setup { |
| 51 public: | 51 public: |
| 52 Setup() { | 52 Setup() { |
| 53 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); | 53 embedder::Init(make_scoped_ptr(new embedder::SimplePlatformSupport())); |
| 54 } | 54 } |
| 55 | 55 |
| 56 ~Setup() {} | 56 ~Setup() {} |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(Setup); | 59 DISALLOW_COPY_AND_ASSIGN(Setup); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 void InitContentHandlers(shell::ApplicationManager* manager, | 62 void InitContentHandlers(package_manager::PackageManagerImpl* manager, |
| 63 const base::CommandLine& command_line) { | 63 const base::CommandLine& command_line) { |
| 64 // Default content handlers. | 64 // Default content handlers. |
| 65 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); | 65 manager->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); |
| 66 manager->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); | 66 manager->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); |
| 67 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); | 67 manager->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); |
| 68 manager->RegisterContentHandler("text/plain", GURL("mojo:html_viewer")); | 68 manager->RegisterContentHandler("text/plain", GURL("mojo:html_viewer")); |
| 69 | 69 |
| 70 // Command-line-specified content handlers. | 70 // Command-line-specified content handlers. |
| 71 std::string handlers_spec = | 71 std::string handlers_spec = |
| 72 command_line.GetSwitchValueASCII(switches::kContentHandlers); | 72 command_line.GetSwitchValueASCII(switches::kContentHandlers); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 StrongBinding<ServiceProvider> binding_; | 157 StrongBinding<ServiceProvider> binding_; |
| 158 | 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider); | 159 DISALLOW_COPY_AND_ASSIGN(TracingServiceProvider); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 } // namespace | 162 } // namespace |
| 163 | 163 |
| 164 Context::Context(const base::FilePath& shell_file_root) | 164 Context::Context(const base::FilePath& shell_file_root) |
| 165 : application_manager_(new shell::ApplicationManager(make_scoped_ptr( | 165 : shell_file_root_(shell_file_root), main_entry_time_(base::Time::Now()) {} |
| 166 new fetcher::BaseApplicationFetcher(shell_file_root)))), | |
| 167 main_entry_time_(base::Time::Now()) {} | |
| 168 | 166 |
| 169 Context::~Context() { | 167 Context::~Context() { |
| 170 DCHECK(!base::MessageLoop::current()); | 168 DCHECK(!base::MessageLoop::current()); |
| 171 } | 169 } |
| 172 | 170 |
| 173 // static | 171 // static |
| 174 void Context::EnsureEmbedderIsInitialized() { | 172 void Context::EnsureEmbedderIsInitialized() { |
| 175 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; | 173 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; |
| 176 setup.Get(); | 174 setup.Get(); |
| 177 } | 175 } |
| 178 | 176 |
| 179 bool Context::Init() { | 177 bool Context::Init() { |
| 180 TRACE_EVENT0("mojo_shell", "Context::Init"); | 178 TRACE_EVENT0("mojo_shell", "Context::Init"); |
| 181 const base::CommandLine& command_line = | 179 const base::CommandLine& command_line = |
| 182 *base::CommandLine::ForCurrentProcess(); | 180 *base::CommandLine::ForCurrentProcess(); |
| 183 | 181 |
| 184 EnsureEmbedderIsInitialized(); | 182 EnsureEmbedderIsInitialized(); |
| 185 task_runners_.reset( | 183 task_runners_.reset( |
| 186 new TaskRunners(base::MessageLoop::current()->task_runner())); | 184 new TaskRunners(base::MessageLoop::current()->task_runner())); |
| 187 | 185 |
| 188 // TODO(vtl): This should be MASTER, not NONE. | 186 // TODO(vtl): This should be MASTER, not NONE. |
| 189 embedder::InitIPCSupport( | 187 embedder::InitIPCSupport( |
| 190 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, | 188 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, |
| 191 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); | 189 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); |
| 192 | 190 |
| 191 package_manager_ = new package_manager::PackageManagerImpl(shell_file_root_); |
| 192 InitContentHandlers(package_manager_, command_line); |
| 193 |
| 194 application_manager_.reset( |
| 195 new shell::ApplicationManager(make_scoped_ptr(package_manager_))); |
| 196 |
| 193 scoped_ptr<shell::NativeRunnerFactory> runner_factory; | 197 scoped_ptr<shell::NativeRunnerFactory> runner_factory; |
| 194 if (command_line.HasSwitch(switches::kEnableMultiprocess)) | 198 if (command_line.HasSwitch(switches::kEnableMultiprocess)) |
| 195 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); | 199 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); |
| 196 else | 200 else |
| 197 runner_factory.reset(new InProcessNativeRunnerFactory(this)); | 201 runner_factory.reset(new InProcessNativeRunnerFactory(this)); |
| 198 application_manager_->set_blocking_pool(task_runners_->blocking_pool()); | 202 application_manager_->set_blocking_pool(task_runners_->blocking_pool()); |
| 199 application_manager_->set_native_runner_factory(runner_factory.Pass()); | 203 application_manager_->set_native_runner_factory(runner_factory.Pass()); |
| 200 | 204 |
| 201 InitContentHandlers(application_manager_.get(), command_line); | |
| 202 | |
| 203 ServiceProviderPtr service_provider_ptr; | 205 ServiceProviderPtr service_provider_ptr; |
| 204 ServiceProviderPtr tracing_service_provider_ptr; | 206 ServiceProviderPtr tracing_service_provider_ptr; |
| 205 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); | 207 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); |
| 206 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 208 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
| 207 request->url = mojo::String::From("mojo:tracing"); | 209 request->url = mojo::String::From("mojo:tracing"); |
| 208 application_manager_->ConnectToApplication( | 210 application_manager_->ConnectToApplication( |
| 209 nullptr, request.Pass(), std::string(), GetProxy(&service_provider_ptr), | 211 nullptr, request.Pass(), std::string(), GetProxy(&service_provider_ptr), |
| 210 tracing_service_provider_ptr.Pass(), | 212 tracing_service_provider_ptr.Pass(), |
| 211 shell::GetPermissiveCapabilityFilter(), base::Closure(), | 213 shell::GetPermissiveCapabilityFilter(), base::Closure(), |
| 212 shell::EmptyConnectCallback()); | 214 shell::EmptyConnectCallback()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 base::MessageLoop::current()->Quit(); | 293 base::MessageLoop::current()->Quit(); |
| 292 } else { | 294 } else { |
| 293 app_complete_callback_.Run(); | 295 app_complete_callback_.Run(); |
| 294 } | 296 } |
| 295 } | 297 } |
| 296 } | 298 } |
| 297 } | 299 } |
| 298 | 300 |
| 299 } // namespace runner | 301 } // namespace runner |
| 300 } // namespace mojo | 302 } // namespace mojo |
| OLD | NEW |