Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: chrome/browser/extensions/updater/extension_downloader.cc

Issue 465543004: Factor Chrome details out of update manifest fetching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 13 matching lines...) Expand all
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 "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/notification_details.h" 32 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_service.h" 33 #include "content/public/browser/notification_service.h"
34 #include "extensions/browser/updater/default_manifest_fetch_data_delegate.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
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 : OAuth2TokenService::Consumer(kTokenServiceConsumerId), 181 : OAuth2TokenService::Consumer(kTokenServiceConsumerId),
181 delegate_(delegate), 182 delegate_(delegate),
182 request_context_(request_context), 183 request_context_(request_context),
183 weak_ptr_factory_(this), 184 weak_ptr_factory_(this),
184 manifests_queue_(&kDefaultBackoffPolicy, 185 manifests_queue_(&kDefaultBackoffPolicy,
185 base::Bind(&ExtensionDownloader::CreateManifestFetcher, 186 base::Bind(&ExtensionDownloader::CreateManifestFetcher,
186 base::Unretained(this))), 187 base::Unretained(this))),
187 extensions_queue_(&kDefaultBackoffPolicy, 188 extensions_queue_(&kDefaultBackoffPolicy,
188 base::Bind(&ExtensionDownloader::CreateExtensionFetcher, 189 base::Bind(&ExtensionDownloader::CreateExtensionFetcher,
189 base::Unretained(this))), 190 base::Unretained(this))),
190 extension_cache_(NULL) { 191 extension_cache_(NULL),
192 manifest_fetch_data_delegate_(new DefaultManifestFetchDataDelegate()) {
191 DCHECK(delegate_); 193 DCHECK(delegate_);
192 DCHECK(request_context_); 194 DCHECK(request_context_);
193 } 195 }
194 196
195 ExtensionDownloader::~ExtensionDownloader() {} 197 ExtensionDownloader::~ExtensionDownloader() {}
196 198
197 bool ExtensionDownloader::AddExtension(const Extension& extension, 199 bool ExtensionDownloader::AddExtension(const Extension& extension,
198 int request_id) { 200 int request_id) {
199 // Skip extensions with empty update URLs converted from user 201 // Skip extensions with empty update URLs converted from user
200 // scripts. 202 // scripts.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 262
261 void ExtensionDownloader::StartBlacklistUpdate( 263 void ExtensionDownloader::StartBlacklistUpdate(
262 const std::string& version, 264 const std::string& version,
263 const ManifestFetchData::PingData& ping_data, 265 const ManifestFetchData::PingData& ping_data,
264 int request_id) { 266 int request_id) {
265 // Note: it is very important that we use the https version of the update 267 // Note: it is very important that we use the https version of the update
266 // url here to avoid DNS hijacking of the blacklist, which is not validated 268 // url here to avoid DNS hijacking of the blacklist, which is not validated
267 // by a public key signature like .crx files are. 269 // by a public key signature like .crx files are.
268 scoped_ptr<ManifestFetchData> blacklist_fetch( 270 scoped_ptr<ManifestFetchData> blacklist_fetch(
269 new ManifestFetchData(extension_urls::GetWebstoreUpdateUrl(), 271 new ManifestFetchData(extension_urls::GetWebstoreUpdateUrl(),
270 request_id)); 272 request_id,
273 manifest_fetch_data_delegate_.get()));
271 DCHECK(blacklist_fetch->base_url().SchemeIsSecure()); 274 DCHECK(blacklist_fetch->base_url().SchemeIsSecure());
272 blacklist_fetch->AddExtension(kBlacklistAppID, 275 blacklist_fetch->AddExtension(kBlacklistAppID,
273 version, 276 version,
274 &ping_data, 277 &ping_data,
275 std::string(), 278 std::string(),
276 kDefaultInstallSource); 279 kDefaultInstallSource);
277 StartUpdateCheck(blacklist_fetch.Pass()); 280 StartUpdateCheck(blacklist_fetch.Pass());
278 } 281 }
279 282
280 void ExtensionDownloader::SetWebstoreIdentityProvider( 283 void ExtensionDownloader::SetWebstoreIdentityProvider(
281 scoped_ptr<IdentityProvider> identity_provider) { 284 scoped_ptr<IdentityProvider> identity_provider) {
282 identity_provider_.swap(identity_provider); 285 identity_provider_.swap(identity_provider);
283 } 286 }
284 287
288 void ExtensionDownloader::SetManifestFetchDataDelegate(
289 scoped_ptr<ManifestFetchDataDelegate> delegate) {
290 manifest_fetch_data_delegate_.swap(delegate);
291 }
292
285 bool ExtensionDownloader::AddExtensionData(const std::string& id, 293 bool ExtensionDownloader::AddExtensionData(const std::string& id,
286 const Version& version, 294 const Version& version,
287 Manifest::Type extension_type, 295 Manifest::Type extension_type,
288 const GURL& extension_update_url, 296 const GURL& extension_update_url,
289 const std::string& update_url_data, 297 const std::string& update_url_data,
290 int request_id) { 298 int request_id) {
291 GURL update_url(extension_update_url); 299 GURL update_url(extension_update_url);
292 // Skip extensions with non-empty invalid update URLs. 300 // Skip extensions with non-empty invalid update URLs.
293 if (!update_url.is_empty() && !update_url.is_valid()) { 301 if (!update_url.is_empty() && !update_url.is_valid()) {
294 LOG(WARNING) << "Extension " << id << " has invalid update url " 302 LOG(WARNING) << "Extension " << id << " has invalid update url "
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 default: 344 default:
337 ++url_stats_.pending_count; 345 ++url_stats_.pending_count;
338 break; 346 break;
339 } 347 }
340 348
341 std::vector<GURL> update_urls; 349 std::vector<GURL> update_urls;
342 update_urls.push_back(update_url); 350 update_urls.push_back(update_url);
343 // If UMA is enabled, also add to ManifestFetchData for the 351 // If UMA is enabled, also add to ManifestFetchData for the
344 // webstore update URL. 352 // webstore update URL.
345 if (!extension_urls::IsWebstoreUpdateUrl(update_url) && 353 if (!extension_urls::IsWebstoreUpdateUrl(update_url) &&
346 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { 354 manifest_fetch_data_delegate_->ShouldAlwaysCheckWebstore()) {
347 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl()); 355 update_urls.push_back(extension_urls::GetWebstoreUpdateUrl());
348 } 356 }
349 357
350 for (size_t i = 0; i < update_urls.size(); ++i) { 358 for (size_t i = 0; i < update_urls.size(); ++i) {
351 DCHECK(!update_urls[i].is_empty()); 359 DCHECK(!update_urls[i].is_empty());
352 DCHECK(update_urls[i].is_valid()); 360 DCHECK(update_urls[i].is_valid());
353 361
354 std::string install_source = i == 0 ? 362 std::string install_source = i == 0 ?
355 kDefaultInstallSource : kNotFromWebstoreInstallSource; 363 kDefaultInstallSource : kNotFromWebstoreInstallSource;
356 364
(...skipping 12 matching lines...) Expand all
369 ManifestFetchData* existing_fetch = existing_iter->second.back().get(); 377 ManifestFetchData* existing_fetch = existing_iter->second.back().get();
370 if (existing_fetch->AddExtension(id, version.GetString(), 378 if (existing_fetch->AddExtension(id, version.GetString(),
371 optional_ping_data, update_url_data, 379 optional_ping_data, update_url_data,
372 install_source)) { 380 install_source)) {
373 added = true; 381 added = true;
374 } 382 }
375 } 383 }
376 if (!added) { 384 if (!added) {
377 // Otherwise add a new element to the list, if the list doesn't exist or 385 // Otherwise add a new element to the list, if the list doesn't exist or
378 // if its last element is already full. 386 // if its last element is already full.
379 linked_ptr<ManifestFetchData> fetch( 387 linked_ptr<ManifestFetchData> fetch(new ManifestFetchData(
380 new ManifestFetchData(update_urls[i], request_id)); 388 update_urls[i], request_id, manifest_fetch_data_delegate_.get()));
381 fetches_preparing_[std::make_pair(request_id, update_urls[i])]. 389 fetches_preparing_[std::make_pair(request_id, update_urls[i])].
382 push_back(fetch); 390 push_back(fetch);
383 added = fetch->AddExtension(id, version.GetString(), 391 added = fetch->AddExtension(id, version.GetString(),
384 optional_ping_data, 392 optional_ping_data,
385 update_url_data, 393 update_url_data,
386 install_source); 394 install_source);
387 DCHECK(added); 395 DCHECK(added);
388 } 396 }
389 } 397 }
390 398
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 930
923 void ExtensionDownloader::OnGetTokenFailure( 931 void ExtensionDownloader::OnGetTokenFailure(
924 const OAuth2TokenService::Request* request, 932 const OAuth2TokenService::Request* request,
925 const GoogleServiceAuthError& error) { 933 const GoogleServiceAuthError& error) {
926 // If we fail to get an access token, kick the pending fetch and let it fall 934 // If we fail to get an access token, kick the pending fetch and let it fall
927 // back on cookies. 935 // back on cookies.
928 extension_fetcher_->Start(); 936 extension_fetcher_->Start();
929 } 937 }
930 938
931 } // namespace extensions 939 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698