Chromium Code Reviews| 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_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } // namespace | 182 } // namespace |
| 183 | 183 |
| 184 namespace extensions { | 184 namespace extensions { |
| 185 | 185 |
| 186 ExtensionUpdater::CheckParams::CheckParams() | 186 ExtensionUpdater::CheckParams::CheckParams() |
| 187 : install_immediately(false) {} | 187 : install_immediately(false) {} |
| 188 | 188 |
| 189 ExtensionUpdater::CheckParams::~CheckParams() {} | 189 ExtensionUpdater::CheckParams::~CheckParams() {} |
| 190 | 190 |
| 191 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile( | 191 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile( |
| 192 const std::string& i, | 192 const CRXFileInfo& file, |
| 193 const base::FilePath& p, | |
| 194 bool file_ownership_passed, | 193 bool file_ownership_passed, |
| 195 const std::set<int>& request_ids) | 194 const std::set<int>& request_ids) |
| 196 : extension_id(i), | 195 : info(file), |
| 197 path(p), | |
| 198 file_ownership_passed(file_ownership_passed), | 196 file_ownership_passed(file_ownership_passed), |
| 199 request_ids(request_ids) {} | 197 request_ids(request_ids) { |
| 198 } | |
| 200 | 199 |
| 201 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile() | 200 ExtensionUpdater::FetchedCRXFile::FetchedCRXFile() |
| 202 : path(), file_ownership_passed(true) {} | 201 : info(), file_ownership_passed(true) { |
|
asargent_no_longer_on_chrome
2015/02/03 19:26:33
do you need to explicitly call the default constru
| |
| 202 } | |
| 203 | 203 |
| 204 ExtensionUpdater::FetchedCRXFile::~FetchedCRXFile() {} | 204 ExtensionUpdater::FetchedCRXFile::~FetchedCRXFile() {} |
| 205 | 205 |
| 206 ExtensionUpdater::InProgressCheck::InProgressCheck() | 206 ExtensionUpdater::InProgressCheck::InProgressCheck() |
| 207 : install_immediately(false) {} | 207 : install_immediately(false) {} |
| 208 | 208 |
| 209 ExtensionUpdater::InProgressCheck::~InProgressCheck() {} | 209 ExtensionUpdater::InProgressCheck::~InProgressCheck() {} |
| 210 | 210 |
| 211 struct ExtensionUpdater::ThrottleInfo { | 211 struct ExtensionUpdater::ThrottleInfo { |
| 212 ThrottleInfo() | 212 ThrottleInfo() |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 | 584 |
| 585 // This method is called if no updates were found. However a previous update | 585 // This method is called if no updates were found. However a previous update |
| 586 // check might have queued an update for this extension already. If a | 586 // check might have queued an update for this extension already. If a |
| 587 // current update check has |install_immediately| set the previously | 587 // current update check has |install_immediately| set the previously |
| 588 // queued update should be installed now. | 588 // queued update should be installed now. |
| 589 if (install_immediately && service_->GetPendingExtensionUpdate(id)) | 589 if (install_immediately && service_->GetPendingExtensionUpdate(id)) |
| 590 service_->FinishDelayedInstallation(id); | 590 service_->FinishDelayedInstallation(id); |
| 591 } | 591 } |
| 592 | 592 |
| 593 void ExtensionUpdater::OnExtensionDownloadFinished( | 593 void ExtensionUpdater::OnExtensionDownloadFinished( |
| 594 const std::string& id, | 594 const CRXFileInfo& file, |
| 595 const base::FilePath& path, | |
| 596 bool file_ownership_passed, | 595 bool file_ownership_passed, |
| 597 const GURL& download_url, | 596 const GURL& download_url, |
| 598 const std::string& version, | 597 const std::string& version, |
| 599 const PingResult& ping, | 598 const PingResult& ping, |
| 600 const std::set<int>& request_ids) { | 599 const std::set<int>& request_ids) { |
| 601 DCHECK(alive_); | 600 DCHECK(alive_); |
| 602 UpdatePingData(id, ping); | 601 UpdatePingData(file.extension_id, ping); |
| 603 | 602 |
| 604 VLOG(2) << download_url << " written to " << path.value(); | 603 VLOG(2) << download_url << " written to " << file.path.value(); |
| 605 | 604 |
| 606 FetchedCRXFile fetched(id, path, file_ownership_passed, request_ids); | 605 FetchedCRXFile fetched(file, file_ownership_passed, request_ids); |
| 607 fetched_crx_files_.push(fetched); | 606 fetched_crx_files_.push(fetched); |
| 608 | 607 |
| 609 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after | 608 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after |
| 610 // starting the crx installer. | 609 // starting the crx installer. |
| 611 MaybeInstallCRXFile(); | 610 MaybeInstallCRXFile(); |
| 612 } | 611 } |
| 613 | 612 |
| 614 bool ExtensionUpdater::GetPingDataForExtension( | 613 bool ExtensionUpdater::GetPingDataForExtension( |
| 615 const std::string& id, | 614 const std::string& id, |
| 616 ManifestFetchData::PingData* ping_data) { | 615 ManifestFetchData::PingData* ping_data) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 | 674 |
| 676 void ExtensionUpdater::MaybeInstallCRXFile() { | 675 void ExtensionUpdater::MaybeInstallCRXFile() { |
| 677 if (crx_install_is_running_ || fetched_crx_files_.empty()) | 676 if (crx_install_is_running_ || fetched_crx_files_.empty()) |
| 678 return; | 677 return; |
| 679 | 678 |
| 680 std::set<int> request_ids; | 679 std::set<int> request_ids; |
| 681 | 680 |
| 682 while (!fetched_crx_files_.empty() && !crx_install_is_running_) { | 681 while (!fetched_crx_files_.empty() && !crx_install_is_running_) { |
| 683 const FetchedCRXFile& crx_file = fetched_crx_files_.top(); | 682 const FetchedCRXFile& crx_file = fetched_crx_files_.top(); |
| 684 | 683 |
| 685 VLOG(2) << "updating " << crx_file.extension_id | 684 VLOG(2) << "updating " << crx_file.info.extension_id |
| 686 << " with " << crx_file.path.value(); | 685 << " with " << crx_file.info.path.value(); |
| 687 | 686 |
| 688 // The ExtensionService is now responsible for cleaning up the temp file | 687 // The ExtensionService is now responsible for cleaning up the temp file |
| 689 // at |crx_file.path|. | 688 // at |crx_file.info.path|. |
| 690 CrxInstaller* installer = NULL; | 689 CrxInstaller* installer = NULL; |
| 691 if (service_->UpdateExtension(crx_file.extension_id, | 690 if (service_->UpdateExtension(crx_file.info, |
| 692 crx_file.path, | |
| 693 crx_file.file_ownership_passed, | 691 crx_file.file_ownership_passed, |
| 694 &installer)) { | 692 &installer)) { |
| 695 crx_install_is_running_ = true; | 693 crx_install_is_running_ = true; |
| 696 current_crx_file_ = crx_file; | 694 current_crx_file_ = crx_file; |
| 697 | 695 |
| 698 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); | 696 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); |
| 699 it != crx_file.request_ids.end(); ++it) { | 697 it != crx_file.request_ids.end(); ++it) { |
| 700 InProgressCheck& request = requests_in_progress_[*it]; | 698 InProgressCheck& request = requests_in_progress_[*it]; |
| 701 if (request.install_immediately) { | 699 if (request.install_immediately) { |
| 702 installer->set_install_immediately(true); | 700 installer->set_install_immediately(true); |
| 703 break; | 701 break; |
| 704 } | 702 } |
| 705 } | 703 } |
| 706 | 704 |
| 707 // Source parameter ensures that we only see the completion event for the | 705 // Source parameter ensures that we only see the completion event for the |
| 708 // the installer we started. | 706 // the installer we started. |
| 709 registrar_.Add(this, | 707 registrar_.Add(this, |
| 710 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 708 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
| 711 content::Source<CrxInstaller>(installer)); | 709 content::Source<CrxInstaller>(installer)); |
| 712 } else { | 710 } else { |
| 713 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); | 711 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); |
| 714 it != crx_file.request_ids.end(); ++it) { | 712 it != crx_file.request_ids.end(); ++it) { |
| 715 InProgressCheck& request = requests_in_progress_[*it]; | 713 InProgressCheck& request = requests_in_progress_[*it]; |
| 716 request.in_progress_ids_.remove(crx_file.extension_id); | 714 request.in_progress_ids_.remove(crx_file.info.extension_id); |
| 717 } | 715 } |
| 718 request_ids.insert(crx_file.request_ids.begin(), | 716 request_ids.insert(crx_file.request_ids.begin(), |
| 719 crx_file.request_ids.end()); | 717 crx_file.request_ids.end()); |
| 720 } | 718 } |
| 721 fetched_crx_files_.pop(); | 719 fetched_crx_files_.pop(); |
| 722 } | 720 } |
| 723 | 721 |
| 724 for (std::set<int>::const_iterator it = request_ids.begin(); | 722 for (std::set<int>::const_iterator it = request_ids.begin(); |
| 725 it != request_ids.end(); ++it) { | 723 it != request_ids.end(); ++it) { |
| 726 NotifyIfFinished(*it); | 724 NotifyIfFinished(*it); |
| 727 } | 725 } |
| 728 } | 726 } |
| 729 | 727 |
| 730 void ExtensionUpdater::Observe(int type, | 728 void ExtensionUpdater::Observe(int type, |
| 731 const content::NotificationSource& source, | 729 const content::NotificationSource& source, |
| 732 const content::NotificationDetails& details) { | 730 const content::NotificationDetails& details) { |
| 733 DCHECK_EQ(type, extensions::NOTIFICATION_CRX_INSTALLER_DONE); | 731 DCHECK_EQ(type, extensions::NOTIFICATION_CRX_INSTALLER_DONE); |
| 734 | 732 |
| 735 registrar_.Remove(this, extensions::NOTIFICATION_CRX_INSTALLER_DONE, source); | 733 registrar_.Remove(this, extensions::NOTIFICATION_CRX_INSTALLER_DONE, source); |
| 736 crx_install_is_running_ = false; | 734 crx_install_is_running_ = false; |
| 737 | 735 |
| 738 const FetchedCRXFile& crx_file = current_crx_file_; | 736 const FetchedCRXFile& crx_file = current_crx_file_; |
| 739 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); | 737 for (std::set<int>::const_iterator it = crx_file.request_ids.begin(); |
| 740 it != crx_file.request_ids.end(); ++it) { | 738 it != crx_file.request_ids.end(); ++it) { |
| 741 InProgressCheck& request = requests_in_progress_[*it]; | 739 InProgressCheck& request = requests_in_progress_[*it]; |
| 742 request.in_progress_ids_.remove(crx_file.extension_id); | 740 request.in_progress_ids_.remove(crx_file.info.extension_id); |
| 743 NotifyIfFinished(*it); | 741 NotifyIfFinished(*it); |
| 744 } | 742 } |
| 745 | 743 |
| 746 // If any files are available to update, start one. | 744 // If any files are available to update, start one. |
| 747 MaybeInstallCRXFile(); | 745 MaybeInstallCRXFile(); |
| 748 } | 746 } |
| 749 | 747 |
| 750 void ExtensionUpdater::OnExtensionWillBeInstalled( | 748 void ExtensionUpdater::OnExtensionWillBeInstalled( |
| 751 content::BrowserContext* browser_context, | 749 content::BrowserContext* browser_context, |
| 752 const Extension* extension, | 750 const Extension* extension, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 768 const InProgressCheck& request = requests_in_progress_[request_id]; | 766 const InProgressCheck& request = requests_in_progress_[request_id]; |
| 769 if (request.in_progress_ids_.empty()) { | 767 if (request.in_progress_ids_.empty()) { |
| 770 VLOG(2) << "Finished update check " << request_id; | 768 VLOG(2) << "Finished update check " << request_id; |
| 771 if (!request.callback.is_null()) | 769 if (!request.callback.is_null()) |
| 772 request.callback.Run(); | 770 request.callback.Run(); |
| 773 requests_in_progress_.erase(request_id); | 771 requests_in_progress_.erase(request_id); |
| 774 } | 772 } |
| 775 } | 773 } |
| 776 | 774 |
| 777 } // namespace extensions | 775 } // namespace extensions |
| OLD | NEW |