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

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

Issue 447063005: Revert 288013 "First cut at "content handling" support in Mojo." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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
9 #include "build/build_config.h" 7 #include "build/build_config.h"
10 #include "base/command_line.h" 8 #include "base/command_line.h"
11 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
12 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string_split.h"
14 #include "mojo/embedder/embedder.h" 11 #include "mojo/embedder/embedder.h"
15 #include "mojo/gles2/gles2_support_impl.h" 12 #include "mojo/gles2/gles2_support_impl.h"
16 #include "mojo/public/cpp/application/application_impl.h" 13 #include "mojo/public/cpp/application/application_impl.h"
17 #include "mojo/service_manager/background_shell_service_loader.h" 14 #include "mojo/service_manager/background_shell_service_loader.h"
18 #include "mojo/service_manager/service_loader.h" 15 #include "mojo/service_manager/service_loader.h"
19 #include "mojo/service_manager/service_manager.h" 16 #include "mojo/service_manager/service_manager.h"
20 #include "mojo/services/native_viewport/native_viewport_service.h" 17 #include "mojo/services/native_viewport/native_viewport_service.h"
21 #include "mojo/shell/dynamic_service_loader.h" 18 #include "mojo/shell/dynamic_service_loader.h"
22 #include "mojo/shell/in_process_dynamic_service_runner.h" 19 #include "mojo/shell/in_process_dynamic_service_runner.h"
23 #include "mojo/shell/out_of_process_dynamic_service_runner.h" 20 #include "mojo/shell/out_of_process_dynamic_service_runner.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 54
58 ~Setup() { 55 ~Setup() {
59 } 56 }
60 57
61 private: 58 private:
62 DISALLOW_COPY_AND_ASSIGN(Setup); 59 DISALLOW_COPY_AND_ASSIGN(Setup);
63 }; 60 };
64 61
65 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER; 62 static base::LazyInstance<Setup>::Leaky setup = LAZY_INSTANCE_INITIALIZER;
66 63
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->RegisterContentHandler(parts[i], url);
90 }
91 }
92
93 } // namespace 64 } // namespace
94 65
95 class Context::NativeViewportServiceLoader : public ServiceLoader { 66 class Context::NativeViewportServiceLoader : public ServiceLoader {
96 public: 67 public:
97 NativeViewportServiceLoader() {} 68 NativeViewportServiceLoader() {}
98 virtual ~NativeViewportServiceLoader() {} 69 virtual ~NativeViewportServiceLoader() {}
99 70
100 private: 71 private:
101 virtual void Load(ServiceManager* manager, 72 virtual void LoadService(ServiceManager* manager,
102 const GURL& url, 73 const GURL& url,
103 scoped_refptr<LoadCallbacks> callbacks) OVERRIDE { 74 ScopedMessagePipeHandle shell_handle) OVERRIDE {
104 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); 75 app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
105 if (shell_handle.is_valid())
106 app_.reset(services::CreateNativeViewportService(shell_handle.Pass()));
107 } 76 }
108 77
109 virtual void OnServiceError(ServiceManager* manager, 78 virtual void OnServiceError(ServiceManager* manager,
110 const GURL& url) OVERRIDE { 79 const GURL& url) OVERRIDE {
111 } 80 }
112 81
113 scoped_ptr<ApplicationImpl> app_; 82 scoped_ptr<ApplicationImpl> app_;
114 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader); 83 DISALLOW_COPY_AND_ASSIGN(NativeViewportServiceLoader);
115 }; 84 };
116 85
117 Context::Context() { 86 Context::Context() {
118 DCHECK(!base::MessageLoop::current()); 87 DCHECK(!base::MessageLoop::current());
119 } 88 }
120 89
121 void Context::Init() { 90 void Context::Init() {
122 setup.Get(); 91 setup.Get();
123 task_runners_.reset( 92 task_runners_.reset(
124 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); 93 new TaskRunners(base::MessageLoop::current()->message_loop_proxy()));
125 94
126 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) 95 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i)
127 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); 96 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i]));
128 97
129 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 98 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
130 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; 99 scoped_ptr<DynamicServiceRunnerFactory> runner_factory;
131 if (command_line->HasSwitch(switches::kEnableMultiprocess)) 100 if (cmdline->HasSwitch(switches::kEnableMultiprocess))
132 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory()); 101 runner_factory.reset(new OutOfProcessDynamicServiceRunnerFactory());
133 else 102 else
134 runner_factory.reset(new InProcessDynamicServiceRunnerFactory()); 103 runner_factory.reset(new InProcessDynamicServiceRunnerFactory());
135 104
136 DynamicServiceLoader* dynamic_service_loader =
137 new DynamicServiceLoader(this, runner_factory.Pass());
138 InitContentHandlers(dynamic_service_loader, command_line);
139 service_manager_.set_default_loader( 105 service_manager_.set_default_loader(
140 scoped_ptr<ServiceLoader>(dynamic_service_loader)); 106 scoped_ptr<ServiceLoader>(
141 107 new DynamicServiceLoader(this, runner_factory.Pass())));
142 // The native viewport service synchronously waits for certain messages. If we 108 // The native viewport service synchronously waits for certain messages. If we
143 // don't run it on its own thread we can easily deadlock. Long term native 109 // don't run it on its own thread we can easily deadlock. Long term native
144 // viewport should run its own process so that this isn't an issue. 110 // viewport should run its own process so that this isn't an issue.
145 #if defined(OS_ANDROID) 111 #if defined(OS_ANDROID)
146 service_manager_.SetLoaderForURL( 112 service_manager_.SetLoaderForURL(
147 scoped_ptr<ServiceLoader>( 113 scoped_ptr<ServiceLoader>(
148 new UIServiceLoader( 114 new UIServiceLoader(
149 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()), 115 scoped_ptr<ServiceLoader>(new NativeViewportServiceLoader()),
150 this)), 116 this)),
151 GURL("mojo:mojo_native_viewport_service")); 117 GURL("mojo:mojo_native_viewport_service"));
(...skipping 15 matching lines...) Expand all
167 scoped_ptr<ServiceLoader>(new ViewManagerLoader()), 133 scoped_ptr<ServiceLoader>(new ViewManagerLoader()),
168 GURL("mojo:mojo_view_manager")); 134 GURL("mojo:mojo_view_manager"));
169 #endif 135 #endif
170 136
171 #if defined(OS_LINUX) 137 #if defined(OS_LINUX)
172 service_manager_.SetLoaderForScheme( 138 service_manager_.SetLoaderForScheme(
173 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)), 139 scoped_ptr<ServiceLoader>(new DBusServiceLoader(this)),
174 "dbus"); 140 "dbus");
175 #endif // defined(OS_LINUX) 141 #endif // defined(OS_LINUX)
176 142
177 if (command_line->HasSwitch(switches::kSpy)) { 143 if (cmdline->HasSwitch(switches::kSpy)) {
178 spy_.reset(new mojo::Spy( 144 spy_.reset(new mojo::Spy(&service_manager_,
179 &service_manager_, command_line->GetSwitchValueASCII(switches::kSpy))); 145 cmdline->GetSwitchValueASCII(switches::kSpy)));
180 } 146 }
181 147
182 #if defined(OS_ANDROID) 148 #if defined(OS_ANDROID)
183 // On android, the network service is bundled with the shell because the 149 // On android, the network service is bundled with the shell because the
184 // network stack depends on the android runtime. 150 // network stack depends on the android runtime.
185 { 151 {
186 scoped_ptr<BackgroundShellServiceLoader> loader( 152 scoped_ptr<BackgroundShellServiceLoader> loader(
187 new BackgroundShellServiceLoader( 153 new BackgroundShellServiceLoader(
188 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()), 154 scoped_ptr<ServiceLoader>(new NetworkServiceLoader()),
189 "network_service", 155 "network_service",
190 base::MessageLoop::TYPE_IO)); 156 base::MessageLoop::TYPE_IO));
191 service_manager_.SetLoaderForURL(loader.PassAs<ServiceLoader>(), 157 service_manager_.SetLoaderForURL(loader.PassAs<ServiceLoader>(),
192 GURL("mojo:mojo_network_service")); 158 GURL("mojo:mojo_network_service"));
193 } 159 }
194 #endif 160 #endif
195 } 161 }
196 162
197 Context::~Context() { 163 Context::~Context() {
198 DCHECK(!base::MessageLoop::current()); 164 DCHECK(!base::MessageLoop::current());
199 } 165 }
200 166
201 } // namespace shell 167 } // namespace shell
202 } // namespace mojo 168 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698