| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/package_manager/package_manager_impl.h" | 5 #include "mojo/shell/package_manager/package_manager_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "mojo/application/public/interfaces/content_handler.mojom.h" | 12 #include "mojo/application/public/interfaces/content_handler.mojom.h" |
| 13 #include "mojo/fetcher/about_fetcher.h" | |
| 14 #include "mojo/fetcher/data_fetcher.h" | |
| 15 #include "mojo/fetcher/local_fetcher.h" | |
| 16 #include "mojo/fetcher/network_fetcher.h" | |
| 17 #include "mojo/fetcher/switches.h" | |
| 18 #include "mojo/fetcher/update_fetcher.h" | |
| 19 #include "mojo/shell/application_manager.h" | 13 #include "mojo/shell/application_manager.h" |
| 20 #include "mojo/shell/connect_util.h" | 14 #include "mojo/shell/connect_util.h" |
| 15 #include "mojo/shell/fetcher/about_fetcher.h" |
| 16 #include "mojo/shell/fetcher/data_fetcher.h" |
| 17 #include "mojo/shell/fetcher/local_fetcher.h" |
| 18 #include "mojo/shell/fetcher/network_fetcher.h" |
| 19 #include "mojo/shell/fetcher/switches.h" |
| 21 #include "mojo/shell/package_manager/content_handler_connection.h" | 20 #include "mojo/shell/package_manager/content_handler_connection.h" |
| 22 #include "mojo/shell/query_util.h" | 21 #include "mojo/shell/query_util.h" |
| 23 #include "mojo/shell/switches.h" | 22 #include "mojo/shell/switches.h" |
| 24 #include "mojo/util/filename_util.h" | 23 #include "mojo/util/filename_util.h" |
| 25 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 26 | 25 |
| 27 namespace mojo { | 26 namespace mojo { |
| 28 namespace shell { | 27 namespace shell { |
| 29 | 28 |
| 30 PackageManagerImpl::PackageManagerImpl( | 29 PackageManagerImpl::PackageManagerImpl( |
| 31 const base::FilePath& shell_file_root, | 30 const base::FilePath& shell_file_root, |
| 32 base::TaskRunner* task_runner) | 31 base::TaskRunner* task_runner) |
| 33 : application_manager_(nullptr), | 32 : application_manager_(nullptr), |
| 34 disable_cache_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 33 disable_cache_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 35 switches::kDisableCache)), | 34 switches::kDisableCache)), |
| 36 content_handler_id_counter_(0u), | 35 content_handler_id_counter_(0u), |
| 37 task_runner_(task_runner), | 36 task_runner_(task_runner), |
| 38 shell_file_root_(shell_file_root) { | 37 shell_file_root_(shell_file_root) { |
| 39 if (!shell_file_root.empty()) { | 38 if (!shell_file_root.empty()) { |
| 40 GURL mojo_root_file_url = | 39 GURL mojo_root_file_url = |
| 41 util::FilePathToFileURL(shell_file_root).Resolve(std::string()); | 40 util::FilePathToFileURL(shell_file_root).Resolve(std::string()); |
| 42 url_resolver_.reset(new fetcher::URLResolver(mojo_root_file_url)); | 41 url_resolver_.reset(new URLResolver(mojo_root_file_url)); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 PackageManagerImpl::~PackageManagerImpl() { | 45 PackageManagerImpl::~PackageManagerImpl() { |
| 47 IdentityToContentHandlerMap identity_to_content_handler( | 46 IdentityToContentHandlerMap identity_to_content_handler( |
| 48 identity_to_content_handler_); | 47 identity_to_content_handler_); |
| 49 for (auto& pair : identity_to_content_handler) | 48 for (auto& pair : identity_to_content_handler) |
| 50 pair.second->CloseConnection(); | 49 pair.second->CloseConnection(); |
| 51 } | 50 } |
| 52 | 51 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 } | 66 } |
| 68 | 67 |
| 69 void PackageManagerImpl::SetApplicationManager(ApplicationManager* manager) { | 68 void PackageManagerImpl::SetApplicationManager(ApplicationManager* manager) { |
| 70 application_manager_ = manager; | 69 application_manager_ = manager; |
| 71 } | 70 } |
| 72 | 71 |
| 73 void PackageManagerImpl::FetchRequest( | 72 void PackageManagerImpl::FetchRequest( |
| 74 URLRequestPtr request, | 73 URLRequestPtr request, |
| 75 const Fetcher::FetchCallback& loader_callback) { | 74 const Fetcher::FetchCallback& loader_callback) { |
| 76 GURL url(request->url); | 75 GURL url(request->url); |
| 77 if (url.SchemeIs(fetcher::AboutFetcher::kAboutScheme)) { | 76 if (url.SchemeIs(AboutFetcher::kAboutScheme)) { |
| 78 fetcher::AboutFetcher::Start(url, loader_callback); | 77 AboutFetcher::Start(url, loader_callback); |
| 79 return; | 78 return; |
| 80 } | 79 } |
| 81 | 80 |
| 82 if (url.SchemeIs(url::kDataScheme)) { | 81 if (url.SchemeIs(url::kDataScheme)) { |
| 83 fetcher::DataFetcher::Start(url, loader_callback); | 82 DataFetcher::Start(url, loader_callback); |
| 84 return; | 83 return; |
| 85 } | 84 } |
| 86 | 85 |
| 87 GURL resolved_url = ResolveURL(url); | 86 GURL resolved_url = ResolveURL(url); |
| 88 if (resolved_url.SchemeIsFile()) { | 87 if (resolved_url.SchemeIsFile()) { |
| 89 // LocalFetcher uses the network service to infer MIME types from URLs. | 88 // LocalFetcher uses the network service to infer MIME types from URLs. |
| 90 // Skip this for mojo URLs to avoid recursively loading the network service. | 89 // Skip this for mojo URLs to avoid recursively loading the network service. |
| 91 if (!network_service_ && !url.SchemeIs("mojo") && !url.SchemeIs("exe")) { | 90 if (!network_service_ && !url.SchemeIs("mojo") && !url.SchemeIs("exe")) { |
| 92 ConnectToService(application_manager_, GURL("mojo:network_service"), | 91 ConnectToService(application_manager_, GURL("mojo:network_service"), |
| 93 &network_service_); | 92 &network_service_); |
| 94 } | 93 } |
| 95 // Ownership of this object is transferred to |loader_callback|. | 94 // Ownership of this object is transferred to |loader_callback|. |
| 96 // TODO(beng): this is eff'n weird. | 95 // TODO(beng): this is eff'n weird. |
| 97 new fetcher::LocalFetcher( | 96 new LocalFetcher(network_service_.get(), resolved_url, |
| 98 network_service_.get(), resolved_url, | 97 GetBaseURLAndQuery(resolved_url, nullptr), |
| 99 GetBaseURLAndQuery(resolved_url, nullptr), | 98 shell_file_root_, loader_callback); |
| 100 shell_file_root_, loader_callback); | |
| 101 return; | 99 return; |
| 102 } | 100 } |
| 103 | 101 |
| 104 if (!url_loader_factory_) { | 102 if (!url_loader_factory_) { |
| 105 ConnectToService(application_manager_, GURL("mojo:network_service"), | 103 ConnectToService(application_manager_, GURL("mojo:network_service"), |
| 106 &url_loader_factory_); | 104 &url_loader_factory_); |
| 107 } | 105 } |
| 108 | 106 |
| 109 // Ownership of this object is transferred to |loader_callback|. | 107 // Ownership of this object is transferred to |loader_callback|. |
| 110 // TODO(beng): this is eff'n weird. | 108 // TODO(beng): this is eff'n weird. |
| 111 new fetcher::NetworkFetcher(disable_cache_, std::move(request), | 109 new NetworkFetcher(disable_cache_, std::move(request), |
| 112 url_loader_factory_.get(), loader_callback); | 110 url_loader_factory_.get(), loader_callback); |
| 113 } | 111 } |
| 114 | 112 |
| 115 uint32_t PackageManagerImpl::HandleWithContentHandler( | 113 uint32_t PackageManagerImpl::HandleWithContentHandler( |
| 116 Fetcher* fetcher, | 114 Fetcher* fetcher, |
| 117 const Identity& source, | 115 const Identity& source, |
| 118 const GURL& target_url, | 116 const GURL& target_url, |
| 119 const CapabilityFilter& target_filter, | 117 const CapabilityFilter& target_filter, |
| 120 InterfaceRequest<Application>* application_request) { | 118 InterfaceRequest<Application>* application_request) { |
| 121 Identity content_handler_identity; | 119 Identity content_handler_identity; |
| 122 URLResponsePtr response; | 120 URLResponsePtr response; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void PackageManagerImpl::OnContentHandlerConnectionClosed( | 218 void PackageManagerImpl::OnContentHandlerConnectionClosed( |
| 221 ContentHandlerConnection* connection) { | 219 ContentHandlerConnection* connection) { |
| 222 // Remove the mapping. | 220 // Remove the mapping. |
| 223 auto it = identity_to_content_handler_.find(connection->identity()); | 221 auto it = identity_to_content_handler_.find(connection->identity()); |
| 224 DCHECK(it != identity_to_content_handler_.end()); | 222 DCHECK(it != identity_to_content_handler_.end()); |
| 225 identity_to_content_handler_.erase(it); | 223 identity_to_content_handler_.erase(it); |
| 226 } | 224 } |
| 227 | 225 |
| 228 } // namespace shell | 226 } // namespace shell |
| 229 } // namespace mojo | 227 } // namespace mojo |
| OLD | NEW |