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 "shell/application_manager/application_manager.h" | 5 #include "shell/application_manager/application_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 ApplicationManager::TestAPI::~TestAPI() { | 80 ApplicationManager::TestAPI::~TestAPI() { |
81 } | 81 } |
82 | 82 |
83 bool ApplicationManager::TestAPI::HasCreatedInstance() { | 83 bool ApplicationManager::TestAPI::HasCreatedInstance() { |
84 return has_created_instance; | 84 return has_created_instance; |
85 } | 85 } |
86 | 86 |
87 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { | 87 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { |
88 return manager_->url_to_shell_impl_.find(url) != | 88 return manager_->identity_to_shell_impl_.find(Identity(url)) != |
89 manager_->url_to_shell_impl_.end(); | 89 manager_->identity_to_shell_impl_.end(); |
90 } | 90 } |
91 | 91 |
92 ApplicationManager::ApplicationManager(Delegate* delegate) | 92 ApplicationManager::ApplicationManager(Delegate* delegate) |
93 : delegate_(delegate), weak_ptr_factory_(this) { | 93 : delegate_(delegate), weak_ptr_factory_(this) { |
94 } | 94 } |
95 | 95 |
96 ApplicationManager::~ApplicationManager() { | 96 ApplicationManager::~ApplicationManager() { |
97 STLDeleteValues(&url_to_content_handler_); | 97 STLDeleteValues(&url_to_content_handler_); |
98 TerminateShellConnections(); | 98 TerminateShellConnections(); |
99 STLDeleteValues(&url_to_loader_); | 99 STLDeleteValues(&url_to_loader_); |
100 STLDeleteValues(&scheme_to_loader_); | 100 STLDeleteValues(&scheme_to_loader_); |
101 } | 101 } |
102 | 102 |
103 void ApplicationManager::TerminateShellConnections() { | 103 void ApplicationManager::TerminateShellConnections() { |
104 STLDeleteValues(&url_to_shell_impl_); | 104 STLDeleteValues(&identity_to_shell_impl_); |
105 } | 105 } |
106 | 106 |
107 void ApplicationManager::ConnectToApplication( | 107 void ApplicationManager::ConnectToApplication( |
108 const GURL& requested_url, | 108 const GURL& requested_url, |
109 const GURL& requestor_url, | 109 const GURL& requestor_url, |
110 InterfaceRequest<ServiceProvider> services, | 110 InterfaceRequest<ServiceProvider> services, |
111 ServiceProviderPtr exposed_services) { | 111 ServiceProviderPtr exposed_services) { |
112 DCHECK(requested_url.is_valid()); | 112 DCHECK(requested_url.is_valid()); |
113 | 113 |
114 // We check both the mapped and resolved urls for existing shell_impls because | 114 // We check both the mapped and resolved urls for existing shell_impls because |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 services->Pass(), exposed_services->Pass())); | 192 services->Pass(), exposed_services->Pass())); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 InterfaceRequest<Application> ApplicationManager::RegisterShell( | 196 InterfaceRequest<Application> ApplicationManager::RegisterShell( |
197 const GURL& original_url, | 197 const GURL& original_url, |
198 const GURL& resolved_url, | 198 const GURL& resolved_url, |
199 const GURL& requestor_url, | 199 const GURL& requestor_url, |
200 InterfaceRequest<ServiceProvider> services, | 200 InterfaceRequest<ServiceProvider> services, |
201 ServiceProviderPtr exposed_services) { | 201 ServiceProviderPtr exposed_services) { |
202 GURL app_url = GetBaseURLAndQuery(resolved_url, nullptr); | 202 Identity app_identity(resolved_url); |
203 | 203 |
204 ApplicationPtr application; | 204 ApplicationPtr application; |
205 InterfaceRequest<Application> application_request = GetProxy(&application); | 205 InterfaceRequest<Application> application_request = GetProxy(&application); |
206 ShellImpl* shell = | 206 ShellImpl* shell = |
207 new ShellImpl(application.Pass(), this, original_url, app_url); | 207 new ShellImpl(application.Pass(), this, original_url, app_identity); |
208 url_to_shell_impl_[app_url] = shell; | 208 identity_to_shell_impl_[app_identity] = shell; |
209 shell->InitializeApplication(GetArgsForURL(original_url)); | 209 shell->InitializeApplication(GetArgsForURL(original_url)); |
210 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), | 210 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), |
211 exposed_services.Pass()); | 211 exposed_services.Pass()); |
212 return application_request.Pass(); | 212 return application_request.Pass(); |
213 } | 213 } |
214 | 214 |
215 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { | 215 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { |
216 const auto& shell_it = url_to_shell_impl_.find(url); | 216 const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); |
217 if (shell_it != url_to_shell_impl_.end()) | 217 if (shell_it != identity_to_shell_impl_.end()) |
218 return shell_it->second; | 218 return shell_it->second; |
219 return nullptr; | 219 return nullptr; |
220 } | 220 } |
221 | 221 |
222 void ApplicationManager::ConnectToClient( | 222 void ApplicationManager::ConnectToClient( |
223 ShellImpl* shell_impl, | 223 ShellImpl* shell_impl, |
224 const GURL& resolved_url, | 224 const GURL& resolved_url, |
225 const GURL& requestor_url, | 225 const GURL& requestor_url, |
226 InterfaceRequest<ServiceProvider> services, | 226 InterfaceRequest<ServiceProvider> services, |
227 ServiceProviderPtr exposed_services) { | 227 ServiceProviderPtr exposed_services) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 void ApplicationManager::RegisterExternalApplication( | 332 void ApplicationManager::RegisterExternalApplication( |
333 const GURL& url, | 333 const GURL& url, |
334 const std::vector<std::string>& args, | 334 const std::vector<std::string>& args, |
335 ApplicationPtr application) { | 335 ApplicationPtr application) { |
336 const auto& args_it = url_to_args_.find(url); | 336 const auto& args_it = url_to_args_.find(url); |
337 if (args_it != url_to_args_.end()) { | 337 if (args_it != url_to_args_.end()) { |
338 LOG(WARNING) << "--args-for provided for external application " << url | 338 LOG(WARNING) << "--args-for provided for external application " << url |
339 << " <ignored>"; | 339 << " <ignored>"; |
340 } | 340 } |
341 ShellImpl* shell_impl = new ShellImpl(application.Pass(), this, url, url); | 341 Identity identity(url); |
342 url_to_shell_impl_[url] = shell_impl; | 342 ShellImpl* shell_impl = |
| 343 new ShellImpl(application.Pass(), this, url, identity); |
| 344 identity_to_shell_impl_[identity] = shell_impl; |
343 shell_impl->InitializeApplication(Array<String>::From(args)); | 345 shell_impl->InitializeApplication(Array<String>::From(args)); |
344 } | 346 } |
345 | 347 |
346 void ApplicationManager::RegisterContentHandler( | 348 void ApplicationManager::RegisterContentHandler( |
347 const std::string& mime_type, | 349 const std::string& mime_type, |
348 const GURL& content_handler_url) { | 350 const GURL& content_handler_url) { |
349 DCHECK(content_handler_url.is_valid()) | 351 DCHECK(content_handler_url.is_valid()) |
350 << "Content handler URL is invalid for mime type " << mime_type; | 352 << "Content handler URL is invalid for mime type " << mime_type; |
351 mime_type_to_url_[mime_type] = content_handler_url; | 353 mime_type_to_url_[mime_type] = content_handler_url; |
352 } | 354 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 if (url_it != url_to_loader_.end()) | 412 if (url_it != url_to_loader_.end()) |
411 return url_it->second; | 413 return url_it->second; |
412 auto scheme_it = scheme_to_loader_.find(url.scheme()); | 414 auto scheme_it = scheme_to_loader_.find(url.scheme()); |
413 if (scheme_it != scheme_to_loader_.end()) | 415 if (scheme_it != scheme_to_loader_.end()) |
414 return scheme_it->second; | 416 return scheme_it->second; |
415 return nullptr; | 417 return nullptr; |
416 } | 418 } |
417 | 419 |
418 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { | 420 void ApplicationManager::OnShellImplError(ShellImpl* shell_impl) { |
419 // Called from ~ShellImpl, so we do not need to call Destroy here. | 421 // Called from ~ShellImpl, so we do not need to call Destroy here. |
420 const GURL url = shell_impl->url(); | 422 const Identity identity = shell_impl->identity(); |
421 const GURL requested_url = shell_impl->requested_url(); | 423 const GURL requested_url = shell_impl->requested_url(); |
422 // Remove the shell. | 424 // Remove the shell. |
423 URLToShellImplMap::iterator it = url_to_shell_impl_.find(url); | 425 auto it = identity_to_shell_impl_.find(identity); |
424 DCHECK(it != url_to_shell_impl_.end()); | 426 DCHECK(it != identity_to_shell_impl_.end()); |
425 delete it->second; | 427 delete it->second; |
426 url_to_shell_impl_.erase(it); | 428 identity_to_shell_impl_.erase(it); |
427 delegate_->OnApplicationError(requested_url); | 429 delegate_->OnApplicationError(requested_url); |
428 } | 430 } |
429 | 431 |
430 void ApplicationManager::OnContentHandlerError( | 432 void ApplicationManager::OnContentHandlerError( |
431 ContentHandlerConnection* content_handler) { | 433 ContentHandlerConnection* content_handler) { |
432 // Remove the mapping to the content handler. | 434 // Remove the mapping to the content handler. |
433 auto it = | 435 auto it = |
434 url_to_content_handler_.find(content_handler->content_handler_url()); | 436 url_to_content_handler_.find(content_handler->content_handler_url()); |
435 DCHECK(it != url_to_content_handler_.end()); | 437 DCHECK(it != url_to_content_handler_.end()); |
436 delete it->second; | 438 delete it->second; |
(...skipping 17 matching lines...) Expand all Loading... |
454 return Array<String>(); | 456 return Array<String>(); |
455 } | 457 } |
456 | 458 |
457 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 459 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
458 native_runners_.erase( | 460 native_runners_.erase( |
459 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 461 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
460 } | 462 } |
461 | 463 |
462 } // namespace shell | 464 } // namespace shell |
463 } // namespace mojo | 465 } // namespace mojo |
OLD | NEW |