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/package_manager/package_manager_impl.h" | 5 #include "mojo/package_manager/package_manager_impl.h" |
6 | 6 |
7 #include "mojo/fetcher/about_fetcher.h" | 7 #include "mojo/fetcher/about_fetcher.h" |
8 #include "mojo/fetcher/data_fetcher.h" | 8 #include "mojo/fetcher/data_fetcher.h" |
9 #include "mojo/fetcher/local_fetcher.h" | 9 #include "mojo/fetcher/local_fetcher.h" |
10 #include "mojo/fetcher/network_fetcher.h" | 10 #include "mojo/fetcher/network_fetcher.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const std::string& qualifier) { | 49 const std::string& qualifier) { |
50 application_package_alias_[alias] = | 50 application_package_alias_[alias] = |
51 std::make_pair(content_handler_package, qualifier); | 51 std::make_pair(content_handler_package, qualifier); |
52 } | 52 } |
53 | 53 |
54 void PackageManagerImpl::SetApplicationManager( | 54 void PackageManagerImpl::SetApplicationManager( |
55 shell::ApplicationManager* manager) { | 55 shell::ApplicationManager* manager) { |
56 application_manager_ = manager; | 56 application_manager_ = manager; |
57 } | 57 } |
58 | 58 |
59 GURL PackageManagerImpl::ResolveURL(const GURL& url) { | |
60 return url_resolver_.get() ? url_resolver_->ResolveMojoURL(url) : url; | |
61 } | |
62 | |
63 void PackageManagerImpl::FetchRequest( | 59 void PackageManagerImpl::FetchRequest( |
64 URLRequestPtr request, | 60 URLRequestPtr request, |
65 const shell::Fetcher::FetchCallback& loader_callback) { | 61 const shell::Fetcher::FetchCallback& loader_callback) { |
66 GURL url(request->url); | 62 GURL url(request->url); |
67 if (url.SchemeIs(fetcher::AboutFetcher::kAboutScheme)) { | 63 if (url.SchemeIs(fetcher::AboutFetcher::kAboutScheme)) { |
68 fetcher::AboutFetcher::Start(url, loader_callback); | 64 fetcher::AboutFetcher::Start(url, loader_callback); |
69 return; | 65 return; |
70 } | 66 } |
71 | 67 |
72 if (url.SchemeIs(url::kDataScheme)) { | 68 if (url.SchemeIs(url::kDataScheme)) { |
73 fetcher::DataFetcher::Start(url, loader_callback); | 69 fetcher::DataFetcher::Start(url, loader_callback); |
74 return; | 70 return; |
75 } | 71 } |
76 | 72 |
77 GURL resolved_url = ResolveURL(url); | 73 GURL resolved_url = ResolveURL(url); |
78 | |
79 if (resolved_url.SchemeIsFile()) { | 74 if (resolved_url.SchemeIsFile()) { |
80 // LocalFetcher uses the network service to infer MIME types from URLs. | 75 // LocalFetcher uses the network service to infer MIME types from URLs. |
81 // Skip this for mojo URLs to avoid recursively loading the network service. | 76 // Skip this for mojo URLs to avoid recursively loading the network service. |
82 if (!network_service_ && !url.SchemeIs("mojo")) { | 77 if (!network_service_ && !url.SchemeIs("mojo")) { |
83 shell::ConnectToService(application_manager_, | 78 shell::ConnectToService(application_manager_, |
84 GURL("mojo:network_service"), &network_service_); | 79 GURL("mojo:network_service"), &network_service_); |
85 } | 80 } |
86 // Ownership of this object is transferred to |loader_callback|. | 81 // Ownership of this object is transferred to |loader_callback|. |
87 // TODO(beng): this is eff'n weird. | 82 // TODO(beng): this is eff'n weird. |
88 new fetcher::LocalFetcher( | 83 new fetcher::LocalFetcher( |
(...skipping 25 matching lines...) Expand all Loading... |
114 &url_loader_factory_); | 109 &url_loader_factory_); |
115 } | 110 } |
116 | 111 |
117 // Ownership of this object is transferred to |loader_callback|. | 112 // Ownership of this object is transferred to |loader_callback|. |
118 // TODO(beng): this is eff'n weird. | 113 // TODO(beng): this is eff'n weird. |
119 new fetcher::NetworkFetcher(disable_cache_, request.Pass(), | 114 new fetcher::NetworkFetcher(disable_cache_, request.Pass(), |
120 url_loader_factory_.get(), loader_callback); | 115 url_loader_factory_.get(), loader_callback); |
121 } | 116 } |
122 | 117 |
123 bool PackageManagerImpl::HandleWithContentHandler(shell::Fetcher* fetcher, | 118 bool PackageManagerImpl::HandleWithContentHandler(shell::Fetcher* fetcher, |
124 const GURL& unresolved_url, | 119 const GURL& url, |
125 base::TaskRunner* task_runner, | 120 base::TaskRunner* task_runner, |
126 URLResponsePtr* new_response, | 121 URLResponsePtr* new_response, |
127 GURL* content_handler_url, | 122 GURL* content_handler_url, |
128 std::string* qualifier) { | 123 std::string* qualifier) { |
129 // TODO(beng): it seems like some delegate should/would want to have a say in | 124 // TODO(beng): it seems like some delegate should/would want to have a say in |
130 // configuring the qualifier also. | 125 // configuring the qualifier also. |
131 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( | 126 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
132 switches::kEnableMultiprocess); | 127 switches::kEnableMultiprocess); |
133 | 128 |
134 // The response begins with a #!mojo <content-handler-url>. | 129 // The response begins with a #!mojo <content-handler-url>. |
(...skipping 10 matching lines...) Expand all Loading... |
145 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 140 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
146 if (iter != mime_type_to_url_.end()) { | 141 if (iter != mime_type_to_url_.end()) { |
147 *new_response = fetcher->AsURLResponse(task_runner, 0); | 142 *new_response = fetcher->AsURLResponse(task_runner, 0); |
148 *content_handler_url = iter->second; | 143 *content_handler_url = iter->second; |
149 *qualifier = enable_multi_process ? (*new_response)->site.To<std::string>() | 144 *qualifier = enable_multi_process ? (*new_response)->site.To<std::string>() |
150 : std::string(); | 145 : std::string(); |
151 return true; | 146 return true; |
152 } | 147 } |
153 | 148 |
154 // The response URL matches a registered content handler. | 149 // The response URL matches a registered content handler. |
155 auto alias_iter = application_package_alias_.find(unresolved_url); | 150 auto alias_iter = application_package_alias_.find(url); |
156 if (alias_iter != application_package_alias_.end()) { | 151 if (alias_iter != application_package_alias_.end()) { |
157 // We replace the qualifier with the one our package alias requested. | 152 // We replace the qualifier with the one our package alias requested. |
158 *new_response = URLResponse::New(); | 153 *new_response = URLResponse::New(); |
159 (*new_response)->url = unresolved_url.spec(); | 154 (*new_response)->url = url.spec(); |
160 | 155 |
161 // Why can't we use this in single process mode? Because of | 156 // Why can't we use this in single process mode? Because of |
162 // base::AtExitManager. If you link in ApplicationRunner into your code, and | 157 // base::AtExitManager. If you link in ApplicationRunner into your code, and |
163 // then we make initialize multiple copies of the application, we end up | 158 // then we make initialize multiple copies of the application, we end up |
164 // with multiple AtExitManagers and will check on the second one being | 159 // with multiple AtExitManagers and will check on the second one being |
165 // created. | 160 // created. |
166 // | 161 // |
167 // Why doesn't that happen when running different apps? Because | 162 // Why doesn't that happen when running different apps? Because |
168 // your_thing.mojo!base::AtExitManager and | 163 // your_thing.mojo!base::AtExitManager and |
169 // my_thing.mojo!base::AtExitManager are different symbols. | 164 // my_thing.mojo!base::AtExitManager are different symbols. |
170 *qualifier = enable_multi_process ? alias_iter->second.second | 165 *qualifier = enable_multi_process ? alias_iter->second.second |
171 : std::string(); | 166 : std::string(); |
172 *content_handler_url = alias_iter->second.first; | 167 *content_handler_url = alias_iter->second.first; |
173 return true; | 168 return true; |
174 } | 169 } |
175 | 170 |
176 return false; | 171 return false; |
177 } | 172 } |
178 | 173 |
| 174 GURL PackageManagerImpl::ResolveURL(const GURL& url) { |
| 175 return url_resolver_.get() ? url_resolver_->ResolveMojoURL(url) : url; |
| 176 } |
| 177 |
179 } // namespace package_manager | 178 } // namespace package_manager |
180 } // namespace mojo | 179 } // namespace mojo |
OLD | NEW |