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

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: blech 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_shell_service_loader.h" 17 #include "mojo/service_manager/background_shell_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 DCHECK(!base::MessageLoop::current()); 119 DCHECK(!base::MessageLoop::current());
88 } 120 }
89 121
90 void Context::Init() { 122 void Context::Init() {
91 setup.Get(); 123 setup.Get();
92 task_runners_.reset( 124 task_runners_.reset(
93 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); 125 new TaskRunners(base::MessageLoop::current()->message_loop_proxy()));
94 126
95 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) 127 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i)
96 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); 128 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i]));
97 129
98 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); 130 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
99 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; 131 scoped_ptr<DynamicServiceRunnerFactory> runner_factory;
100 if (cmdline->HasSwitch(switches::kEnableMultiprocess)) 132 if (command_line->HasSwitch(switches::kEnableMultiprocess))
101 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); 133 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
102 else 134 else
103 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); 135 runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
104 136
137 DynamicServiceLoader* dynamic_service_loader =
138 new DynamicServiceLoader(this, runner_factory.Pass());
139 InitContentHandlers(dynamic_service_loader, command_line);
105 service_manager_.set_default_loader( 140 service_manager_.set_default_loader(
106 scoped_ptr<ServiceLoader>( 141 scoped_ptr<ServiceLoader>(dynamic_service_loader));
107 new DynamicServiceLoader(this, runner_factory.Pass()))); 142
108 // The native viewport service synchronously waits for certain messages. If we 143 // The native viewport service synchronously waits for certain messages. If we
109 // don't run it on its own thread we can easily deadlock. Long term native 144 // don't run it on its own thread we can easily deadlock. Long term native
110 // viewport should run its own process so that this isn't an issue. 145 // viewport should run its own process so that this isn't an issue.
111 #if defined(OS_ANDROID) 146 #if defined(OS_ANDROID)
112 service_manager_.SetLoaderForURL( 147 service_manager_.SetLoaderForURL(
113 scoped_ptr<ServiceLoader>( 148 scoped_ptr<ServiceLoader>(
114 new UIServiceLoader( 149 new UIServiceLoader(
115 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), 150 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
116 this)), 151 this)),
117 GURL("mojo:mojo_native_viewport_service")); 152 GURL("mojo:mojo_native_viewport_service"));
(...skipping 17 matching lines...) Expand all
135 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), 170 scoped_ptr<ServiceLoader>(new ViewManagerLoader()),
136 GURL("mojo:mojo_view_manager")); 171 GURL("mojo:mojo_view_manager"));
137 #endif 172 #endif
138 173
139 #if defined(OS_LINUX) 174 #if defined(OS_LINUX)
140 service_manager_.SetLoaderForScheme( 175 service_manager_.SetLoaderForScheme(
141 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)), 176 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)),
142 "dbus"); 177 "dbus");
143 #endif // defined(OS_LINUX) 178 #endif // defined(OS_LINUX)
144 179
145 if (cmdline->HasSwitch(switches::kSpy)) { 180 if (command_line->HasSwitch(switches::kSpy)) {
146 spy_.reset(new mojo::Spy(&service_manager_, 181 spy_.reset(new mojo::Spy(
147 cmdline->GetSwitchValueASCII(switches::kSpy))); 182 &service_manager_, command_line->GetSwitchValueASCII(switches::kSpy)));
148 } 183 }
149 184
150 #if defined(OS_ANDROID) 185 #if defined(OS_ANDROID)
151 // On android, the network service is bundled with the shell because the 186 // On android, the network service is bundled with the shell because the
152 // network stack depends on the android runtime. 187 // network stack depends on the android runtime.
153 { 188 {
154 scoped_ptr<BackgroundShellServiceLoader> loader( 189 scoped_ptr<BackgroundShellServiceLoader> loader(
155 new BackgroundShellServiceLoader( 190 new BackgroundShellServiceLoader(
156 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()), 191 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()),
157 "network_service", 192 "network_service",
(...skipping 19 matching lines...) Expand all
177 service_manager_.TerminateShellConnections(); 212 service_manager_.TerminateShellConnections();
178 } 213 }
179 214
180 Context::~Context() { 215 Context::~Context() {
181 DCHECK(!base::MessageLoop::current()); 216 DCHECK(!base::MessageLoop::current());
182 Shutdown(); 217 Shutdown();
183 } 218 }
184 219
185 } // namespace shell 220 } // namespace shell
186 } // namespace mojo 221 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698