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

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

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
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 "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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 void ExtensionDownloader::DoStartAllPending() { 249 void ExtensionDownloader::DoStartAllPending() {
250 ReportStats(); 250 ReportStats();
251 url_stats_ = URLStats(); 251 url_stats_ = URLStats();
252 252
253 for (FetchMap::iterator it = fetches_preparing_.begin(); 253 for (FetchMap::iterator it = fetches_preparing_.begin();
254 it != fetches_preparing_.end(); 254 it != fetches_preparing_.end();
255 ++it) { 255 ++it) {
256 std::vector<linked_ptr<ManifestFetchData>>& list = it->second; 256 std::vector<linked_ptr<ManifestFetchData>>& list = it->second;
257 for (size_t i = 0; i < list.size(); ++i) { 257 for (size_t i = 0; i < list.size(); ++i) {
258 StartUpdateCheck(scoped_ptr<ManifestFetchData>(list[i].release())); 258 StartUpdateCheck(std::unique_ptr<ManifestFetchData>(list[i].release()));
259 } 259 }
260 } 260 }
261 fetches_preparing_.clear(); 261 fetches_preparing_.clear();
262 } 262 }
263 263
264 void ExtensionDownloader::StartBlacklistUpdate( 264 void ExtensionDownloader::StartBlacklistUpdate(
265 const std::string& version, 265 const std::string& version,
266 const ManifestFetchData::PingData& ping_data, 266 const ManifestFetchData::PingData& ping_data,
267 int request_id) { 267 int request_id) {
268 // Note: it is very important that we use the https version of the update 268 // Note: it is very important that we use the https version of the update
269 // url here to avoid DNS hijacking of the blacklist, which is not validated 269 // url here to avoid DNS hijacking of the blacklist, which is not validated
270 // by a public key signature like .crx files are. 270 // by a public key signature like .crx files are.
271 scoped_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData( 271 std::unique_ptr<ManifestFetchData> blacklist_fetch(CreateManifestFetchData(
272 extension_urls::GetWebstoreUpdateUrl(), request_id)); 272 extension_urls::GetWebstoreUpdateUrl(), request_id));
273 DCHECK(blacklist_fetch->base_url().SchemeIsCryptographic()); 273 DCHECK(blacklist_fetch->base_url().SchemeIsCryptographic());
274 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data, 274 blacklist_fetch->AddExtension(kBlacklistAppID, version, &ping_data,
275 std::string(), kDefaultInstallSource); 275 std::string(), kDefaultInstallSource);
276 StartUpdateCheck(std::move(blacklist_fetch)); 276 StartUpdateCheck(std::move(blacklist_fetch));
277 } 277 }
278 278
279 void ExtensionDownloader::SetWebstoreIdentityProvider( 279 void ExtensionDownloader::SetWebstoreIdentityProvider(
280 scoped_ptr<IdentityProvider> identity_provider) { 280 std::unique_ptr<IdentityProvider> identity_provider) {
281 identity_provider_.swap(identity_provider); 281 identity_provider_.swap(identity_provider);
282 } 282 }
283 283
284 // static 284 // static
285 void ExtensionDownloader::set_test_delegate( 285 void ExtensionDownloader::set_test_delegate(
286 ExtensionDownloaderTestDelegate* delegate) { 286 ExtensionDownloaderTestDelegate* delegate) {
287 g_test_delegate = delegate; 287 g_test_delegate = delegate;
288 } 288 }
289 289
290 bool ExtensionDownloader::AddExtensionData(const std::string& id, 290 bool ExtensionDownloader::AddExtensionData(const std::string& id,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 url_stats_.pending_count); 406 url_stats_.pending_count);
407 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl", 407 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckGoogleUrl",
408 url_stats_.google_url_count); 408 url_stats_.google_url_count);
409 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl", 409 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckOtherUrl",
410 url_stats_.other_url_count); 410 url_stats_.other_url_count);
411 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl", 411 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckNoUrl",
412 url_stats_.no_url_count); 412 url_stats_.no_url_count);
413 } 413 }
414 414
415 void ExtensionDownloader::StartUpdateCheck( 415 void ExtensionDownloader::StartUpdateCheck(
416 scoped_ptr<ManifestFetchData> fetch_data) { 416 std::unique_ptr<ManifestFetchData> fetch_data) {
417 if (g_test_delegate) { 417 if (g_test_delegate) {
418 g_test_delegate->StartUpdateCheck(this, delegate_, std::move(fetch_data)); 418 g_test_delegate->StartUpdateCheck(this, delegate_, std::move(fetch_data));
419 return; 419 return;
420 } 420 }
421 421
422 const std::set<std::string>& id_set(fetch_data->extension_ids()); 422 const std::set<std::string>& id_set(fetch_data->extension_ids());
423 423
424 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) { 424 if (!ExtensionsBrowserClient::Get()->IsBackgroundUpdateAllowed()) {
425 NotifyExtensionsDownloadFailed(id_set, 425 NotifyExtensionsDownloadFailed(id_set,
426 fetch_data->request_ids(), 426 fetch_data->request_ids(),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 576
577 // Force https (crbug.com/129587). 577 // Force https (crbug.com/129587).
578 if (!crx_url.SchemeIsCryptographic()) { 578 if (!crx_url.SchemeIsCryptographic()) {
579 url::Replacements<char> replacements; 579 url::Replacements<char> replacements;
580 std::string scheme("https"); 580 std::string scheme("https");
581 replacements.SetScheme(scheme.c_str(), 581 replacements.SetScheme(scheme.c_str(),
582 url::Component(0, scheme.size())); 582 url::Component(0, scheme.size()));
583 crx_url = crx_url.ReplaceComponents(replacements); 583 crx_url = crx_url.ReplaceComponents(replacements);
584 } 584 }
585 } 585 }
586 scoped_ptr<ExtensionFetch> fetch( 586 std::unique_ptr<ExtensionFetch> fetch(
587 new ExtensionFetch(update->extension_id, crx_url, update->package_hash, 587 new ExtensionFetch(update->extension_id, crx_url, update->package_hash,
588 update->version, fetch_data->request_ids())); 588 update->version, fetch_data->request_ids()));
589 FetchUpdatedExtension(std::move(fetch)); 589 FetchUpdatedExtension(std::move(fetch));
590 } 590 }
591 591
592 // If the manifest response included a <daystart> element, we want to save 592 // If the manifest response included a <daystart> element, we want to save
593 // that value for any extensions which had sent a ping in the request. 593 // that value for any extensions which had sent a ping in the request.
594 if (fetch_data->base_url().DomainIs(kGoogleDotCom) && 594 if (fetch_data->base_url().DomainIs(kGoogleDotCom) &&
595 results->daystart_elapsed_seconds >= 0) { 595 results->daystart_elapsed_seconds >= 0) {
596 Time day_start = 596 Time day_start =
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 << update->browser_min_version; 663 << update->browser_min_version;
664 continue; 664 continue;
665 } 665 }
666 VLOG(2) << "will try to update " << id; 666 VLOG(2) << "will try to update " << id;
667 result->push_back(i); 667 result->push_back(i);
668 } 668 }
669 } 669 }
670 670
671 // Begins (or queues up) download of an updated extension. 671 // Begins (or queues up) download of an updated extension.
672 void ExtensionDownloader::FetchUpdatedExtension( 672 void ExtensionDownloader::FetchUpdatedExtension(
673 scoped_ptr<ExtensionFetch> fetch_data) { 673 std::unique_ptr<ExtensionFetch> fetch_data) {
674 if (!fetch_data->url.is_valid()) { 674 if (!fetch_data->url.is_valid()) {
675 // TODO(asargent): This can sometimes be invalid. See crbug.com/130881. 675 // TODO(asargent): This can sometimes be invalid. See crbug.com/130881.
676 DLOG(WARNING) << "Invalid URL: '" << fetch_data->url.possibly_invalid_spec() 676 DLOG(WARNING) << "Invalid URL: '" << fetch_data->url.possibly_invalid_spec()
677 << "' for extension " << fetch_data->id; 677 << "' for extension " << fetch_data->id;
678 return; 678 return;
679 } 679 }
680 680
681 for (RequestQueue<ExtensionFetch>::iterator iter = extensions_queue_.begin(); 681 for (RequestQueue<ExtensionFetch>::iterator iter = extensions_queue_.begin();
682 iter != extensions_queue_.end(); 682 iter != extensions_queue_.end();
683 ++iter) { 683 ++iter) {
(...skipping 20 matching lines...) Expand all
704 &crx_path, &version); 704 &crx_path, &version);
705 NotifyDelegateDownloadFinished(std::move(fetch_data), true, crx_path, 705 NotifyDelegateDownloadFinished(std::move(fetch_data), true, crx_path,
706 false); 706 false);
707 } else { 707 } else {
708 extensions_queue_.ScheduleRequest(std::move(fetch_data)); 708 extensions_queue_.ScheduleRequest(std::move(fetch_data));
709 } 709 }
710 } 710 }
711 } 711 }
712 712
713 void ExtensionDownloader::NotifyDelegateDownloadFinished( 713 void ExtensionDownloader::NotifyDelegateDownloadFinished(
714 scoped_ptr<ExtensionFetch> fetch_data, 714 std::unique_ptr<ExtensionFetch> fetch_data,
715 bool from_cache, 715 bool from_cache,
716 const base::FilePath& crx_path, 716 const base::FilePath& crx_path,
717 bool file_ownership_passed) { 717 bool file_ownership_passed) {
718 // Dereference required params before passing a scoped_ptr. 718 // Dereference required params before passing a scoped_ptr.
719 const std::string& id = fetch_data->id; 719 const std::string& id = fetch_data->id;
720 const std::string& package_hash = fetch_data->package_hash; 720 const std::string& package_hash = fetch_data->package_hash;
721 const GURL& url = fetch_data->url; 721 const GURL& url = fetch_data->url;
722 const std::string& version = fetch_data->version; 722 const std::string& version = fetch_data->version;
723 const std::set<int>& request_ids = fetch_data->request_ids; 723 const std::set<int>& request_ids = fetch_data->request_ids;
724 delegate_->OnExtensionDownloadFinished( 724 delegate_->OnExtensionDownloadFinished(
725 CRXFileInfo(id, crx_path, package_hash), file_ownership_passed, url, 725 CRXFileInfo(id, crx_path, package_hash), file_ownership_passed, url,
726 version, ping_results_[id], request_ids, 726 version, ping_results_[id], request_ids,
727 from_cache ? base::Bind(&ExtensionDownloader::CacheInstallDone, 727 from_cache ? base::Bind(&ExtensionDownloader::CacheInstallDone,
728 weak_ptr_factory_.GetWeakPtr(), 728 weak_ptr_factory_.GetWeakPtr(),
729 base::Passed(&fetch_data)) 729 base::Passed(&fetch_data))
730 : ExtensionDownloaderDelegate::InstallCallback()); 730 : ExtensionDownloaderDelegate::InstallCallback());
731 if (!from_cache) 731 if (!from_cache)
732 ping_results_.erase(id); 732 ping_results_.erase(id);
733 } 733 }
734 734
735 void ExtensionDownloader::CacheInstallDone( 735 void ExtensionDownloader::CacheInstallDone(
736 scoped_ptr<ExtensionFetch> fetch_data, 736 std::unique_ptr<ExtensionFetch> fetch_data,
737 bool should_download) { 737 bool should_download) {
738 ping_results_.erase(fetch_data->id); 738 ping_results_.erase(fetch_data->id);
739 if (should_download) { 739 if (should_download) {
740 // Resume download from cached manifest data. 740 // Resume download from cached manifest data.
741 extensions_queue_.ScheduleRequest(std::move(fetch_data)); 741 extensions_queue_.ScheduleRequest(std::move(fetch_data));
742 } 742 }
743 } 743 }
744 744
745 void ExtensionDownloader::CreateExtensionFetcher() { 745 void ExtensionDownloader::CreateExtensionFetcher() {
746 const ExtensionFetch* fetch = extensions_queue_.active_request(); 746 const ExtensionFetch* fetch = extensions_queue_.active_request();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 ExtensionFetch& active_request = *extensions_queue_.active_request(); 796 ExtensionFetch& active_request = *extensions_queue_.active_request();
797 const std::string& id = active_request.id; 797 const std::string& id = active_request.id;
798 if (status.status() == net::URLRequestStatus::SUCCESS && 798 if (status.status() == net::URLRequestStatus::SUCCESS &&
799 (response_code == 200 || url.SchemeIsFile())) { 799 (response_code == 200 || url.SchemeIsFile())) {
800 RETRY_HISTOGRAM("CrxFetchSuccess", 800 RETRY_HISTOGRAM("CrxFetchSuccess",
801 extensions_queue_.active_request_failure_count(), 801 extensions_queue_.active_request_failure_count(),
802 url); 802 url);
803 base::FilePath crx_path; 803 base::FilePath crx_path;
804 // Take ownership of the file at |crx_path|. 804 // Take ownership of the file at |crx_path|.
805 CHECK(source->GetResponseAsFilePath(true, &crx_path)); 805 CHECK(source->GetResponseAsFilePath(true, &crx_path));
806 scoped_ptr<ExtensionFetch> fetch_data = 806 std::unique_ptr<ExtensionFetch> fetch_data =
807 extensions_queue_.reset_active_request(); 807 extensions_queue_.reset_active_request();
808 if (extension_cache_) { 808 if (extension_cache_) {
809 const std::string& version = fetch_data->version; 809 const std::string& version = fetch_data->version;
810 const std::string& expected_hash = fetch_data->package_hash; 810 const std::string& expected_hash = fetch_data->package_hash;
811 extension_cache_->PutExtension( 811 extension_cache_->PutExtension(
812 id, expected_hash, crx_path, version, 812 id, expected_hash, crx_path, version,
813 base::Bind(&ExtensionDownloader::NotifyDelegateDownloadFinished, 813 base::Bind(&ExtensionDownloader::NotifyDelegateDownloadFinished,
814 weak_ptr_factory_.GetWeakPtr(), base::Passed(&fetch_data), 814 weak_ptr_factory_.GetWeakPtr(), base::Passed(&fetch_data),
815 false)); 815 false));
816 } else { 816 } else {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 const GURL& update_url, 952 const GURL& update_url,
953 int request_id) { 953 int request_id) {
954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING; 954 ManifestFetchData::PingMode ping_mode = ManifestFetchData::NO_PING;
955 if (update_url.DomainIs(ping_enabled_domain_.c_str())) 955 if (update_url.DomainIs(ping_enabled_domain_.c_str()))
956 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE; 956 ping_mode = ManifestFetchData::PING_WITH_ENABLED_STATE;
957 return new ManifestFetchData( 957 return new ManifestFetchData(
958 update_url, request_id, brand_code_, manifest_query_params_, ping_mode); 958 update_url, request_id, brand_code_, manifest_query_params_, ping_mode);
959 } 959 }
960 960
961 } // namespace extensions 961 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/updater/extension_downloader.h ('k') | extensions/browser/updater/request_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698