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

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

Issue 129873019: Support extension update dwnloads which require auth (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 -1, 70 -1,
71 71
72 // Don't use initial delay unless the last request was an error. 72 // Don't use initial delay unless the last request was an error.
73 false, 73 false,
74 }; 74 };
75 75
76 const char kNotFromWebstoreInstallSource[] = "notfromwebstore"; 76 const char kNotFromWebstoreInstallSource[] = "notfromwebstore";
77 const char kDefaultInstallSource[] = ""; 77 const char kDefaultInstallSource[] = "";
78 78
79 #define RETRY_HISTOGRAM(name, retry_count, url) \ 79 #define RETRY_HISTOGRAM(name, retry_count, url) \
80 if ((url).DomainIs("google.com")) \ 80 if ((url).DomainIs("google.com")) { \
Ken Rockot(use gerrit already) 2014/01/22 22:34:52 Just cleaning up an uninteresting presubmit warnin
81 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 81 UMA_HISTOGRAM_CUSTOM_COUNTS( \
82 "Extensions." name "RetryCountGoogleUrl", retry_count, 1, \ 82 "Extensions." name "RetryCountGoogleUrl", retry_count, 1, \
83 kMaxRetries, kMaxRetries+1); \ 83 kMaxRetries, kMaxRetries+1); \
84 else \ 84 } else { \
85 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 85 UMA_HISTOGRAM_CUSTOM_COUNTS( \
86 "Extensions." name "RetryCountOtherUrl", retry_count, 1, \ 86 "Extensions." name "RetryCountOtherUrl", retry_count, 1, \
87 kMaxRetries, kMaxRetries+1) 87 kMaxRetries, kMaxRetries+1) \
88 }
88 89
89 bool ShouldRetryRequest(const net::URLRequestStatus& status, 90 bool ShouldRetryRequest(const net::URLRequestStatus& status,
90 int response_code) { 91 int response_code) {
91 // Retry if the response code is a server error, or the request failed because 92 // Retry if the response code is a server error, or the request failed because
92 // of network errors as opposed to file errors. 93 // of network errors as opposed to file errors.
93 return (response_code >= 500 && status.is_success()) || 94 return (response_code >= 500 && status.is_success()) ||
94 status.status() == net::URLRequestStatus::FAILED; 95 status.status() == net::URLRequestStatus::FAILED;
95 } 96 }
96 97
97 } // namespace 98 } // namespace
98 99
99 UpdateDetails::UpdateDetails(const std::string& id, const Version& version) 100 UpdateDetails::UpdateDetails(const std::string& id, const 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,
110 const std::string& version, 111 const std::string& version,
111 const std::set<int>& request_ids) 112 const std::set<int>& request_ids)
112 : id(id), url(url), package_hash(package_hash), version(version), 113 : id(id), url(url), package_hash(package_hash), version(version),
113 request_ids(request_ids) {} 114 request_ids(request_ids), is_protected(false) {}
114 115
115 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() {} 116 ExtensionDownloader::ExtensionFetch::~ExtensionFetch() {}
116 117
117 ExtensionDownloader::ExtensionDownloader( 118 ExtensionDownloader::ExtensionDownloader(
118 ExtensionDownloaderDelegate* delegate, 119 ExtensionDownloaderDelegate* delegate,
119 net::URLRequestContextGetter* request_context) 120 net::URLRequestContextGetter* request_context)
120 : delegate_(delegate), 121 : delegate_(delegate),
121 request_context_(request_context), 122 request_context_(request_context),
122 weak_ptr_factory_(this), 123 weak_ptr_factory_(this),
123 manifests_queue_(&kDefaultBackoffPolicy, 124 manifests_queue_(&kDefaultBackoffPolicy,
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (extensions_queue_.active_request() && 618 if (extensions_queue_.active_request() &&
618 extensions_queue_.active_request()->url == fetch_data->url) { 619 extensions_queue_.active_request()->url == fetch_data->url) {
619 extensions_queue_.active_request()->request_ids.insert( 620 extensions_queue_.active_request()->request_ids.insert(
620 fetch_data->request_ids.begin(), fetch_data->request_ids.end()); 621 fetch_data->request_ids.begin(), fetch_data->request_ids.end());
621 } else { 622 } else {
622 extensions_queue_.ScheduleRequest(fetch_data.Pass()); 623 extensions_queue_.ScheduleRequest(fetch_data.Pass());
623 } 624 }
624 } 625 }
625 626
626 void ExtensionDownloader::CreateExtensionFetcher() { 627 void ExtensionDownloader::CreateExtensionFetcher() {
628 const ExtensionFetch* fetch = extensions_queue_.active_request();
629 int load_flags = net::LOAD_DISABLE_CACHE;
630 if (!fetch->is_protected) {
631 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES |
632 net::LOAD_DO_NOT_SAVE_COOKIES;
633 }
627 extension_fetcher_.reset(net::URLFetcher::Create( 634 extension_fetcher_.reset(net::URLFetcher::Create(
628 kExtensionFetcherId, extensions_queue_.active_request()->url, 635 kExtensionFetcherId, fetch->url, net::URLFetcher::GET, this));
629 net::URLFetcher::GET, this));
630 extension_fetcher_->SetRequestContext(request_context_); 636 extension_fetcher_->SetRequestContext(request_context_);
631 extension_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 637 extension_fetcher_->SetLoadFlags(load_flags);
632 net::LOAD_DO_NOT_SAVE_COOKIES |
633 net::LOAD_DISABLE_CACHE);
634 extension_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3); 638 extension_fetcher_->SetAutomaticallyRetryOnNetworkChanges(3);
635 // Download CRX files to a temp file. The blacklist is small and will be 639 // Download CRX files to a temp file. The blacklist is small and will be
636 // processed in memory, so it is fetched into a string. 640 // processed in memory, so it is fetched into a string.
637 if (extensions_queue_.active_request()->id != kBlacklistAppID) { 641 if (fetch->id != kBlacklistAppID) {
638 extension_fetcher_->SaveResponseToTemporaryFile( 642 extension_fetcher_->SaveResponseToTemporaryFile(
639 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); 643 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
640 } 644 }
641 645
642 VLOG(2) << "Starting fetch of " << extensions_queue_.active_request()->url 646 VLOG(2) << "Starting fetch of " << fetch->url << " for " << fetch->id;
643 << " for " << extensions_queue_.active_request()->id;
644 647
645 extension_fetcher_->Start(); 648 extension_fetcher_->Start();
646 } 649 }
647 650
648 void ExtensionDownloader::OnCRXFetchComplete( 651 void ExtensionDownloader::OnCRXFetchComplete(
649 const net::URLFetcher* source, 652 const net::URLFetcher* source,
650 const GURL& url, 653 const GURL& url,
651 const net::URLRequestStatus& status, 654 const net::URLRequestStatus& status,
652 int response_code, 655 int response_code,
653 const base::TimeDelta& backoff_delay) { 656 const base::TimeDelta& backoff_delay) {
654 const std::string& id = extensions_queue_.active_request()->id; 657 ExtensionFetch* fetch = extensions_queue_.active_request();
655 const std::set<int>& request_ids = 658 const std::string& id = fetch->id;
656 extensions_queue_.active_request()->request_ids; 659 const std::set<int>& request_ids = fetch->request_ids;
657 const ExtensionDownloaderDelegate::PingResult& ping = ping_results_[id]; 660 const ExtensionDownloaderDelegate::PingResult& ping = ping_results_[id];
658 661
659 if (status.status() == net::URLRequestStatus::SUCCESS && 662 if (status.status() == net::URLRequestStatus::SUCCESS &&
660 (response_code == 200 || url.SchemeIsFile())) { 663 (response_code == 200 || url.SchemeIsFile())) {
661 RETRY_HISTOGRAM("CrxFetchSuccess", 664 RETRY_HISTOGRAM("CrxFetchSuccess",
662 extensions_queue_.active_request_failure_count(), url); 665 extensions_queue_.active_request_failure_count(), url);
663 base::FilePath crx_path; 666 base::FilePath crx_path;
664 // Take ownership of the file at |crx_path|. 667 // Take ownership of the file at |crx_path|.
665 CHECK(source->GetResponseAsFilePath(true, &crx_path)); 668 CHECK(source->GetResponseAsFilePath(true, &crx_path));
666 delegate_->OnExtensionDownloadFinished( 669 delegate_->OnExtensionDownloadFinished(
667 id, crx_path, url, extensions_queue_.active_request()->version, 670 id, crx_path, url, fetch->version, ping, request_ids);
668 ping, request_ids); 671 } else if (status.status() == net::URLRequestStatus::SUCCESS &&
672 response_code == 401 && !fetch->is_protected) {
673 // On 401, requeue this fetch with cookies enabled.
674 fetch->is_protected = true;
675 extensions_queue_.RetryRequest(backoff_delay);
669 } else { 676 } else {
670 VLOG(1) << "Failed to fetch extension '" << url.possibly_invalid_spec() 677 VLOG(1) << "Failed to fetch extension '" << url.possibly_invalid_spec()
671 << "' response code:" << response_code; 678 << "' response code:" << response_code;
672 if (ShouldRetryRequest(status, response_code) && 679 if (ShouldRetryRequest(status, response_code) &&
673 extensions_queue_.active_request_failure_count() < kMaxRetries) { 680 extensions_queue_.active_request_failure_count() < kMaxRetries) {
674 extensions_queue_.RetryRequest(backoff_delay); 681 extensions_queue_.RetryRequest(backoff_delay);
675 } else { 682 } else {
676 RETRY_HISTOGRAM("CrxFetchFailure", 683 RETRY_HISTOGRAM("CrxFetchFailure",
677 extensions_queue_.active_request_failure_count(), url); 684 extensions_queue_.active_request_failure_count(), url);
678 // status.error() is 0 (net::OK) or negative. (See net/base/net_errors.h) 685 // status.error() is 0 (net::OK) or negative. (See net/base/net_errors.h)
(...skipping 27 matching lines...) Expand all
706 void ExtensionDownloader::NotifyUpdateFound(const std::string& id, 713 void ExtensionDownloader::NotifyUpdateFound(const std::string& id,
707 const std::string& version) { 714 const std::string& version) {
708 UpdateDetails updateInfo(id, Version(version)); 715 UpdateDetails updateInfo(id, Version(version));
709 content::NotificationService::current()->Notify( 716 content::NotificationService::current()->Notify(
710 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND, 717 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND,
711 content::NotificationService::AllBrowserContextsAndSources(), 718 content::NotificationService::AllBrowserContextsAndSources(),
712 content::Details<UpdateDetails>(&updateInfo)); 719 content::Details<UpdateDetails>(&updateInfo));
713 } 720 }
714 721
715 } // namespace extensions 722 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698