OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/updater/extension_downloader.h" | 5 #include "chrome/browser/extensions/updater/extension_downloader.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "base/version.h" | 21 #include "base/version.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/extensions/updater/extension_cache.h" | 23 #include "chrome/browser/extensions/updater/extension_cache.h" |
24 #include "chrome/browser/extensions/updater/request_queue_impl.h" | 24 #include "chrome/browser/extensions/updater/request_queue_impl.h" |
25 #include "chrome/browser/extensions/updater/safe_manifest_parser.h" | 25 #include "chrome/browser/extensions/updater/safe_manifest_parser.h" |
26 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 26 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chrome/common/extensions/manifest_url_handler.h" | 30 #include "chrome/common/extensions/manifest_url_handler.h" |
31 #include "components/omaha_query_params/omaha_query_params.h" | |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
33 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
34 #include "google_apis/gaia/identity_provider.h" | 35 #include "google_apis/gaia/identity_provider.h" |
35 #include "net/base/backoff_entry.h" | 36 #include "net/base/backoff_entry.h" |
36 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
37 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
38 #include "net/http/http_request_headers.h" | 39 #include "net/http/http_request_headers.h" |
39 #include "net/http/http_status_code.h" | 40 #include "net/http/http_status_code.h" |
40 #include "net/url_request/url_fetcher.h" | 41 #include "net/url_request/url_fetcher.h" |
41 #include "net/url_request/url_request_context_getter.h" | 42 #include "net/url_request/url_request_context_getter.h" |
42 #include "net/url_request/url_request_status.h" | 43 #include "net/url_request/url_request_status.h" |
43 | 44 |
44 using base::Time; | 45 using base::Time; |
45 using base::TimeDelta; | 46 using base::TimeDelta; |
46 using content::BrowserThread; | 47 using content::BrowserThread; |
48 using omaha_query_params::OmahaQueryParams; | |
47 | 49 |
48 namespace extensions { | 50 namespace extensions { |
49 | 51 |
50 const char ExtensionDownloader::kBlacklistAppID[] = "com.google.crx.blacklist"; | 52 const char ExtensionDownloader::kBlacklistAppID[] = "com.google.crx.blacklist"; |
51 | 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | 56 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { |
55 // Number of initial errors (in sequence) to ignore before applying | 57 // Number of initial errors (in sequence) to ignore before applying |
56 // exponential back-off rules. | 58 // exponential back-off rules. |
(...skipping 20 matching lines...) Expand all Loading... | |
77 false, | 79 false, |
78 }; | 80 }; |
79 | 81 |
80 const char kAuthUserQueryKey[] = "authuser"; | 82 const char kAuthUserQueryKey[] = "authuser"; |
81 | 83 |
82 const int kMaxAuthUserValue = 10; | 84 const int kMaxAuthUserValue = 10; |
83 const int kMaxOAuth2Attempts = 3; | 85 const int kMaxOAuth2Attempts = 3; |
84 | 86 |
85 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; | 87 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; |
86 const char kDefaultInstallSource[] = ""; | 88 const char kDefaultInstallSource[] = ""; |
89 const char kWrongMultiCrxInstallSource[] = "wrong_multi_crx"; | |
87 | 90 |
88 const char kGoogleDotCom[] = "google.com"; | 91 const char kGoogleDotCom[] = "google.com"; |
89 const char kTokenServiceConsumerId[] = "extension_downloader"; | 92 const char kTokenServiceConsumerId[] = "extension_downloader"; |
90 const char kWebstoreOAuth2Scope[] = | 93 const char kWebstoreOAuth2Scope[] = |
91 "https://www.googleapis.com/auth/chromewebstore.readonly"; | 94 "https://www.googleapis.com/auth/chromewebstore.readonly"; |
92 | 95 |
93 #define RETRY_HISTOGRAM(name, retry_count, url) \ | 96 #define RETRY_HISTOGRAM(name, retry_count, url) \ |
94 if ((url).DomainIs(kGoogleDotCom)) { \ | 97 if ((url).DomainIs(kGoogleDotCom)) { \ |
95 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \ | 98 UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions." name "RetryCountGoogleUrl", \ |
96 retry_count, \ | 99 retry_count, \ |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 return false; | 206 return false; |
204 } | 207 } |
205 | 208 |
206 // If the extension updates itself from the gallery, ignore any update URL | 209 // If the extension updates itself from the gallery, ignore any update URL |
207 // data. At the moment there is no extra data that an extension can | 210 // data. At the moment there is no extra data that an extension can |
208 // communicate to the the gallery update servers. | 211 // communicate to the the gallery update servers. |
209 std::string update_url_data; | 212 std::string update_url_data; |
210 if (!ManifestURL::UpdatesFromGallery(&extension)) | 213 if (!ManifestURL::UpdatesFromGallery(&extension)) |
211 update_url_data = delegate_->GetUpdateUrlData(extension.id()); | 214 update_url_data = delegate_->GetUpdateUrlData(extension.id()); |
212 | 215 |
213 return AddExtensionData(extension.id(), *extension.version(), | 216 // If the browser's native architecture has changed since this extension was |
217 // installed, we need to force an update. | |
218 bool force_update = false; | |
219 std::string install_source; | |
220 if (extension.HasPlatformSpecificResources() && | |
Sorin Jianu
2014/09/02 20:06:39
Do we need both conditions?
Ken Rockot(use gerrit already)
2014/09/02 20:19:20
Yes. Many extensions don't have any platform-speci
| |
221 !extension.HasResourcesForPlatform(OmahaQueryParams::GetNaclArch())) { | |
222 force_update = true; | |
223 install_source = kWrongMultiCrxInstallSource; | |
224 } | |
225 | |
226 return AddExtensionData(extension.id(), | |
227 *extension.version(), | |
214 extension.GetType(), | 228 extension.GetType(), |
215 ManifestURL::GetUpdateURL(&extension), | 229 ManifestURL::GetUpdateURL(&extension), |
216 update_url_data, request_id); | 230 update_url_data, |
231 request_id, | |
232 force_update, | |
233 install_source); | |
217 } | 234 } |
218 | 235 |
219 bool ExtensionDownloader::AddPendingExtension(const std::string& id, | 236 bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
220 const GURL& update_url, | 237 const GURL& update_url, |
221 int request_id) { | 238 int request_id) { |
222 // Use a zero version to ensure that a pending extension will always | 239 // Use a zero version to ensure that a pending extension will always |
223 // be updated, and thus installed (assuming all extensions have | 240 // be updated, and thus installed (assuming all extensions have |
224 // non-zero versions). | 241 // non-zero versions). |
225 Version version("0.0.0.0"); | 242 Version version("0.0.0.0"); |
226 DCHECK(version.IsValid()); | 243 DCHECK(version.IsValid()); |
227 | 244 |
228 return AddExtensionData(id, | 245 return AddExtensionData(id, |
229 version, | 246 version, |
230 Manifest::TYPE_UNKNOWN, | 247 Manifest::TYPE_UNKNOWN, |
231 update_url, | 248 update_url, |
232 std::string(), | 249 std::string(), |
233 request_id); | 250 request_id, |
251 false, | |
252 ""); | |
234 } | 253 } |
235 | 254 |
236 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { | 255 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { |
237 if (cache) { | 256 if (cache) { |
238 extension_cache_ = cache; | 257 extension_cache_ = cache; |
239 extension_cache_->Start(base::Bind( | 258 extension_cache_->Start(base::Bind( |
240 &ExtensionDownloader::DoStartAllPending, | 259 &ExtensionDownloader::DoStartAllPending, |
241 weak_ptr_factory_.GetWeakPtr())); | 260 weak_ptr_factory_.GetWeakPtr())); |
242 } else { | 261 } else { |
243 DoStartAllPending(); | 262 DoStartAllPending(); |
(...skipping 22 matching lines...) Expand all Loading... | |
266 // url here to avoid DNS hijacking of the blacklist, which is not validated | 285 // url here to avoid DNS hijacking of the blacklist, which is not validated |
267 // by a public key signature like .crx files are. | 286 // by a public key signature like .crx files are. |
268 scoped_ptr<ManifestFetchData> blacklist_fetch( | 287 scoped_ptr<ManifestFetchData> blacklist_fetch( |
269 new ManifestFetchData(extension_urls::GetWebstoreUpdateUrl(), | 288 new ManifestFetchData(extension_urls::GetWebstoreUpdateUrl(), |
270 request_id)); | 289 request_id)); |
271 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); | 290 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); |
272 blacklist_fetch->AddExtension(kBlacklistAppID, | 291 blacklist_fetch->AddExtension(kBlacklistAppID, |
273 version, | 292 version, |
274 &ping_data, | 293 &ping_data, |
275 std::string(), | 294 std::string(), |
276 kDefaultInstallSource); | 295 kDefaultInstallSource, |
296 false); | |
277 StartUpdateCheck(blacklist_fetch.Pass()); | 297 StartUpdateCheck(blacklist_fetch.Pass()); |
278 } | 298 } |
279 | 299 |
280 void ExtensionDownloader::SetWebstoreIdentityProvider( | 300 void ExtensionDownloader::SetWebstoreIdentityProvider( |
281 scoped_ptr<IdentityProvider> identity_provider) { | 301 scoped_ptr<IdentityProvider> identity_provider) { |
282 identity_provider_.swap(identity_provider); | 302 identity_provider_.swap(identity_provider); |
283 } | 303 } |
284 | 304 |
285 bool ExtensionDownloader::AddExtensionData(const std::string& id, | 305 bool ExtensionDownloader::AddExtensionData( |
286 const Version& version, | 306 const std::string& id, |
287 Manifest::Type extension_type, | 307 const Version& version, |
288 const GURL& extension_update_url, | 308 Manifest::Type extension_type, |
289 const std::string& update_url_data, | 309 const GURL& extension_update_url, |
290 int request_id) { | 310 const std::string& update_url_data, |
311 int request_id, | |
312 bool force_update, | |
313 const std::string& install_source_override) { | |
291 GURL update_url(extension_update_url); | 314 GURL update_url(extension_update_url); |
292 // Skip extensions with non-empty invalid update URLs. | 315 // Skip extensions with non-empty invalid update URLs. |
293 if (!update_url.is_empty() && !update_url.is_valid()) { | 316 if (!update_url.is_empty() && !update_url.is_valid()) { |
294 LOG(WARNING) << "Extension " << id << " has invalid update url " | 317 LOG(WARNING) << "Extension " << id << " has invalid update url " |
295 << update_url; | 318 << update_url; |
296 return false; | 319 return false; |
297 } | 320 } |
298 | 321 |
299 // Make sure we use SSL for store-hosted extensions. | 322 // Make sure we use SSL for store-hosted extensions. |
300 if (extension_urls::IsWebstoreUpdateUrl(update_url) && | 323 if (extension_urls::IsWebstoreUpdateUrl(update_url) && |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { | 369 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { |
347 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl()); | 370 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl()); |
348 } | 371 } |
349 | 372 |
350 for (size_t i = 0; i < update_urls.size(); ++i) { | 373 for (size_t i = 0; i < update_urls.size(); ++i) { |
351 DCHECK(!update_urls[i].is_empty()); | 374 DCHECK(!update_urls[i].is_empty()); |
352 DCHECK(update_urls[i].is_valid()); | 375 DCHECK(update_urls[i].is_valid()); |
353 | 376 |
354 std::string install_source = i == 0 ? | 377 std::string install_source = i == 0 ? |
355 kDefaultInstallSource : kNotFromWebstoreInstallSource; | 378 kDefaultInstallSource : kNotFromWebstoreInstallSource; |
379 if (!install_source_override.empty()) { | |
380 install_source = install_source_override; | |
381 } | |
356 | 382 |
357 ManifestFetchData::PingData ping_data; | 383 ManifestFetchData::PingData ping_data; |
358 ManifestFetchData::PingData* optional_ping_data = NULL; | 384 ManifestFetchData::PingData* optional_ping_data = NULL; |
359 if (delegate_->GetPingDataForExtension(id, &ping_data)) | 385 if (delegate_->GetPingDataForExtension(id, &ping_data)) |
360 optional_ping_data = &ping_data; | 386 optional_ping_data = &ping_data; |
361 | 387 |
362 // Find or create a ManifestFetchData to add this extension to. | 388 // Find or create a ManifestFetchData to add this extension to. |
363 bool added = false; | 389 bool added = false; |
364 FetchMap::iterator existing_iter = fetches_preparing_.find( | 390 FetchMap::iterator existing_iter = fetches_preparing_.find( |
365 std::make_pair(request_id, update_urls[i])); | 391 std::make_pair(request_id, update_urls[i])); |
366 if (existing_iter != fetches_preparing_.end() && | 392 if (existing_iter != fetches_preparing_.end() && |
367 !existing_iter->second.empty()) { | 393 !existing_iter->second.empty()) { |
368 // Try to add to the ManifestFetchData at the end of the list. | 394 // Try to add to the ManifestFetchData at the end of the list. |
369 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); | 395 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); |
370 if (existing_fetch->AddExtension(id, version.GetString(), | 396 if (existing_fetch->AddExtension(id, version.GetString(), |
371 optional_ping_data, update_url_data, | 397 optional_ping_data, update_url_data, |
372 install_source)) { | 398 install_source, |
399 force_update)) { | |
373 added = true; | 400 added = true; |
374 } | 401 } |
375 } | 402 } |
376 if (!added) { | 403 if (!added) { |
377 // Otherwise add a new element to the list, if the list doesn't exist or | 404 // Otherwise add a new element to the list, if the list doesn't exist or |
378 // if its last element is already full. | 405 // if its last element is already full. |
379 linked_ptr<ManifestFetchData> fetch( | 406 linked_ptr<ManifestFetchData> fetch( |
380 new ManifestFetchData(update_urls[i], request_id)); | 407 new ManifestFetchData(update_urls[i], request_id)); |
381 fetches_preparing_[std::make_pair(request_id, update_urls[i])]. | 408 fetches_preparing_[std::make_pair(request_id, update_urls[i])]. |
382 push_back(fetch); | 409 push_back(fetch); |
383 added = fetch->AddExtension(id, version.GetString(), | 410 added = fetch->AddExtension(id, version.GetString(), |
384 optional_ping_data, | 411 optional_ping_data, |
385 update_url_data, | 412 update_url_data, |
386 install_source); | 413 install_source, |
414 force_update); | |
387 DCHECK(added); | 415 DCHECK(added); |
388 } | 416 } |
389 } | 417 } |
390 | 418 |
391 return true; | 419 return true; |
392 } | 420 } |
393 | 421 |
394 void ExtensionDownloader::ReportStats() const { | 422 void ExtensionDownloader::ReportStats() const { |
395 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", | 423 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", |
396 url_stats_.extension_count); | 424 url_stats_.extension_count); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 if (!delegate_->GetExtensionExistingVersion(id, &version)) { | 663 if (!delegate_->GetExtensionExistingVersion(id, &version)) { |
636 VLOG(2) << id << " is not installed"; | 664 VLOG(2) << id << " is not installed"; |
637 continue; | 665 continue; |
638 } | 666 } |
639 | 667 |
640 VLOG(2) << id << " is at '" << version << "'"; | 668 VLOG(2) << id << " is at '" << version << "'"; |
641 | 669 |
642 Version existing_version(version); | 670 Version existing_version(version); |
643 Version update_version(update->version); | 671 Version update_version(update->version); |
644 | 672 |
645 if (!update_version.IsValid() || | 673 // We should skip the version check if update was forced. |
646 update_version.CompareTo(existing_version) <= 0) { | 674 if (!fetch_data.DidForceUpdate(id)) { |
Yoyo Zhou
2014/09/02 19:30:04
This could be at 669.
Ken Rockot(use gerrit already)
2014/09/02 20:04:30
Doh! Done.
| |
647 continue; | 675 if (!update_version.IsValid() || |
676 update_version.CompareTo(existing_version) <= 0) { | |
677 continue; | |
678 } | |
648 } | 679 } |
649 } | 680 } |
650 | 681 |
651 // If the update specifies a browser minimum version, do we qualify? | 682 // If the update specifies a browser minimum version, do we qualify? |
652 if (update->browser_min_version.length() > 0) { | 683 if (update->browser_min_version.length() > 0) { |
653 // First determine the browser version if we haven't already. | 684 // First determine the browser version if we haven't already. |
654 if (!browser_version.IsValid()) { | 685 if (!browser_version.IsValid()) { |
655 chrome::VersionInfo version_info; | 686 chrome::VersionInfo version_info; |
656 if (version_info.is_valid()) | 687 if (version_info.is_valid()) |
657 browser_version = Version(version_info.Version()); | 688 browser_version = Version(version_info.Version()); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 | 953 |
923 void ExtensionDownloader::OnGetTokenFailure( | 954 void ExtensionDownloader::OnGetTokenFailure( |
924 const OAuth2TokenService::Request* request, | 955 const OAuth2TokenService::Request* request, |
925 const GoogleServiceAuthError& error) { | 956 const GoogleServiceAuthError& error) { |
926 // If we fail to get an access token, kick the pending fetch and let it fall | 957 // If we fail to get an access token, kick the pending fetch and let it fall |
927 // back on cookies. | 958 // back on cookies. |
928 extension_fetcher_->Start(); | 959 extension_fetcher_->Start(); |
929 } | 960 } |
930 | 961 |
931 } // namespace extensions | 962 } // namespace extensions |
OLD | NEW |