| 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 "extensions/browser/updater/extension_downloader.h" | 5 #include "extensions/browser/updater/extension_downloader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 bool ExtensionDownloader::AddExtension(const Extension& extension, | 204 bool ExtensionDownloader::AddExtension(const Extension& extension, |
| 205 int request_id) { | 205 int request_id) { |
| 206 // Skip extensions with empty update URLs converted from user | 206 // Skip extensions with empty update URLs converted from user |
| 207 // scripts. | 207 // scripts. |
| 208 if (extension.converted_from_user_script() && | 208 if (extension.converted_from_user_script() && |
| 209 ManifestURL::GetUpdateURL(&extension).is_empty()) { | 209 ManifestURL::GetUpdateURL(&extension).is_empty()) { |
| 210 return false; | 210 return false; |
| 211 } | 211 } |
| 212 | 212 |
| 213 ManifestFetchData::ExtraParams extra; |
| 214 |
| 213 // If the extension updates itself from the gallery, ignore any update URL | 215 // If the extension updates itself from the gallery, ignore any update URL |
| 214 // data. At the moment there is no extra data that an extension can | 216 // data. At the moment there is no extra data that an extension can |
| 215 // communicate to the the gallery update servers. | 217 // communicate to the the gallery update servers. |
| 216 std::string update_url_data; | 218 std::string update_url_data; |
| 217 if (!ManifestURL::UpdatesFromGallery(&extension)) | 219 if (!ManifestURL::UpdatesFromGallery(&extension)) |
| 218 update_url_data = delegate_->GetUpdateUrlData(extension.id()); | 220 extra.update_url_data = delegate_->GetUpdateUrlData(extension.id()); |
| 219 | 221 |
| 220 return AddExtensionData( | 222 return AddExtensionData( |
| 221 extension.id(), *extension.version(), extension.GetType(), | 223 extension.id(), *extension.version(), extension.GetType(), |
| 222 ManifestURL::GetUpdateURL(&extension), update_url_data, request_id); | 224 ManifestURL::GetUpdateURL(&extension), &extra, request_id); |
| 223 } | 225 } |
| 224 | 226 |
| 225 bool ExtensionDownloader::AddPendingExtension(const std::string& id, | 227 bool ExtensionDownloader::AddPendingExtension(const std::string& id, |
| 226 const GURL& update_url, | 228 const GURL& update_url, |
| 229 bool is_corrupt_reinstall, |
| 227 int request_id) { | 230 int request_id) { |
| 228 // Use a zero version to ensure that a pending extension will always | 231 // Use a zero version to ensure that a pending extension will always |
| 229 // be updated, and thus installed (assuming all extensions have | 232 // be updated, and thus installed (assuming all extensions have |
| 230 // non-zero versions). | 233 // non-zero versions). |
| 231 base::Version version("0.0.0.0"); | 234 base::Version version("0.0.0.0"); |
| 232 DCHECK(version.IsValid()); | 235 DCHECK(version.IsValid()); |
| 236 ManifestFetchData::ExtraParams extra; |
| 237 if (is_corrupt_reinstall) |
| 238 extra.is_corrupt_policy_reinstall = true; |
| 233 | 239 |
| 234 return AddExtensionData(id, version, Manifest::TYPE_UNKNOWN, update_url, | 240 return AddExtensionData(id, version, Manifest::TYPE_UNKNOWN, update_url, |
| 235 std::string(), request_id); | 241 &extra, request_id); |
| 236 } | 242 } |
| 237 | 243 |
| 238 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { | 244 void ExtensionDownloader::StartAllPending(ExtensionCache* cache) { |
| 239 if (cache) { | 245 if (cache) { |
| 240 extension_cache_ = cache; | 246 extension_cache_ = cache; |
| 241 extension_cache_->Start(base::Bind(&ExtensionDownloader::DoStartAllPending, | 247 extension_cache_->Start(base::Bind(&ExtensionDownloader::DoStartAllPending, |
| 242 weak_ptr_factory_.GetWeakPtr())); | 248 weak_ptr_factory_.GetWeakPtr())); |
| 243 } else { | 249 } else { |
| 244 DoStartAllPending(); | 250 DoStartAllPending(); |
| 245 } | 251 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 263 const std::string& version, | 269 const std::string& version, |
| 264 const ManifestFetchData::PingData& ping_data, | 270 const ManifestFetchData::PingData& ping_data, |
| 265 int request_id) { | 271 int request_id) { |
| 266 // Note: it is very important that we use the https version of the update | 272 // Note: it is very important that we use the https version of the update |
| 267 // url here to avoid DNS hijacking of the blacklist, which is not validated | 273 // url here to avoid DNS hijacking of the blacklist, which is not validated |
| 268 // by a public key signature like .crx files are. | 274 // by a public key signature like .crx files are. |
| 269 std::unique_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData( | 275 std::unique_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData( |
| 270 extension_urls::GetWebstoreUpdateUrl(), request_id)); | 276 extension_urls::GetWebstoreUpdateUrl(), request_id)); |
| 271 DCHECK(blacklist_fetch->base_url().SchemeIsCryptographic()); | 277 DCHECK(blacklist_fetch->base_url().SchemeIsCryptographic()); |
| 272 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, | 278 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, |
| 273 std::string(), kDefaultInstallSource); | 279 kDefaultInstallSource, nullptr); |
| 274 StartUpdateCheck(std::move(blacklist_fetch)); | 280 StartUpdateCheck(std::move(blacklist_fetch)); |
| 275 } | 281 } |
| 276 | 282 |
| 277 void ExtensionDownloader::SetWebstoreIdentityProvider( | 283 void ExtensionDownloader::SetWebstoreIdentityProvider( |
| 278 std::unique_ptr<IdentityProvider> identity_provider) { | 284 std::unique_ptr<IdentityProvider> identity_provider) { |
| 279 identity_provider_.swap(identity_provider); | 285 identity_provider_.swap(identity_provider); |
| 280 } | 286 } |
| 281 | 287 |
| 282 // static | 288 // static |
| 283 void ExtensionDownloader::set_test_delegate( | 289 void ExtensionDownloader::set_test_delegate( |
| 284 ExtensionDownloaderTestDelegate* delegate) { | 290 ExtensionDownloaderTestDelegate* delegate) { |
| 285 g_test_delegate = delegate; | 291 g_test_delegate = delegate; |
| 286 } | 292 } |
| 287 | 293 |
| 288 bool ExtensionDownloader::AddExtensionData(const std::string& id, | 294 bool ExtensionDownloader::AddExtensionData( |
| 289 const base::Version& version, | 295 const std::string& id, |
| 290 Manifest::Type extension_type, | 296 const base::Version& version, |
| 291 const GURL& extension_update_url, | 297 Manifest::Type extension_type, |
| 292 const std::string& update_url_data, | 298 const GURL& extension_update_url, |
| 293 int request_id) { | 299 const ManifestFetchData::ExtraParams* extra, |
| 300 int request_id) { |
| 294 GURL update_url(extension_update_url); | 301 GURL update_url(extension_update_url); |
| 295 // Skip extensions with non-empty invalid update URLs. | 302 // Skip extensions with non-empty invalid update URLs. |
| 296 if (!update_url.is_empty() && !update_url.is_valid()) { | 303 if (!update_url.is_empty() && !update_url.is_valid()) { |
| 297 DLOG(WARNING) << "Extension " << id << " has invalid update url " | 304 DLOG(WARNING) << "Extension " << id << " has invalid update url " |
| 298 << update_url; | 305 << update_url; |
| 299 return false; | 306 return false; |
| 300 } | 307 } |
| 301 | 308 |
| 302 // Make sure we use SSL for store-hosted extensions. | 309 // Make sure we use SSL for store-hosted extensions. |
| 303 if (extension_urls::IsWebstoreUpdateUrl(update_url) && | 310 if (extension_urls::IsWebstoreUpdateUrl(update_url) && |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 362 |
| 356 // Find or create a ManifestFetchData to add this extension to. | 363 // Find or create a ManifestFetchData to add this extension to. |
| 357 bool added = false; | 364 bool added = false; |
| 358 FetchMap::iterator existing_iter = | 365 FetchMap::iterator existing_iter = |
| 359 fetches_preparing_.find(std::make_pair(request_id, update_url)); | 366 fetches_preparing_.find(std::make_pair(request_id, update_url)); |
| 360 if (existing_iter != fetches_preparing_.end() && | 367 if (existing_iter != fetches_preparing_.end() && |
| 361 !existing_iter->second.empty()) { | 368 !existing_iter->second.empty()) { |
| 362 // Try to add to the ManifestFetchData at the end of the list. | 369 // Try to add to the ManifestFetchData at the end of the list. |
| 363 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); | 370 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); |
| 364 if (existing_fetch->AddExtension(id, version.GetString(), | 371 if (existing_fetch->AddExtension(id, version.GetString(), |
| 365 optional_ping_data, update_url_data, | 372 optional_ping_data, install_source, |
| 366 install_source)) { | 373 extra)) { |
| 367 added = true; | 374 added = true; |
| 368 } | 375 } |
| 369 } | 376 } |
| 370 if (!added) { | 377 if (!added) { |
| 371 // Otherwise add a new element to the list, if the list doesn't exist or | 378 // Otherwise add a new element to the list, if the list doesn't exist or |
| 372 // if its last element is already full. | 379 // if its last element is already full. |
| 373 std::unique_ptr<ManifestFetchData> fetch( | 380 std::unique_ptr<ManifestFetchData> fetch( |
| 374 CreateManifestFetchData(update_url, request_id)); | 381 CreateManifestFetchData(update_url, request_id)); |
| 375 ManifestFetchData* fetch_ptr = fetch.get(); | 382 ManifestFetchData* fetch_ptr = fetch.get(); |
| 376 fetches_preparing_[std::make_pair(request_id, update_url)].push_back( | 383 fetches_preparing_[std::make_pair(request_id, update_url)].push_back( |
| 377 std::move(fetch)); | 384 std::move(fetch)); |
| 378 added = fetch_ptr->AddExtension(id, version.GetString(), optional_ping_data, | 385 added = fetch_ptr->AddExtension(id, version.GetString(), optional_ping_data, |
| 379 update_url_data, install_source); | 386 install_source, extra); |
| 380 DCHECK(added); | 387 DCHECK(added); |
| 381 } | 388 } |
| 382 | 389 |
| 383 return true; | 390 return true; |
| 384 } | 391 } |
| 385 | 392 |
| 386 void ExtensionDownloader::ReportStats() const { | 393 void ExtensionDownloader::ReportStats() const { |
| 387 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", | 394 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtension", |
| 388 url_stats_.extension_count); | 395 url_stats_.extension_count); |
| 389 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", | 396 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 const GURL& update_url, | 948 const GURL& update_url, |
| 942 int request_id) { | 949 int request_id) { |
| 943 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; | 950 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; |
| 944 if (update_url.DomainIs(ping_enabled_domain_.c_str())) | 951 if (update_url.DomainIs(ping_enabled_domain_.c_str())) |
| 945 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; | 952 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; |
| 946 return new ManifestFetchData( | 953 return new ManifestFetchData( |
| 947 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); | 954 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
| 948 } | 955 } |
| 949 | 956 |
| 950 } // namespace extensions | 957 } // namespace extensions |
| OLD | NEW |