| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 bool ShouldRetryRequest(const net::URLRequestStatus& status, | 89 bool ShouldRetryRequest(const net::URLRequestStatus& status, |
| 90 int response_code) { | 90 int response_code) { |
| 91 // Retry if the response code is a server error, or the request failed because | 91 // Retry if the response code is a server error, or the request failed because |
| 92 // of network errors as opposed to file errors. | 92 // of network errors as opposed to file errors. |
| 93 return (response_code >= 500 && status.is_success()) || | 93 return (response_code >= 500 && status.is_success()) || |
| 94 status.status() == net::URLRequestStatus::FAILED; | 94 status.status() == net::URLRequestStatus::FAILED; |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 UpdateDetails::UpdateDetails(const std::string& id, const Version& version) | 99 UpdateDetails::UpdateDetails(const std::string& id, |
| 100 const base::Version& version) |
| 100 : id(id), version(version) {} | 101 : id(id), version(version) {} |
| 101 | 102 |
| 102 UpdateDetails::~UpdateDetails() {} | 103 UpdateDetails::~UpdateDetails() {} |
| 103 | 104 |
| 104 ExtensionDownloader::ExtensionFetch::ExtensionFetch() : url() {} | 105 ExtensionDownloader::ExtensionFetch::ExtensionFetch() : url() {} |
| 105 | 106 |
| 106 ExtensionDownloader::ExtensionFetch::ExtensionFetch( | 107 ExtensionDownloader::ExtensionFetch::ExtensionFetch( |
| 107 const std::string& id, | 108 const std::string& id, |
| 108 const GURL& url, | 109 const GURL& url, |
| 109 const std::string& package_hash, | 110 const std::string& package_hash, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ManifestURL::GetUpdateURL(&extension), | 154 ManifestURL::GetUpdateURL(&extension), |
| 154 update_url_data, request_id); | 155 update_url_data, request_id); |
| 155 } | 156 } |
| 156 | 157 |
| 157 bool ExtensionDownloader::AddPendingExtension(const std::string& id, | 158 bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
| 158 const GURL& update_url, | 159 const GURL& update_url, |
| 159 int request_id) { | 160 int request_id) { |
| 160 // Use a zero version to ensure that a pending extension will always | 161 // Use a zero version to ensure that a pending extension will always |
| 161 // be updated, and thus installed (assuming all extensions have | 162 // be updated, and thus installed (assuming all extensions have |
| 162 // non-zero versions). | 163 // non-zero versions). |
| 163 Version version("0.0.0.0"); | 164 base::Version version("0.0.0.0"); |
| 164 DCHECK(version.IsValid()); | 165 DCHECK(version.IsValid()); |
| 165 | 166 |
| 166 return AddExtensionData(id, | 167 return AddExtensionData(id, |
| 167 version, | 168 version, |
| 168 Manifest::TYPE_UNKNOWN, | 169 Manifest::TYPE_UNKNOWN, |
| 169 update_url, | 170 update_url, |
| 170 std::string(), | 171 std::string(), |
| 171 request_id); | 172 request_id); |
| 172 } | 173 } |
| 173 | 174 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 198 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); | 199 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); |
| 199 blacklist_fetch->AddExtension(kBlacklistAppID, | 200 blacklist_fetch->AddExtension(kBlacklistAppID, |
| 200 version, | 201 version, |
| 201 &ping_data, | 202 &ping_data, |
| 202 std::string(), | 203 std::string(), |
| 203 kDefaultInstallSource); | 204 kDefaultInstallSource); |
| 204 StartUpdateCheck(blacklist_fetch.Pass()); | 205 StartUpdateCheck(blacklist_fetch.Pass()); |
| 205 } | 206 } |
| 206 | 207 |
| 207 bool ExtensionDownloader::AddExtensionData(const std::string& id, | 208 bool ExtensionDownloader::AddExtensionData(const std::string& id, |
| 208 const Version& version, | 209 const base::Version& version, |
| 209 Manifest::Type extension_type, | 210 Manifest::Type extension_type, |
| 210 const GURL& extension_update_url, | 211 const GURL& extension_update_url, |
| 211 const std::string& update_url_data, | 212 const std::string& update_url_data, |
| 212 int request_id) { | 213 int request_id) { |
| 213 GURL update_url(extension_update_url); | 214 GURL update_url(extension_update_url); |
| 214 // Skip extensions with non-empty invalid update URLs. | 215 // Skip extensions with non-empty invalid update URLs. |
| 215 if (!update_url.is_empty() && !update_url.is_valid()) { | 216 if (!update_url.is_empty() && !update_url.is_valid()) { |
| 216 LOG(WARNING) << "Extension " << id << " has invalid update url " | 217 LOG(WARNING) << "Extension " << id << " has invalid update url " |
| 217 << update_url; | 218 << update_url; |
| 218 return false; | 219 return false; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 fetch_data.request_ids(), | 524 fetch_data.request_ids(), |
| 524 ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE); | 525 ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE); |
| 525 } | 526 } |
| 526 | 527 |
| 527 void ExtensionDownloader::DetermineUpdates( | 528 void ExtensionDownloader::DetermineUpdates( |
| 528 const ManifestFetchData& fetch_data, | 529 const ManifestFetchData& fetch_data, |
| 529 const UpdateManifest::Results& possible_updates, | 530 const UpdateManifest::Results& possible_updates, |
| 530 std::vector<int>* result) { | 531 std::vector<int>* result) { |
| 531 // This will only be valid if one of possible_updates specifies | 532 // This will only be valid if one of possible_updates specifies |
| 532 // browser_min_version. | 533 // browser_min_version. |
| 533 Version browser_version; | 534 base::Version browser_version; |
| 534 | 535 |
| 535 for (size_t i = 0; i < possible_updates.list.size(); i++) { | 536 for (size_t i = 0; i < possible_updates.list.size(); i++) { |
| 536 const UpdateManifest::Result* update = &possible_updates.list[i]; | 537 const UpdateManifest::Result* update = &possible_updates.list[i]; |
| 537 const std::string& id = update->extension_id; | 538 const std::string& id = update->extension_id; |
| 538 | 539 |
| 539 if (!fetch_data.Includes(id)) { | 540 if (!fetch_data.Includes(id)) { |
| 540 VLOG(2) << "Ignoring " << id << " from this manifest"; | 541 VLOG(2) << "Ignoring " << id << " from this manifest"; |
| 541 continue; | 542 continue; |
| 542 } | 543 } |
| 543 | 544 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 554 // version is the same or older than what's already installed, | 555 // version is the same or older than what's already installed, |
| 555 // we don't want it. | 556 // we don't want it. |
| 556 std::string version; | 557 std::string version; |
| 557 if (!delegate_->GetExtensionExistingVersion(id, &version)) { | 558 if (!delegate_->GetExtensionExistingVersion(id, &version)) { |
| 558 VLOG(2) << id << " is not installed"; | 559 VLOG(2) << id << " is not installed"; |
| 559 continue; | 560 continue; |
| 560 } | 561 } |
| 561 | 562 |
| 562 VLOG(2) << id << " is at '" << version << "'"; | 563 VLOG(2) << id << " is at '" << version << "'"; |
| 563 | 564 |
| 564 Version existing_version(version); | 565 base::Version existing_version(version); |
| 565 Version update_version(update->version); | 566 base::Version update_version(update->version); |
| 566 | 567 |
| 567 if (!update_version.IsValid() || | 568 if (!update_version.IsValid() || |
| 568 update_version.CompareTo(existing_version) <= 0) { | 569 update_version.CompareTo(existing_version) <= 0) { |
| 569 continue; | 570 continue; |
| 570 } | 571 } |
| 571 } | 572 } |
| 572 | 573 |
| 573 // If the update specifies a browser minimum version, do we qualify? | 574 // If the update specifies a browser minimum version, do we qualify? |
| 574 if (update->browser_min_version.length() > 0) { | 575 if (update->browser_min_version.length() > 0) { |
| 575 // First determine the browser version if we haven't already. | 576 // First determine the browser version if we haven't already. |
| 576 if (!browser_version.IsValid()) { | 577 if (!browser_version.IsValid()) { |
| 577 chrome::VersionInfo version_info; | 578 chrome::VersionInfo version_info; |
| 578 if (version_info.is_valid()) | 579 if (version_info.is_valid()) |
| 579 browser_version = Version(version_info.Version()); | 580 browser_version = base::Version(version_info.Version()); |
| 580 } | 581 } |
| 581 Version browser_min_version(update->browser_min_version); | 582 base::Version browser_min_version(update->browser_min_version); |
| 582 if (browser_version.IsValid() && browser_min_version.IsValid() && | 583 if (browser_version.IsValid() && browser_min_version.IsValid() && |
| 583 browser_min_version.CompareTo(browser_version) > 0) { | 584 browser_min_version.CompareTo(browser_version) > 0) { |
| 584 // TODO(asargent) - We may want this to show up in the extensions UI | 585 // TODO(asargent) - We may want this to show up in the extensions UI |
| 585 // eventually. (http://crbug.com/12547). | 586 // eventually. (http://crbug.com/12547). |
| 586 LOG(WARNING) << "Updated version of extension " << id | 587 LOG(WARNING) << "Updated version of extension " << id |
| 587 << " available, but requires chrome version " | 588 << " available, but requires chrome version " |
| 588 << update->browser_min_version; | 589 << update->browser_min_version; |
| 589 continue; | 590 continue; |
| 590 } | 591 } |
| 591 } | 592 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 for (std::set<std::string>::const_iterator it = extension_ids.begin(); | 699 for (std::set<std::string>::const_iterator it = extension_ids.begin(); |
| 699 it != extension_ids.end(); ++it) { | 700 it != extension_ids.end(); ++it) { |
| 700 const ExtensionDownloaderDelegate::PingResult& ping = ping_results_[*it]; | 701 const ExtensionDownloaderDelegate::PingResult& ping = ping_results_[*it]; |
| 701 delegate_->OnExtensionDownloadFailed(*it, error, ping, request_ids); | 702 delegate_->OnExtensionDownloadFailed(*it, error, ping, request_ids); |
| 702 ping_results_.erase(*it); | 703 ping_results_.erase(*it); |
| 703 } | 704 } |
| 704 } | 705 } |
| 705 | 706 |
| 706 void ExtensionDownloader::NotifyUpdateFound(const std::string& id, | 707 void ExtensionDownloader::NotifyUpdateFound(const std::string& id, |
| 707 const std::string& version) { | 708 const std::string& version) { |
| 708 UpdateDetails updateInfo(id, Version(version)); | 709 UpdateDetails updateInfo(id, base::Version(version)); |
| 709 content::NotificationService::current()->Notify( | 710 content::NotificationService::current()->Notify( |
| 710 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, | 711 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, |
| 711 content::NotificationService::AllBrowserContextsAndSources(), | 712 content::NotificationService::AllBrowserContextsAndSources(), |
| 712 content::Details<UpdateDetails>(&updateInfo)); | 713 content::Details<UpdateDetails>(&updateInfo)); |
| 713 } | 714 } |
| 714 | 715 |
| 715 } // namespace extensions | 716 } // namespace extensions |
| OLD | NEW |