Chromium Code Reviews| Index: extensions/browser/updater/extension_downloader.cc |
| diff --git a/extensions/browser/updater/extension_downloader.cc b/extensions/browser/updater/extension_downloader.cc |
| index b2de04204df9eacb6b93097708432066f9c43703..8942b3aa2e5155ce96eefa518f693d2fc5915812 100644 |
| --- a/extensions/browser/updater/extension_downloader.cc |
| +++ b/extensions/browser/updater/extension_downloader.cc |
| @@ -21,6 +21,7 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| #include "base/version.h" |
| +#include "components/update_client/update_query_params.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_service.h" |
| @@ -45,6 +46,7 @@ |
| using base::Time; |
| using base::TimeDelta; |
| using content::BrowserThread; |
| +using update_client::UpdateQueryParams; |
| namespace extensions { |
| @@ -152,6 +154,15 @@ bool IncrementAuthUserIndex(GURL* url) { |
| } // namespace |
| +const char ExtensionDownloader::kUpdateInteractivityHeader[] = |
| + "X-GoogleUpdate-Interactivity"; |
| +const char ExtensionDownloader::kUpdateAppIdHeader[] = "X-GoogleUpdate-AppId"; |
| +const char ExtensionDownloader::kUpdateUpdaterHeader[] = |
| + "X-GoogleUpdate-Updater"; |
| + |
| +const char ExtensionDownloader::kUpdateInteractivityForeground[] = "fg"; |
| +const char ExtensionDownloader::kUpdateInteractivityBackground[] = "bg"; |
| + |
| UpdateDetails::UpdateDetails(const std::string& id, |
| const base::Version& version) |
| : id(id), version(version) {} |
| @@ -205,7 +216,8 @@ ExtensionDownloader::~ExtensionDownloader() { |
| } |
| bool ExtensionDownloader::AddExtension(const Extension& extension, |
| - int request_id) { |
| + int request_id, |
| + bool foreground_check) { |
| // Skip extensions with empty update URLs converted from user |
| // scripts. |
| if (extension.converted_from_user_script() && |
| @@ -222,15 +234,17 @@ bool ExtensionDownloader::AddExtension(const Extension& extension, |
| if (!ManifestURL::UpdatesFromGallery(&extension)) |
| extra.update_url_data = delegate_->GetUpdateUrlData(extension.id()); |
| - return AddExtensionData( |
| - extension.id(), *extension.version(), extension.GetType(), |
| - ManifestURL::GetUpdateURL(&extension), extra, request_id); |
| + return AddExtensionData(extension.id(), *extension.version(), |
| + extension.GetType(), |
| + ManifestURL::GetUpdateURL(&extension), extra, |
| + request_id, foreground_check); |
| } |
| bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
| const GURL& update_url, |
| bool is_corrupt_reinstall, |
| - int request_id) { |
| + int request_id, |
| + bool foreground_check) { |
| // Use a zero version to ensure that a pending extension will always |
| // be updated, and thus installed (assuming all extensions have |
| // non-zero versions). |
| @@ -241,7 +255,7 @@ bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
| extra.is_corrupt_reinstall = true; |
| return AddExtensionData(id, version, Manifest::TYPE_UNKNOWN, update_url, |
| - extra, request_id); |
| + extra, request_id, foreground_check); |
| } |
| void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { |
| @@ -276,10 +290,10 @@ void ExtensionDownloader::StartBlacklistUpdate( |
| // url here to avoid DNS hijacking of the blacklist, which is not validated |
| // by a public key signature like .crx files are. |
| std::unique_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData( |
| - extension_urls::GetWebstoreUpdateUrl(), request_id)); |
| + extension_urls::GetWebstoreUpdateUrl(), request_id, false)); |
| DCHECK(blacklist_fetch->base_url().SchemeIsCryptographic()); |
| blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, |
| - std::string(), kDefaultInstallSource); |
| + std::string(), kDefaultInstallSource, false); |
| StartUpdateCheck(std::move(blacklist_fetch)); |
| } |
| @@ -299,7 +313,8 @@ bool ExtensionDownloader::AddExtensionData(const std::string& id, |
| Manifest::Type extension_type, |
| const GURL& extension_update_url, |
| const ExtraParams& extra, |
| - int request_id) { |
| + int request_id, |
| + bool foreground_check) { |
| GURL update_url(extension_update_url); |
| // Skip extensions with non-empty invalid update URLs. |
| if (!update_url.is_empty() && !update_url.is_valid()) { |
| @@ -374,7 +389,7 @@ bool ExtensionDownloader::AddExtensionData(const std::string& id, |
| ManifestFetchData* existing_fetch = existing_iter->second.back().get(); |
| if (existing_fetch->AddExtension(id, version.GetString(), |
| optional_ping_data, extra.update_url_data, |
| - install_source)) { |
| + install_source, foreground_check)) { |
| added = true; |
| } |
| } |
| @@ -382,12 +397,13 @@ bool ExtensionDownloader::AddExtensionData(const std::string& id, |
| // Otherwise add a new element to the list, if the list doesn't exist or |
| // if its last element is already full. |
| std::unique_ptr<ManifestFetchData> fetch( |
| - CreateManifestFetchData(update_url, request_id)); |
| + CreateManifestFetchData(update_url, request_id, foreground_check)); |
| ManifestFetchData* fetch_ptr = fetch.get(); |
| fetches_preparing_[std::make_pair(request_id, update_url)].push_back( |
| std::move(fetch)); |
| added = fetch_ptr->AddExtension(id, version.GetString(), optional_ping_data, |
| - extra.update_url_data, install_source); |
| + extra.update_url_data, install_source, |
| + foreground_check); |
| DCHECK(added); |
| } |
| @@ -450,22 +466,36 @@ void ExtensionDownloader::StartUpdateCheck( |
| } |
| void ExtensionDownloader::CreateManifestFetcher() { |
| + const ManifestFetchData* active_request = manifests_queue_.active_request(); |
| + std::vector<std::string> id_vector(active_request->extension_ids().begin(), |
| + active_request->extension_ids().end()); |
| + std::string id_list = base::JoinString(id_vector, ","); |
| if (VLOG_IS_ON(2)) { |
| - std::vector<std::string> id_vector( |
| - manifests_queue_.active_request()->extension_ids().begin(), |
| - manifests_queue_.active_request()->extension_ids().end()); |
| - std::string id_list = base::JoinString(id_vector, ","); |
| - VLOG(2) << "Fetching " << manifests_queue_.active_request()->full_url() |
| - << " for " << id_list; |
| + VLOG(2) << "Fetching " << active_request->full_url() << " for " << id_list; |
| + VLOG(2) << "Update interactivity: " |
| + << (active_request->foreground_check() ? "fg" : "bg"); |
| } |
| - manifest_fetcher_ = net::URLFetcher::Create( |
| - kManifestFetcherId, manifests_queue_.active_request()->full_url(), |
| - net::URLFetcher::GET, this); |
| + manifest_fetcher_ = |
| + net::URLFetcher::Create(kManifestFetcherId, active_request->full_url(), |
| + net::URLFetcher::GET, this); |
| manifest_fetcher_->SetRequestContext(request_context_.get()); |
| manifest_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| net::LOAD_DO_NOT_SAVE_COOKIES | |
| net::LOAD_DISABLE_CACHE); |
| + |
| + // Send traffic-management headers. http://crosbug.com/130602 |
| + manifest_fetcher_->AddExtraRequestHeader(base::StringPrintf( |
| + "%s: %s", kUpdateInteractivityHeader, |
| + active_request->foreground_check() ? kUpdateInteractivityForeground |
| + : kUpdateInteractivityBackground)); |
| + manifest_fetcher_->AddExtraRequestHeader( |
| + base::StringPrintf("%s: %s", kUpdateAppIdHeader, id_list.c_str())); |
|
Devlin
2017/03/24 15:14:46
(see comment in bug about this)
Minh X. Nguyen
2017/03/27 23:05:29
Acknowledged.
|
| + manifest_fetcher_->AddExtraRequestHeader(base::StringPrintf( |
| + "%s: %s-%s", kUpdateUpdaterHeader, |
| + UpdateQueryParams::GetProdIdString(UpdateQueryParams::CRX), |
| + UpdateQueryParams::GetProdVersion().c_str())); |
| + |
| // Update checks can be interrupted if a network change is detected; this is |
| // common for the retail mode AppPack on ChromeOS. Retrying once should be |
| // enough to recover in those cases; let the fetcher retry up to 3 times |
| @@ -950,12 +980,14 @@ void ExtensionDownloader::OnGetTokenFailure( |
| ManifestFetchData* ExtensionDownloader::CreateManifestFetchData( |
| const GURL& update_url, |
| - int request_id) { |
| + int request_id, |
| + bool foreground_check) { |
| ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; |
| if (update_url.DomainIs(ping_enabled_domain_.c_str())) |
| ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; |
| - return new ManifestFetchData( |
| - update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
| + return new ManifestFetchData(update_url, request_id, brand_code_, |
| + manifest_query_params_, ping_mode, |
| + foreground_check); |
| } |
| } // namespace extensions |