| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), | 180 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), |
| 181 delegate_(delegate), | 181 delegate_(delegate), |
| 182 request_context_(request_context), | 182 request_context_(request_context), |
| 183 manifests_queue_(&kDefaultBackoffPolicy, | 183 manifests_queue_(&kDefaultBackoffPolicy, |
| 184 base::Bind(&ExtensionDownloader::CreateManifestFetcher, | 184 base::Bind(&ExtensionDownloader::CreateManifestFetcher, |
| 185 base::Unretained(this))), | 185 base::Unretained(this))), |
| 186 extensions_queue_(&kDefaultBackoffPolicy, | 186 extensions_queue_(&kDefaultBackoffPolicy, |
| 187 base::Bind(&ExtensionDownloader::CreateExtensionFetcher, | 187 base::Bind(&ExtensionDownloader::CreateExtensionFetcher, |
| 188 base::Unretained(this))), | 188 base::Unretained(this))), |
| 189 extension_cache_(NULL), | 189 extension_cache_(NULL), |
| 190 enable_extra_update_metrics_(false), |
| 190 weak_ptr_factory_(this) { | 191 weak_ptr_factory_(this) { |
| 191 DCHECK(delegate_); | 192 DCHECK(delegate_); |
| 192 DCHECK(request_context_.get()); | 193 DCHECK(request_context_.get()); |
| 193 } | 194 } |
| 194 | 195 |
| 195 ExtensionDownloader::~ExtensionDownloader() {} | 196 ExtensionDownloader::~ExtensionDownloader() {} |
| 196 | 197 |
| 197 bool ExtensionDownloader::AddExtension(const Extension& extension, | 198 bool ExtensionDownloader::AddExtension(const Extension& extension, |
| 198 int request_id) { | 199 int request_id) { |
| 199 // Skip extensions with empty update URLs converted from user | 200 // Skip extensions with empty update URLs converted from user |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 fetches_preparing_.clear(); | 268 fetches_preparing_.clear(); |
| 268 } | 269 } |
| 269 | 270 |
| 270 void ExtensionDownloader::StartBlacklistUpdate( | 271 void ExtensionDownloader::StartBlacklistUpdate( |
| 271 const std::string& version, | 272 const std::string& version, |
| 272 const ManifestFetchData::PingData& ping_data, | 273 const ManifestFetchData::PingData& ping_data, |
| 273 int request_id) { | 274 int request_id) { |
| 274 // Note: it is very important that we use the https version of the update | 275 // Note: it is very important that we use the https version of the update |
| 275 // url here to avoid DNS hijacking of the blacklist, which is not validated | 276 // url here to avoid DNS hijacking of the blacklist, which is not validated |
| 276 // by a public key signature like .crx files are. | 277 // by a public key signature like .crx files are. |
| 277 scoped_ptr<ManifestFetchData> blacklist_fetch( | 278 scoped_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData( |
| 278 new ManifestFetchData(extension_urls::GetWebstoreUpdateUrl(), | 279 extension_urls::GetWebstoreUpdateUrl(), request_id)); |
| 279 request_id)); | |
| 280 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); | 280 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); |
| 281 blacklist_fetch->AddExtension(kBlacklistAppID, | 281 blacklist_fetch->AddExtension(kBlacklistAppID, |
| 282 version, | 282 version, |
| 283 &ping_data, | 283 &ping_data, |
| 284 std::string(), | 284 std::string(), |
| 285 kDefaultInstallSource, | 285 kDefaultInstallSource, |
| 286 false); | 286 false); |
| 287 StartUpdateCheck(blacklist_fetch.Pass()); | 287 StartUpdateCheck(blacklist_fetch.Pass()); |
| 288 } | 288 } |
| 289 | 289 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 ++url_stats_.platform_app_count; | 346 ++url_stats_.platform_app_count; |
| 347 break; | 347 break; |
| 348 case Manifest::TYPE_UNKNOWN: | 348 case Manifest::TYPE_UNKNOWN: |
| 349 default: | 349 default: |
| 350 ++url_stats_.pending_count; | 350 ++url_stats_.pending_count; |
| 351 break; | 351 break; |
| 352 } | 352 } |
| 353 | 353 |
| 354 std::vector<GURL> update_urls; | 354 std::vector<GURL> update_urls; |
| 355 update_urls.push_back(update_url); | 355 update_urls.push_back(update_url); |
| 356 // If UMA is enabled, also add to ManifestFetchData for the | 356 // If metrics are enabled, also add to ManifestFetchData for the |
| 357 // webstore update URL. | 357 // webstore update URL. |
| 358 if (!extension_urls::IsWebstoreUpdateUrl(update_url) && | 358 if (!extension_urls::IsWebstoreUpdateUrl(update_url) && |
| 359 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { | 359 enable_extra_update_metrics_) { |
| 360 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl()); | 360 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 for (size_t i = 0; i < update_urls.size(); ++i) { | 363 for (size_t i = 0; i < update_urls.size(); ++i) { |
| 364 DCHECK(!update_urls[i].is_empty()); | 364 DCHECK(!update_urls[i].is_empty()); |
| 365 DCHECK(update_urls[i].is_valid()); | 365 DCHECK(update_urls[i].is_valid()); |
| 366 | 366 |
| 367 std::string install_source = i == 0 ? | 367 std::string install_source = i == 0 ? |
| 368 kDefaultInstallSource : kNotFromWebstoreInstallSource; | 368 kDefaultInstallSource : kNotFromWebstoreInstallSource; |
| 369 if (!install_source_override.empty()) { | 369 if (!install_source_override.empty()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 387 optional_ping_data, update_url_data, | 387 optional_ping_data, update_url_data, |
| 388 install_source, | 388 install_source, |
| 389 force_update)) { | 389 force_update)) { |
| 390 added = true; | 390 added = true; |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 if (!added) { | 393 if (!added) { |
| 394 // Otherwise add a new element to the list, if the list doesn't exist or | 394 // Otherwise add a new element to the list, if the list doesn't exist or |
| 395 // if its last element is already full. | 395 // if its last element is already full. |
| 396 linked_ptr<ManifestFetchData> fetch( | 396 linked_ptr<ManifestFetchData> fetch( |
| 397 new ManifestFetchData(update_urls[i], request_id)); | 397 CreateManifestFetchData(update_urls[i], request_id)); |
| 398 fetches_preparing_[std::make_pair(request_id, update_urls[i])]. | 398 fetches_preparing_[std::make_pair(request_id, update_urls[i])]. |
| 399 push_back(fetch); | 399 push_back(fetch); |
| 400 added = fetch->AddExtension(id, version.GetString(), | 400 added = fetch->AddExtension(id, version.GetString(), |
| 401 optional_ping_data, | 401 optional_ping_data, |
| 402 update_url_data, | 402 update_url_data, |
| 403 install_source, | 403 install_source, |
| 404 force_update); | 404 force_update); |
| 405 DCHECK(added); | 405 DCHECK(added); |
| 406 } | 406 } |
| 407 } | 407 } |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 } | 941 } |
| 942 | 942 |
| 943 void ExtensionDownloader::OnGetTokenFailure( | 943 void ExtensionDownloader::OnGetTokenFailure( |
| 944 const OAuth2TokenService::Request* request, | 944 const OAuth2TokenService::Request* request, |
| 945 const GoogleServiceAuthError& error) { | 945 const GoogleServiceAuthError& error) { |
| 946 // If we fail to get an access token, kick the pending fetch and let it fall | 946 // If we fail to get an access token, kick the pending fetch and let it fall |
| 947 // back on cookies. | 947 // back on cookies. |
| 948 extension_fetcher_->Start(); | 948 extension_fetcher_->Start(); |
| 949 } | 949 } |
| 950 | 950 |
| 951 ManifestFetchData* ExtensionDownloader::CreateManifestFetchData( |
| 952 const GURL& update_url, |
| 953 int request_id) { |
| 954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; |
| 955 if (update_url.DomainIs(ping_enabled_domain_.c_str())) { |
| 956 if (enable_extra_update_metrics_) { |
| 957 ping_mode = ManifestFetchData::PING_WITH_METRICS; |
| 958 } else { |
| 959 ping_mode = ManifestFetchData::PING; |
| 960 } |
| 961 } |
| 962 return new ManifestFetchData( |
| 963 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); |
| 964 } |
| 965 |
| 951 } // namespace extensions | 966 } // namespace extensions |
| OLD | NEW |