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/shell/context.h" | 5 #include "mojo/shell/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 GURL url(parts[i + 1]); | 89 GURL url(parts[i + 1]); |
90 if (!url.is_valid()) { | 90 if (!url.is_valid()) { |
91 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers | 91 LOG(ERROR) << "Invalid value for switch " << switches::kContentHandlers |
92 << ": '" << parts[i + 1] << "' is not a valid URL."; | 92 << ": '" << parts[i + 1] << "' is not a valid URL."; |
93 return; | 93 return; |
94 } | 94 } |
95 loader->RegisterContentHandler(parts[i], url); | 95 loader->RegisterContentHandler(parts[i], url); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
| 99 class EmptyServiceProvider : public InterfaceImpl<ServiceProvider> { |
| 100 private: |
| 101 virtual void ConnectToService(const mojo::String& service_name, |
| 102 ScopedMessagePipeHandle client_handle) |
| 103 MOJO_OVERRIDE { |
| 104 } |
| 105 }; |
| 106 |
99 } // namespace | 107 } // namespace |
100 | 108 |
101 class Context::NativeViewportApplicationLoader | 109 class Context::NativeViewportApplicationLoader |
102 : public ApplicationLoader, | 110 : public ApplicationLoader, |
103 public ApplicationDelegate, | 111 public ApplicationDelegate, |
104 public InterfaceFactory<NativeViewport>, | 112 public InterfaceFactory<NativeViewport>, |
105 public InterfaceFactory<Gpu> { | 113 public InterfaceFactory<Gpu> { |
106 public: | 114 public: |
107 NativeViewportApplicationLoader() | 115 NativeViewportApplicationLoader() |
108 : share_group_(new gfx::GLShareGroup), | 116 : share_group_(new gfx::GLShareGroup), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 scoped_refptr<gfx::GLShareGroup> share_group_; | 154 scoped_refptr<gfx::GLShareGroup> share_group_; |
147 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 155 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
148 scoped_ptr<ApplicationImpl> app_; | 156 scoped_ptr<ApplicationImpl> app_; |
149 DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader); | 157 DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader); |
150 }; | 158 }; |
151 | 159 |
152 Context::Context() { | 160 Context::Context() { |
153 DCHECK(!base::MessageLoop::current()); | 161 DCHECK(!base::MessageLoop::current()); |
154 } | 162 } |
155 | 163 |
| 164 Context::~Context() { |
| 165 DCHECK(!base::MessageLoop::current()); |
| 166 } |
| 167 |
156 void Context::Init() { | 168 void Context::Init() { |
| 169 application_manager_.set_delegate(this); |
157 setup.Get(); | 170 setup.Get(); |
158 task_runners_.reset( | 171 task_runners_.reset( |
159 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); | 172 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); |
160 | 173 |
161 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) | 174 for (size_t i = 0; i < arraysize(kLocalMojoURLs); ++i) |
162 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); | 175 mojo_url_resolver_.AddLocalFileMapping(GURL(kLocalMojoURLs[i])); |
163 | 176 |
164 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 177 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
165 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; | 178 scoped_ptr<DynamicServiceRunnerFactory> runner_factory; |
166 if (command_line->HasSwitch(switches::kEnableMultiprocess)) | 179 if (command_line->HasSwitch(switches::kEnableMultiprocess)) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 new BackgroundShellApplicationLoader( | 235 new BackgroundShellApplicationLoader( |
223 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()), | 236 scoped_ptr<ApplicationLoader>(new NetworkApplicationLoader()), |
224 "network_service", | 237 "network_service", |
225 base::MessageLoop::TYPE_IO)); | 238 base::MessageLoop::TYPE_IO)); |
226 application_manager_.SetLoaderForURL(loader.PassAs<ApplicationLoader>(), | 239 application_manager_.SetLoaderForURL(loader.PassAs<ApplicationLoader>(), |
227 GURL("mojo:mojo_network_service")); | 240 GURL("mojo:mojo_network_service")); |
228 } | 241 } |
229 #endif | 242 #endif |
230 } | 243 } |
231 | 244 |
232 Context::~Context() { | 245 void Context::OnServiceError(const GURL& gurl) { |
233 DCHECK(!base::MessageLoop::current()); | 246 if (app_urls_.find(gurl) != app_urls_.end()) { |
| 247 app_urls_.erase(gurl); |
| 248 if (app_urls_.empty() && base::MessageLoop::current()->is_running()) |
| 249 base::MessageLoop::current()->Quit(); |
| 250 } |
| 251 } |
| 252 |
| 253 void Context::Run(const GURL& url) { |
| 254 EmptyServiceProvider* sp = new EmptyServiceProvider; |
| 255 ServiceProviderPtr spp; |
| 256 BindToProxy(sp, &spp); |
| 257 |
| 258 app_urls_.insert(url); |
| 259 application_manager_.ConnectToApplication(url, GURL(), spp.Pass()); |
| 260 } |
| 261 |
| 262 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
| 263 const GURL& application_url, |
| 264 const std::string& service_name) { |
| 265 app_urls_.insert(application_url); |
| 266 return application_manager_.ConnectToServiceByName( |
| 267 application_url, service_name).Pass(); |
234 } | 268 } |
235 | 269 |
236 } // namespace shell | 270 } // namespace shell |
237 } // namespace mojo | 271 } // namespace mojo |
OLD | NEW |