OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/application_manager/application_manager.h" | 5 #include "mojo/application_manager/application_manager.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 | 154 |
155 ApplicationManager::~ApplicationManager() { | 155 ApplicationManager::~ApplicationManager() { |
156 STLDeleteValues(&url_to_content_handler_); | 156 STLDeleteValues(&url_to_content_handler_); |
157 TerminateShellConnections(); | 157 TerminateShellConnections(); |
158 STLDeleteValues(&url_to_loader_); | 158 STLDeleteValues(&url_to_loader_); |
159 STLDeleteValues(&scheme_to_loader_); | 159 STLDeleteValues(&scheme_to_loader_); |
160 } | 160 } |
161 | 161 |
162 void ApplicationManager::TerminateShellConnections() { | 162 void ApplicationManager::TerminateShellConnections() { |
163 STLDeleteValues(&url_to_shell_impl_); | 163 STLDeleteValues(&url_to_shell_impl_); |
164 STLDeleteElements(&content_handler_shells_); | |
164 } | 165 } |
165 | 166 |
166 // static | 167 // static |
167 ApplicationManager* ApplicationManager::GetInstance() { | 168 ApplicationManager* ApplicationManager::GetInstance() { |
168 static base::LazyInstance<ApplicationManager> instance = | 169 static base::LazyInstance<ApplicationManager> instance = |
169 LAZY_INSTANCE_INITIALIZER; | 170 LAZY_INSTANCE_INITIALIZER; |
170 has_created_instance = true; | 171 has_created_instance = true; |
171 return &instance.Get(); | 172 return &instance.Get(); |
172 } | 173 } |
173 | 174 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 ScopedMessagePipeHandle* shell_handle) { | 218 ScopedMessagePipeHandle* shell_handle) { |
218 ShellImpl* shell_impl = NULL; | 219 ShellImpl* shell_impl = NULL; |
219 URLToShellImplMap::iterator iter = url_to_shell_impl_.find(url); | 220 URLToShellImplMap::iterator iter = url_to_shell_impl_.find(url); |
220 if (iter != url_to_shell_impl_.end()) { | 221 if (iter != url_to_shell_impl_.end()) { |
221 // This can happen because services are loaded asynchronously. So if we get | 222 // This can happen because services are loaded asynchronously. So if we get |
222 // two requests for the same service close to each other, we might get here | 223 // two requests for the same service close to each other, we might get here |
223 // and find that we already have it. | 224 // and find that we already have it. |
224 shell_impl = iter->second; | 225 shell_impl = iter->second; |
225 } else { | 226 } else { |
226 MessagePipe pipe; | 227 MessagePipe pipe; |
227 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | |
228 Array<String> args; | |
229 if (args_it != url_to_args_.end()) | |
230 args = Array<String>::From(args_it->second); | |
231 shell_impl = WeakBindToPipe(new ShellImpl(this, url), pipe.handle1.Pass()); | 228 shell_impl = WeakBindToPipe(new ShellImpl(this, url), pipe.handle1.Pass()); |
232 url_to_shell_impl_[url] = shell_impl; | 229 url_to_shell_impl_[url] = shell_impl; |
233 *shell_handle = pipe.handle0.Pass(); | 230 *shell_handle = pipe.handle0.Pass(); |
234 shell_impl->client()->Initialize(args.Pass()); | 231 shell_impl->client()->Initialize(GetArgsForURL(url)); |
235 } | 232 } |
236 | 233 |
237 ConnectToClient(shell_impl, url, requestor_url, service_provider.Pass()); | 234 ConnectToClient(shell_impl, url, requestor_url, service_provider.Pass()); |
238 } | 235 } |
239 | 236 |
240 void ApplicationManager::LoadWithContentHandler( | 237 void ApplicationManager::LoadWithContentHandler( |
241 const GURL& content_url, | 238 const GURL& content_url, |
242 const GURL& requestor_url, | 239 const GURL& requestor_url, |
243 const GURL& content_handler_url, | 240 const GURL& content_handler_url, |
244 URLResponsePtr url_response, | 241 URLResponsePtr url_response, |
245 ServiceProviderPtr service_provider) { | 242 ServiceProviderPtr service_provider) { |
246 ContentHandlerConnection* connection = NULL; | 243 ContentHandlerConnection* connection = NULL; |
247 URLToContentHandlerMap::iterator iter = | 244 URLToContentHandlerMap::iterator iter = |
248 url_to_content_handler_.find(content_handler_url); | 245 url_to_content_handler_.find(content_handler_url); |
249 if (iter != url_to_content_handler_.end()) { | 246 if (iter != url_to_content_handler_.end()) { |
250 connection = iter->second; | 247 connection = iter->second; |
251 } else { | 248 } else { |
252 connection = new ContentHandlerConnection(this, content_handler_url); | 249 connection = new ContentHandlerConnection(this, content_handler_url); |
253 url_to_content_handler_[content_handler_url] = connection; | 250 url_to_content_handler_[content_handler_url] = connection; |
254 } | 251 } |
255 | 252 |
256 InterfaceRequest<ServiceProvider> spir; | 253 ShellPtr shell_proxy; |
257 spir.Bind(service_provider.PassMessagePipe()); | 254 ShellImpl* shell_impl = |
258 connection->content_handler->OnConnect( | 255 WeakBindToProxy(new ShellImpl(this, content_url), &shell_proxy); |
259 requestor_url.spec(), url_response.Pass(), spir.Pass()); | 256 content_handler_shells_.insert(shell_impl); |
Aaron Boodman
2014/10/31 08:24:01
How about the name 'content_shell_impls'?
1. it's
qsr
2014/10/31 12:10:44
Good idea. Done.
| |
257 shell_impl->client()->Initialize(GetArgsForURL(content_url)); | |
258 | |
259 connection->content_handler->StartApplication(shell_proxy.Pass(), | |
260 url_response.Pass()); | |
261 ConnectToClient( | |
262 shell_impl, content_url, requestor_url, service_provider.Pass()); | |
260 } | 263 } |
261 | 264 |
262 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 265 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
263 const GURL& url) { | 266 const GURL& url) { |
264 URLToLoaderMap::iterator it = url_to_loader_.find(url); | 267 URLToLoaderMap::iterator it = url_to_loader_.find(url); |
265 if (it != url_to_loader_.end()) | 268 if (it != url_to_loader_.end()) |
266 delete it->second; | 269 delete it->second; |
267 url_to_loader_[url] = loader.release(); | 270 url_to_loader_[url] = loader.release(); |
268 } | 271 } |
269 | 272 |
(...skipping 21 matching lines...) Expand all Loading... | |
291 return url_it->second; | 294 return url_it->second; |
292 SchemeToLoaderMap::const_iterator scheme_it = | 295 SchemeToLoaderMap::const_iterator scheme_it = |
293 scheme_to_loader_.find(url.scheme()); | 296 scheme_to_loader_.find(url.scheme()); |
294 if (scheme_it != scheme_to_loader_.end()) | 297 if (scheme_it != scheme_to_loader_.end()) |
295 return scheme_it->second; | 298 return scheme_it->second; |
296 return default_loader_.get(); | 299 return default_loader_.get(); |
297 } | 300 } |
298 | 301 |
299 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { | 302 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { |
300 // Called from ~ShellImpl, so we do not need to call Destroy here. | 303 // Called from ~ShellImpl, so we do not need to call Destroy here. |
301 const GURL url = shell_impl->url(); | 304 auto it = content_handler_shells_.find(shell_impl); |
302 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); | 305 if (it != content_handler_shells_.end()) { |
303 DCHECK(it != url_to_shell_impl_.end()); | 306 delete (*it); |
304 delete it->second; | 307 content_handler_shells_.erase(it); |
Aaron Boodman
2014/10/31 08:24:01
return early.
qsr
2014/10/31 12:10:44
Done.
| |
305 url_to_shell_impl_.erase(it); | 308 } else { |
306 ApplicationLoader* loader = GetLoaderForURL(url); | 309 const GURL url = shell_impl->url(); |
Aaron Boodman
2014/10/31 08:24:01
Can't you remove the entry from url_to_content_han
qsr
2014/10/31 12:10:44
More than can, I must. That was part of the reason
| |
307 if (loader) | 310 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); |
308 loader->OnApplicationError(this, url); | 311 DCHECK(it != url_to_shell_impl_.end()); |
309 if (delegate_) | 312 delete it->second; |
310 delegate_->OnApplicationError(url); | 313 url_to_shell_impl_.erase(it); |
314 ApplicationLoader* loader = GetLoaderForURL(url); | |
315 if (loader) | |
316 loader->OnApplicationError(this, url); | |
317 if (delegate_) | |
318 delegate_->OnApplicationError(url); | |
319 } | |
311 } | 320 } |
312 | 321 |
313 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( | 322 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( |
314 const GURL& application_url, | 323 const GURL& application_url, |
315 const std::string& interface_name) { | 324 const std::string& interface_name) { |
316 StubServiceProvider* stub_sp = new StubServiceProvider; | 325 StubServiceProvider* stub_sp = new StubServiceProvider; |
317 ServiceProviderPtr spp; | 326 ServiceProviderPtr spp; |
318 BindToProxy(stub_sp, &spp); | 327 BindToProxy(stub_sp, &spp); |
319 ConnectToApplication(application_url, GURL(), spp.Pass()); | 328 ConnectToApplication(application_url, GURL(), spp.Pass()); |
320 MessagePipe pipe; | 329 MessagePipe pipe; |
321 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, | 330 stub_sp->GetRemoteServiceProvider()->ConnectToService(interface_name, |
322 pipe.handle1.Pass()); | 331 pipe.handle1.Pass()); |
323 return pipe.handle0.Pass(); | 332 return pipe.handle0.Pass(); |
324 } | 333 } |
334 | |
335 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { | |
336 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); | |
337 if (args_it != url_to_args_.end()) | |
338 return Array<String>::From(args_it->second); | |
339 return Array<String>(); | |
340 } | |
325 } // namespace mojo | 341 } // namespace mojo |
OLD | NEW |