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/package_manager/package_manager_impl.h" | 32 #include "mojo/fetcher/base_application_fetcher.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(package_manager::PackageManagerImpl* manager, | 62 void InitContentHandlers(shell::ApplicationManager* 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 : shell_file_root_(shell_file_root), main_entry_time_(base::Time::Now()) {} | 165 : application_manager_(new shell::ApplicationManager(make_scoped_ptr( |
| 166 new fetcher::BaseApplicationFetcher(shell_file_root)))), |
| 167 main_entry_time_(base::Time::Now()) {} |
166 | 168 |
167 Context::~Context() { | 169 Context::~Context() { |
168 DCHECK(!base::MessageLoop::current()); | 170 DCHECK(!base::MessageLoop::current()); |
169 } | 171 } |
170 | 172 |
171 // static | 173 // static |
172 void Context::EnsureEmbedderIsInitialized() { | 174 void Context::EnsureEmbedderIsInitialized() { |
173 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; | 175 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; |
174 setup.Get(); | 176 setup.Get(); |
175 } | 177 } |
176 | 178 |
177 bool Context::Init() { | 179 bool Context::Init() { |
178 TRACE_EVENT0("mojo_shell", "Context::Init"); | 180 TRACE_EVENT0("mojo_shell", "Context::Init"); |
179 const base::CommandLine& command_line = | 181 const base::CommandLine& command_line = |
180 *base::CommandLine::ForCurrentProcess(); | 182 *base::CommandLine::ForCurrentProcess(); |
181 | 183 |
182 EnsureEmbedderIsInitialized(); | 184 EnsureEmbedderIsInitialized(); |
183 task_runners_.reset( | 185 task_runners_.reset( |
184 new TaskRunners(base::MessageLoop::current()->task_runner())); | 186 new TaskRunners(base::MessageLoop::current()->task_runner())); |
185 | 187 |
186 // TODO(vtl): This should be MASTER, not NONE. | 188 // TODO(vtl): This should be MASTER, not NONE. |
187 embedder::InitIPCSupport( | 189 embedder::InitIPCSupport( |
188 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, | 190 embedder::ProcessType::NONE, task_runners_->shell_runner(), this, |
189 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); | 191 task_runners_->io_runner(), embedder::ScopedPlatformHandle()); |
190 | 192 |
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 | |
197 scoped_ptr<shell::NativeRunnerFactory> runner_factory; | 193 scoped_ptr<shell::NativeRunnerFactory> runner_factory; |
198 if (command_line.HasSwitch(switches::kEnableMultiprocess)) | 194 if (command_line.HasSwitch(switches::kEnableMultiprocess)) |
199 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); | 195 runner_factory.reset(new OutOfProcessNativeRunnerFactory(this)); |
200 else | 196 else |
201 runner_factory.reset(new InProcessNativeRunnerFactory(this)); | 197 runner_factory.reset(new InProcessNativeRunnerFactory(this)); |
202 application_manager_->set_blocking_pool(task_runners_->blocking_pool()); | 198 application_manager_->set_blocking_pool(task_runners_->blocking_pool()); |
203 application_manager_->set_native_runner_factory(runner_factory.Pass()); | 199 application_manager_->set_native_runner_factory(runner_factory.Pass()); |
204 | 200 |
| 201 InitContentHandlers(application_manager_.get(), command_line); |
| 202 |
205 ServiceProviderPtr service_provider_ptr; | 203 ServiceProviderPtr service_provider_ptr; |
206 ServiceProviderPtr tracing_service_provider_ptr; | 204 ServiceProviderPtr tracing_service_provider_ptr; |
207 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); | 205 new TracingServiceProvider(GetProxy(&tracing_service_provider_ptr)); |
208 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 206 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
209 request->url = mojo::String::From("mojo:tracing"); | 207 request->url = mojo::String::From("mojo:tracing"); |
210 application_manager_->ConnectToApplication( | 208 application_manager_->ConnectToApplication( |
211 nullptr, request.Pass(), std::string(), GetProxy(&service_provider_ptr), | 209 nullptr, request.Pass(), std::string(), GetProxy(&service_provider_ptr), |
212 tracing_service_provider_ptr.Pass(), | 210 tracing_service_provider_ptr.Pass(), |
213 shell::GetPermissiveCapabilityFilter(), base::Closure(), | 211 shell::GetPermissiveCapabilityFilter(), base::Closure(), |
214 shell::EmptyConnectCallback()); | 212 shell::EmptyConnectCallback()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 base::MessageLoop::current()->Quit(); | 291 base::MessageLoop::current()->Quit(); |
294 } else { | 292 } else { |
295 app_complete_callback_.Run(); | 293 app_complete_callback_.Run(); |
296 } | 294 } |
297 } | 295 } |
298 } | 296 } |
299 } | 297 } |
300 | 298 |
301 } // namespace runner | 299 } // namespace runner |
302 } // namespace mojo | 300 } // namespace mojo |
OLD | NEW |