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

Side by Side Diff: chrome/browser/extensions/extension_updater.cc

Issue 2819023: Reworked ExtensionsService::AddPendingExtension(). (Closed)
Patch Set: Fixed browsertest test failure Created 10 years, 6 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_updater.h" 5 #include "chrome/browser/extensions/extension_updater.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 extension.id(), 162 extension.id(),
163 *extension.version(), 163 *extension.version(),
164 extension.converted_from_user_script(), 164 extension.converted_from_user_script(),
165 extension.is_theme(), 165 extension.is_theme(),
166 extension.update_url()); 166 extension.update_url());
167 } 167 }
168 168
169 void ManifestFetchesBuilder::AddPendingExtension( 169 void ManifestFetchesBuilder::AddPendingExtension(
170 const std::string& id, 170 const std::string& id,
171 const PendingExtensionInfo& info) { 171 const PendingExtensionInfo& info) {
172 AddExtensionData(Extension::INTERNAL, id, info.version, 172 // Use a zero version to ensure that a pending extension will always
173 // be updated, and thus installed (assuming all extensions have
174 // non-zero versions).
175 scoped_ptr<Version> version(
176 Version::GetVersionFromString("0.0.0.0"));
177 AddExtensionData(Extension::INTERNAL, id, *version,
173 false, info.is_theme, info.update_url); 178 false, info.is_theme, info.update_url);
174 } 179 }
175 180
176 void ManifestFetchesBuilder::ReportStats() const { 181 void ManifestFetchesBuilder::ReportStats() const {
177 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtensions", 182 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckExtensions",
178 url_stats_.google_url_count + 183 url_stats_.google_url_count +
179 url_stats_.other_url_count - 184 url_stats_.other_url_count -
180 url_stats_.theme_count); 185 url_stats_.theme_count);
181 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme", 186 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateCheckTheme",
182 url_stats_.theme_count); 187 url_stats_.theme_count);
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 fetches.clear(); 714 fetches.clear();
710 } 715 }
711 716
712 bool ExtensionUpdater::GetExistingVersion(const std::string& id, 717 bool ExtensionUpdater::GetExistingVersion(const std::string& id,
713 std::string* version) { 718 std::string* version) {
714 if (id == kBlacklistAppID) { 719 if (id == kBlacklistAppID) {
715 *version = 720 *version =
716 WideToASCII(prefs_->GetString(kExtensionBlacklistUpdateVersion)); 721 WideToASCII(prefs_->GetString(kExtensionBlacklistUpdateVersion));
717 return true; 722 return true;
718 } 723 }
719 PendingExtensionMap::const_iterator it =
720 service_->pending_extensions().find(id);
721 if (it != service_->pending_extensions().end()) {
722 *version = it->second.version.GetString();
723 return true;
724 }
725 Extension* extension = service_->GetExtensionById(id, false); 724 Extension* extension = service_->GetExtensionById(id, false);
726 if (!extension) { 725 if (!extension) {
727 return false; 726 return false;
728 } 727 }
729 *version = extension->version()->GetString(); 728 *version = extension->version()->GetString();
730 return true; 729 return true;
731 } 730 }
732 731
733 std::vector<int> ExtensionUpdater::DetermineUpdates( 732 std::vector<int> ExtensionUpdater::DetermineUpdates(
734 const ManifestFetchData& fetch_data, 733 const ManifestFetchData& fetch_data,
735 const UpdateManifest::Results& possible_updates) { 734 const UpdateManifest::Results& possible_updates) {
736 std::vector<int> result; 735 std::vector<int> result;
737 736
738 // This will only get set if one of possible_updates specifies 737 // This will only get set if one of possible_updates specifies
739 // browser_min_version. 738 // browser_min_version.
740 scoped_ptr<Version> browser_version; 739 scoped_ptr<Version> browser_version;
741 740
742 for (size_t i = 0; i < possible_updates.list.size(); i++) { 741 for (size_t i = 0; i < possible_updates.list.size(); i++) {
743 const UpdateManifest::Result* update = &possible_updates.list[i]; 742 const UpdateManifest::Result* update = &possible_updates.list[i];
744 743
745 if (!fetch_data.Includes(update->extension_id)) 744 if (!fetch_data.Includes(update->extension_id))
746 continue; 745 continue;
747 746
748 std::string version; 747 if (service_->pending_extensions().find(update->extension_id) ==
749 if (!GetExistingVersion(update->extension_id, &version)) 748 service_->pending_extensions().end()) {
750 continue; 749 // If we're not installing pending extension, and the update
750 // version is the same or older than what's already installed,
751 // we don't want it.
752 std::string version;
753 if (!GetExistingVersion(update->extension_id, &version))
754 continue;
751 755
752 // If the update version is the same or older than what's already installed, 756 scoped_ptr<Version> existing_version(
753 // we don't want it. 757 Version::GetVersionFromString(version));
754 scoped_ptr<Version> existing_version( 758 scoped_ptr<Version> update_version(
755 Version::GetVersionFromString(version)); 759 Version::GetVersionFromString(update->version));
756 scoped_ptr<Version> update_version(
757 Version::GetVersionFromString(update->version));
758 760
759 if (!update_version.get() || 761 if (!update_version.get() ||
760 update_version->CompareTo(*(existing_version.get())) <= 0) { 762 update_version->CompareTo(*(existing_version.get())) <= 0) {
761 continue; 763 continue;
764 }
762 } 765 }
763 766
764 // If the update specifies a browser minimum version, do we qualify? 767 // If the update specifies a browser minimum version, do we qualify?
765 if (update->browser_min_version.length() > 0) { 768 if (update->browser_min_version.length() > 0) {
766 // First determine the browser version if we haven't already. 769 // First determine the browser version if we haven't already.
767 if (!browser_version.get()) { 770 if (!browser_version.get()) {
768 scoped_ptr<FileVersionInfo> version_info( 771 scoped_ptr<FileVersionInfo> version_info(
769 chrome_app::GetChromeVersionInfo()); 772 chrome_app::GetChromeVersionInfo());
770 if (version_info.get()) { 773 if (version_info.get()) {
771 browser_version.reset(Version::GetVersionFromString( 774 browser_version.reset(Version::GetVersionFromString(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 extension_fetcher_.reset( 842 extension_fetcher_.reset(
840 URLFetcher::Create(kExtensionFetcherId, url, URLFetcher::GET, this)); 843 URLFetcher::Create(kExtensionFetcherId, url, URLFetcher::GET, this));
841 extension_fetcher_->set_request_context( 844 extension_fetcher_->set_request_context(
842 Profile::GetDefaultRequestContext()); 845 Profile::GetDefaultRequestContext());
843 extension_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | 846 extension_fetcher_->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES |
844 net::LOAD_DO_NOT_SAVE_COOKIES); 847 net::LOAD_DO_NOT_SAVE_COOKIES);
845 extension_fetcher_->Start(); 848 extension_fetcher_->Start();
846 current_extension_fetch_ = ExtensionFetch(id, url, hash, version); 849 current_extension_fetch_ = ExtensionFetch(id, url, hash, version);
847 } 850 }
848 } 851 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs_unittest.cc ('k') | chrome/browser/extensions/extension_updater_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698