Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: shell/context.cc

Issue 775343004: Move //mojo/shell to //shell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « shell/context.h ('k') | shell/data_pipe_peek.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell/context.h" 5 #include "shell/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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/strings/string_split.h" 16 #include "base/strings/string_split.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "mojo/application_manager/application_loader.h" 18 #include "mojo/application_manager/application_loader.h"
19 #include "mojo/application_manager/application_manager.h" 19 #include "mojo/application_manager/application_manager.h"
20 #include "mojo/application_manager/background_shell_application_loader.h" 20 #include "mojo/application_manager/background_shell_application_loader.h"
21 #include "mojo/common/tracing_impl.h" 21 #include "mojo/common/tracing_impl.h"
22 #include "mojo/edk/embedder/embedder.h" 22 #include "mojo/edk/embedder/embedder.h"
23 #include "mojo/edk/embedder/simple_platform_support.h" 23 #include "mojo/edk/embedder/simple_platform_support.h"
24 #include "mojo/public/cpp/application/application_connection.h" 24 #include "mojo/public/cpp/application/application_connection.h"
25 #include "mojo/public/cpp/application/application_delegate.h" 25 #include "mojo/public/cpp/application/application_delegate.h"
26 #include "mojo/public/cpp/application/application_impl.h" 26 #include "mojo/public/cpp/application/application_impl.h"
27 #include "mojo/shell/dynamic_application_loader.h"
28 #include "mojo/shell/external_application_listener.h"
29 #include "mojo/shell/in_process_dynamic_service_runner.h"
30 #include "mojo/shell/out_of_process_dynamic_service_runner.h"
31 #include "mojo/shell/switches.h"
32 #include "mojo/shell/ui_application_loader_android.h"
33 #include "mojo/spy/spy.h" 27 #include "mojo/spy/spy.h"
34 #include "services/tracing/tracing.mojom.h" 28 #include "services/tracing/tracing.mojom.h"
29 #include "shell/dynamic_application_loader.h"
30 #include "shell/external_application_listener.h"
31 #include "shell/in_process_dynamic_service_runner.h"
32 #include "shell/out_of_process_dynamic_service_runner.h"
33 #include "shell/switches.h"
34 #include "shell/ui_application_loader_android.h"
35 #include "url/gurl.h" 35 #include "url/gurl.h"
36 36
37 #if defined(OS_ANDROID) 37 #if defined(OS_ANDROID)
38 #include "mojo/shell/android/android_handler_loader.h"
39 #include "mojo/shell/network_application_loader.h"
40 #include "services/gles2/gpu_impl.h" 38 #include "services/gles2/gpu_impl.h"
41 #include "services/native_viewport/native_viewport_impl.h" 39 #include "services/native_viewport/native_viewport_impl.h"
40 #include "shell/android/android_handler_loader.h"
41 #include "shell/network_application_loader.h"
42 #endif // defined(OS_ANDROID) 42 #endif // defined(OS_ANDROID)
43 43
44 namespace mojo { 44 namespace mojo {
45 namespace shell { 45 namespace shell {
46 namespace { 46 namespace {
47 47
48 // These mojo: URLs are loaded directly from the local filesystem. They 48 // These mojo: URLs are loaded directly from the local filesystem. They
49 // correspond to shared libraries bundled alongside the mojo_shell. 49 // correspond to shared libraries bundled alongside the mojo_shell.
50 const char* kLocalMojoURLs[] = { 50 const char* kLocalMojoURLs[] = {
51 "mojo:network_service", 51 "mojo:network_service",
52 }; 52 };
53 53
54 // Used to ensure we only init once. 54 // Used to ensure we only init once.
55 class Setup { 55 class Setup {
56 public: 56 public:
57 Setup() { 57 Setup() {
58 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( 58 embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>(
59 new mojo::embedder::SimplePlatformSupport())); 59 new mojo::embedder::SimplePlatformSupport()));
60 } 60 }
61 61
62 ~Setup() { 62 ~Setup() {}
63 }
64 63
65 private: 64 private:
66 DISALLOW_COPY_AND_ASSIGN(Setup); 65 DISALLOW_COPY_AND_ASSIGN(Setup);
67 }; 66 };
68 67
69 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; 68 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
70 69
71 void InitContentHandlers(DynamicApplicationLoader* loader, 70 void InitContentHandlers(DynamicApplicationLoader* loader,
72 base::CommandLine* command_line) { 71 base::CommandLine* command_line) {
73 // Default content handlers. 72 // Default content handlers.
74 loader->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer")); 73 loader->RegisterContentHandler("application/pdf", GURL("mojo:pdf_viewer"));
75 loader->RegisterContentHandler("image/png", GURL("mojo:png_viewer")); 74 loader->RegisterContentHandler("image/png", GURL("mojo:png_viewer"));
76 loader->RegisterContentHandler("text/html", GURL("mojo:html_viewer")); 75 loader->RegisterContentHandler("text/html", GURL("mojo:html_viewer"));
77 76
78 // Command-line-specified content handlers. 77 // Command-line-specified content handlers.
79 std::string handlers_spec = command_line->GetSwitchValueASCII( 78 std::string handlers_spec =
80 switches::kContentHandlers); 79 command_line->GetSwitchValueASCII(switches::kContentHandlers);
81 if (handlers_spec.empty()) 80 if (handlers_spec.empty())
82 return; 81 return;
83 82
84 std::vector<std::string> parts; 83 std::vector<std::string> parts;
85 base::SplitString(handlers_spec, ',', &parts); 84 base::SplitString(handlers_spec, ',', &parts);
86 if (parts.size() % 2 != 0) { 85 if (parts.size() % 2 != 0) {
87 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers 86 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
88 << ": must be a comma-separated list of mimetype/url pairs."; 87 << ": must be a comma-separated list of mimetype/url pairs.";
89 return; 88 return;
90 } 89 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); 224 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
226 else 225 else
227 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); 226 runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
228 227
229 DynamicApplicationLoader* dynamic_application_loader = 228 DynamicApplicationLoader* dynamic_application_loader =
230 new DynamicApplicationLoader(this, runner_factory.Pass()); 229 new DynamicApplicationLoader(this, runner_factory.Pass());
231 InitContentHandlers(dynamic_application_loader, command_line); 230 InitContentHandlers(dynamic_application_loader, command_line);
232 application_manager_.set_default_loader( 231 application_manager_.set_default_loader(
233 scoped_ptr<ApplicationLoader>(dynamic_application_loader)); 232 scoped_ptr<ApplicationLoader>(dynamic_application_loader));
234 233
235 // The native viewport service synchronously waits for certain messages. If we 234 // The native viewport service synchronously waits for certain messages. If we
236 // don't run it on its own thread we can easily deadlock. Long term native 235 // don't run it on its own thread we can easily deadlock. Long term native
237 // viewport should run its own process so that this isn't an issue. 236 // viewport should run its own process so that this isn't an issue.
238 #if defined(OS_ANDROID) 237 #if defined(OS_ANDROID)
239 application_manager_.SetLoaderForURL( 238 application_manager_.SetLoaderForURL(
240 scoped_ptr<ApplicationLoader>(new UIApplicationLoader( 239 scoped_ptr<ApplicationLoader>(new UIApplicationLoader(
241 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()), 240 scoped_ptr<ApplicationLoader>(new NativeViewportApplicationLoader()),
242 this)), 241 this)),
243 GURL("mojo:native_viewport_service")); 242 GURL("mojo:native_viewport_service"));
244 #endif 243 #endif
245 244
246 if (command_line->HasSwitch(switches::kSpy)) { 245 if (command_line->HasSwitch(switches::kSpy)) {
247 spy_.reset( 246 spy_.reset(
248 new mojo::Spy(&application_manager_, 247 new mojo::Spy(&application_manager_,
249 command_line->GetSwitchValueASCII(switches::kSpy))); 248 command_line->GetSwitchValueASCII(switches::kSpy)));
250 // TODO(cpu): the spy can snoop, but can't tell anybody until 249 // TODO(cpu): the spy can snoop, but can't tell anybody until
251 // the Spy::WebSocketDelegate is implemented. In the original repo this 250 // the Spy::WebSocketDelegate is implemented. In the original repo this
252 // was implemented by src\mojo\spy\websocket_server.h and .cc. 251 // was implemented by src\mojo\spy\websocket_server.h and .cc.
253 } 252 }
254 253
255 #if defined(OS_ANDROID) 254 #if defined(OS_ANDROID)
256 // On android, the network service is bundled with the shell because the 255 // On android, the network service is bundled with the shell because the
257 // network stack depends on the android runtime. 256 // network stack depends on the android runtime.
258 { 257 {
259 scoped_ptr<BackgroundShellApplicationLoader> loader( 258 scoped_ptr<BackgroundShellApplicationLoader> loader(
260 new BackgroundShellApplicationLoader( 259 new BackgroundShellApplicationLoader(
261 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()), 260 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()),
262 "network_service", 261 "network_service", base::MessageLoop::TYPE_IO));
263 base::MessageLoop::TYPE_IO));
264 application_manager_.SetLoaderForURL(loader.Pass(), 262 application_manager_.SetLoaderForURL(loader.Pass(),
265 GURL("mojo:network_service")); 263 GURL("mojo:network_service"));
266 } 264 }
267 { 265 {
268 scoped_ptr<BackgroundShellApplicationLoader> loader( 266 scoped_ptr<BackgroundShellApplicationLoader> loader(
269 new BackgroundShellApplicationLoader( 267 new BackgroundShellApplicationLoader(
270 scoped_ptr<ApplicationLoader>(new AndroidHandlerLoader()), 268 scoped_ptr<ApplicationLoader>(new AndroidHandlerLoader()),
271 "android_handler", base::MessageLoop::TYPE_DEFAULT)); 269 "android_handler", base::MessageLoop::TYPE_DEFAULT));
272 application_manager_.SetLoaderForURL(loader.Pass(), 270 application_manager_.SetLoaderForURL(loader.Pass(),
273 GURL("mojo:android_handler")); 271 GURL("mojo:android_handler"));
(...skipping 29 matching lines...) Expand all
303 BindToProxy(sp, &spp); 301 BindToProxy(sp, &spp);
304 302
305 app_urls_.insert(url); 303 app_urls_.insert(url);
306 application_manager_.ConnectToApplication(url, GURL(), spp.Pass()); 304 application_manager_.ConnectToApplication(url, GURL(), spp.Pass());
307 } 305 }
308 306
309 ScopedMessagePipeHandle Context::ConnectToServiceByName( 307 ScopedMessagePipeHandle Context::ConnectToServiceByName(
310 const GURL& application_url, 308 const GURL& application_url,
311 const std::string& service_name) { 309 const std::string& service_name) {
312 app_urls_.insert(application_url); 310 app_urls_.insert(application_url);
313 return application_manager_.ConnectToServiceByName( 311 return application_manager_.ConnectToServiceByName(application_url,
314 application_url, service_name).Pass(); 312 service_name).Pass();
315 } 313 }
316 314
317 } // namespace shell 315 } // namespace shell
318 } // namespace mojo 316 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/context.h ('k') | shell/data_pipe_peek.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698