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

Side by Side Diff: mojo/shell/context.cc

Issue 423963004: First cut at "content handling" support in Mojo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Dave's comments, plus added a --content-handlers switch Created 6 years, 4 months 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 | Annotate | Revision Log
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 "mojo/shell/context.h"
6 6
7 #include <vector>
8
7 #include "build/build_config.h" 9 #include "build/build_config.h"
8 #include "base/command_line.h" 10 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string_split.h"
11 #include "mojo/embedder/embedder.h" 14 #include "mojo/embedder/embedder.h"
12 #include "mojo/gles2/gles2_support_impl.h" 15 #include "mojo/gles2/gles2_support_impl.h"
13 #include "mojo/public/cpp/application/application_impl.h" 16 #include "mojo/public/cpp/application/application_impl.h"
14 #include "mojo/service_manager/background_service_loader.h" 17 #include "mojo/service_manager/background_service_loader.h"
15 #include "mojo/service_manager/service_loader.h" 18 #include "mojo/service_manager/service_loader.h"
16 #include "mojo/service_manager/service_manager.h" 19 #include "mojo/service_manager/service_manager.h"
17 #include "mojo/services/native_viewport/native_viewport_service.h" 20 #include "mojo/services/native_viewport/native_viewport_service.h"
18 #include "mojo/shell/dynamic_service_loader.h" 21 #include "mojo/shell/dynamic_service_loader.h"
19 #include "mojo/shell/in_process_dynamic_service_runner.h" 22 #include "mojo/shell/in_process_dynamic_service_runner.h"
20 #include "mojo/shell/out_of_process_dynamic_service_runner.h" 23 #include "mojo/shell/out_of_process_dynamic_service_runner.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 57
55 ~Setup() { 58 ~Setup() {
56 } 59 }
57 60
58 private: 61 private:
59 DISALLOW_COPY_AND_ASSIGN(Setup); 62 DISALLOW_COPY_AND_ASSIGN(Setup);
60 }; 63 };
61 64
62 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; 65 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
63 66
67 void InitContentHandlers(DynamicServiceLoader* loader,
68 base::CommandLine* command_line) {
69 std::string handlers_spec = command_line->GetSwitchValueASCII(
70 switches::kContentHandlers);
71 if (handlers_spec.empty())
72 return;
73
74 std::vector<std::string> parts;
75 base::SplitString(handlers_spec, ',', &parts);
76 if (parts.size() % 2 != 0) {
77 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
78 << ": must be a comma-separated list of mimetype/url pairs.";
79 return;
80 }
81
82 for (size_t i = 0; i < parts.size(); i += 2) {
83 GURL url(parts[i + 1]);
84 if (!url.is_valid()) {
85 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers
86 << ": '" << parts[i + 1] << "' is not a valid URL.";
87 return;
88 }
89 loader->set_content_handler(parts[i], url);
90 }
91 }
92
64 } // namespace 93 } // namespace
65 94
66 class Context::NativeViewportServiceLoader : public ServiceLoader { 95 class Context::NativeViewportServiceLoader : public ServiceLoader {
67 public: 96 public:
68 NativeViewportServiceLoader() {} 97 NativeViewportServiceLoader() {}
69 virtual ~NativeViewportServiceLoader() {} 98 virtual ~NativeViewportServiceLoader() {}
70 99
71 private: 100 private:
72 virtual void LoadService(ServiceManager* manager, 101 virtual void LoadService(
73 const GURL& url, 102 ServiceManager* manager,
74 ScopedMessagePipeHandle shell_handle) OVERRIDE { 103 const GURL& url,
75 app_.reset(services::CreateNativeViewportService(shell_handle.Pass())); 104 scoped_refptr<LoadServiceCallbacks> callbacks) OVERRIDE {
105 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
106 if (shell_handle.is_valid())
107 app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
76 } 108 }
77 109
78 virtual void OnServiceError(ServiceManager* manager, 110 virtual void OnServiceError(ServiceManager* manager,
79 const GURL& url) OVERRIDE { 111 const GURL& url) OVERRIDE {
80 } 112 }
81 113
82 scoped_ptr<ApplicationImpl> app_; 114 scoped_ptr<ApplicationImpl> app_;
83 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); 115 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader);
84 }; 116 };
85 117
86 Context::Context() 118 Context::Context()
87 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) { 119 : task_runners_(base::MessageLoop::current()->message_loop_proxy()) {
88 setup.Get(); 120 setup.Get();
89 121
90 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) 122 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i)
91 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); 123 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i]));
92 124
93 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 125 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
94 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; 126 scoped_ptr<DynamicServiceRunnerFactory> runner_factory;
95 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) 127 if (command_line->HasSwitch(switches::kEnableMultiprocess))
96 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); 128 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
97 else 129 else
98 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); 130 runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
99 131
132 DynamicServiceLoader* dynamic_service_loader =
133 new DynamicServiceLoader(this, runner_factory.Pass());
134 InitContentHandlers(dynamic_service_loader, command_line);
100 service_manager_.set_default_loader( 135 service_manager_.set_default_loader(
101 scoped_ptr<ServiceLoader>( 136 scoped_ptr<ServiceLoader>(dynamic_service_loader));
102 new DynamicServiceLoader(this, runner_factory.Pass()))); 137
103 // The native viewport service synchronously waits for certain messages. If we 138 // The native viewport service synchronously waits for certain messages. If we
104 // don't run it on its own thread we can easily deadlock. Long term native 139 // don't run it on its own thread we can easily deadlock. Long term native
105 // viewport should run its own process so that this isn't an issue. 140 // viewport should run its own process so that this isn't an issue.
106 #if defined(OS_ANDROID) 141 #if defined(OS_ANDROID)
107 service_manager_.SetLoaderForURL( 142 service_manager_.SetLoaderForURL(
108 scoped_ptr<ServiceLoader>( 143 scoped_ptr<ServiceLoader>(
109 new UIServiceLoader( 144 new UIServiceLoader(
110 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), 145 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
111 this)), 146 this)),
112 GURL("mojo:mojo_native_viewport_service")); 147 GURL("mojo:mojo_native_viewport_service"));
(...skipping 12 matching lines...) Expand all
125 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), 160 scoped_ptr<ServiceLoader>(new ViewManagerLoader()),
126 GURL("mojo:mojo_view_manager")); 161 GURL("mojo:mojo_view_manager"));
127 #endif 162 #endif
128 163
129 #if defined(OS_LINUX) 164 #if defined(OS_LINUX)
130 service_manager_.SetLoaderForScheme( 165 service_manager_.SetLoaderForScheme(
131 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)), 166 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)),
132 "dbus"); 167 "dbus");
133 #endif // defined(OS_LINUX) 168 #endif // defined(OS_LINUX)
134 169
135 if (cmdline->HasSwitch(switches::kSpy)) { 170 if (command_line->HasSwitch(switches::kSpy)) {
136 spy_.reset(new mojo::Spy(&service_manager_, 171 spy_.reset(new mojo::Spy(
137 cmdline->GetSwitchValueASCII(switches::kSpy))); 172 &service_manager_, command_line->GetSwitchValueASCII(switches::kSpy)));
138 } 173 }
139 174
140 #if defined(OS_ANDROID) 175 #if defined(OS_ANDROID)
141 // On android, the network service is bundled with the shell because the 176 // On android, the network service is bundled with the shell because the
142 // network stack depends on the android runtime. 177 // network stack depends on the android runtime.
143 service_manager_.SetLoaderForURL( 178 service_manager_.SetLoaderForURL(
144 scoped_ptr<ServiceLoader>( 179 scoped_ptr<ServiceLoader>(
145 new BackgroundServiceLoader( 180 new BackgroundServiceLoader(
146 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()), 181 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()),
147 "network_service", 182 "network_service",
(...skipping 14 matching lines...) Expand all
162 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>()); 197 service_manager_.set_default_loader(scoped_ptr<ServiceLoader>());
163 service_manager_.TerminateShellConnections(); 198 service_manager_.TerminateShellConnections();
164 } 199 }
165 200
166 Context::~Context() { 201 Context::~Context() {
167 Shutdown(); 202 Shutdown();
168 } 203 }
169 204
170 } // namespace shell 205 } // namespace shell
171 } // namespace mojo 206 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698