diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:44:06 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-30 23:44:06 +0000 |
commit | c5804aa16e82c47165652c1f3e6b570a4125b12e (patch) | |
tree | 904a8d835f1aac9158849bfcca2d6142a38ca692 | |
parent | cc2d7cdf57e13b1b71080fe674589e62afd689bc (diff) | |
download | chromium_src-c5804aa16e82c47165652c1f3e6b570a4125b12e.zip chromium_src-c5804aa16e82c47165652c1f3e6b570a4125b12e.tar.gz chromium_src-c5804aa16e82c47165652c1f3e6b570a4125b12e.tar.bz2 |
Send ping days parameter for extension blacklist update checks
BUG=39745
TEST=Extension update in general, and blacklisting, should still work normally.
Review URL: http://codereview.chromium.org/1540003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43142 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater.cc | 36 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater.h | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_updater_unittest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 4 |
7 files changed, 34 insertions, 28 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 015d7cb..177c882c 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -255,8 +255,8 @@ void ExtensionPrefs::UpdateBlacklist( return; } -Time ExtensionPrefs::LastPingDay(const std::string& extension_id) { - DictionaryValue* dictionary = GetExtensionPref(extension_id); +Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { + const DictionaryValue* dictionary = GetExtensionPref(extension_id); if (dictionary && dictionary->HasKey(kLastPingDay)) { std::string string_value; int64 value; @@ -490,7 +490,7 @@ DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref( } DictionaryValue* ExtensionPrefs::GetExtensionPref( - const std::string& extension_id) { + const std::string& extension_id) const { const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); if (!dict) return NULL; diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index e6de376..43d270e 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -90,7 +90,7 @@ class ExtensionPrefs { // Returns the last value set via SetLastPingDay. If there isn't such a // pref, the returned Time will return true for is_null(). - base::Time LastPingDay(const std::string& extension_id); + base::Time LastPingDay(const std::string& extension_id) const; // The time stored is based on the server's perspective of day start time, not // the client's. @@ -143,7 +143,7 @@ class ExtensionPrefs { DictionaryValue* GetOrCreateExtensionPref(const std::string& id); // Same as above, but returns NULL if it doesn't exist. - DictionaryValue* GetExtensionPref(const std::string& id); + DictionaryValue* GetExtensionPref(const std::string& id) const; // Checks if kPrefBlacklist is set to true in the DictionaryValue. // Return false if the value is false or kPrefBlacklist does not exist. diff --git a/chrome/browser/extensions/extension_updater.cc b/chrome/browser/extensions/extension_updater.cc index 1a8c6a0..9970cfe 100644 --- a/chrome/browser/extensions/extension_updater.cc +++ b/chrome/browser/extensions/extension_updater.cc @@ -142,6 +142,21 @@ bool ManifestFetchData::ShouldPing(int days) const { (days == kNeverPinged || days > 0); } +namespace { + +// Calculates the value to use for the ping days parameter in manifest +// fetches for a given extension. +static int CalculatePingDays(const std::string& extension_id, + const ExtensionUpdateService& service) { + int days = ManifestFetchData::kNeverPinged; + Time last_ping_day = service.LastPingDay(extension_id); + if (!last_ping_day.is_null()) { + days = (Time::Now() - last_ping_day).InDays(); + } + return days; +} + +} // namespace ManifestFetchesBuilder::ManifestFetchesBuilder( ExtensionUpdateService* service) : service_(service) { @@ -245,7 +260,7 @@ void ManifestFetchesBuilder::AddExtensionData( fetches_.find(update_url); // Find or create a ManifestFetchData to add this extension to. - int ping_days = CalculatePingDays(id); + int ping_days = CalculatePingDays(id, *service_); while (existing_iter != fetches_.end()) { if (existing_iter->second->AddExtension(id, version.GetString(), ping_days)) { @@ -262,17 +277,6 @@ void ManifestFetchesBuilder::AddExtensionData( } } -int ManifestFetchesBuilder::CalculatePingDays( - const std::string& extension_id) { - int days = ManifestFetchData::kNeverPinged; - Time last_ping_day = service_->LastPingDay(extension_id); - if (!last_ping_day.is_null()) { - days = (Time::Now() - last_ping_day).InDays(); - } - return days; -} - - // A utility class to do file handling on the file I/O thread. class ExtensionUpdaterFileHandler : public base::RefCountedThreadSafe<ExtensionUpdaterFileHandler> { @@ -550,7 +554,9 @@ void ExtensionUpdater::HandleManifestResults( std::set<std::string>::const_iterator i; for (i = extension_ids.begin(); i != extension_ids.end(); i++) { bool did_ping = fetch_data.DidPing(*i); - if (did_ping && service_->GetExtensionById(*i, true)) { + bool installed = (*i == kBlacklistAppID) || + (service_->GetExtensionById(*i, true) != NULL); + if (did_ping && installed) { service_->SetLastPingDay(*i, daystart); } } @@ -700,7 +706,9 @@ void ExtensionUpdater::CheckNow() { ManifestFetchData* blacklist_fetch = new ManifestFetchData(GURL(kBlacklistUpdateUrl)); std::wstring version = prefs_->GetString(kExtensionBlacklistUpdateVersion); - blacklist_fetch->AddExtension(kBlacklistAppID, WideToASCII(version), 0); + int ping_days = CalculatePingDays(kBlacklistAppID, *service_); + blacklist_fetch->AddExtension(kBlacklistAppID, WideToASCII(version), + ping_days); StartUpdateCheck(blacklist_fetch); } diff --git a/chrome/browser/extensions/extension_updater.h b/chrome/browser/extensions/extension_updater.h index 34043d6..eee0269 100644 --- a/chrome/browser/extensions/extension_updater.h +++ b/chrome/browser/extensions/extension_updater.h @@ -114,10 +114,6 @@ class ManifestFetchesBuilder { bool is_theme, GURL update_url); - // Calculates the value to use for the ping days parameter in manifest - // fetches for a given extension. - int CalculatePingDays(const std::string& extension_id); - ExtensionUpdateService* service_; // List of data on fetches we're going to do. We limit the number of diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc index 8865255..fd8a209 100644 --- a/chrome/browser/extensions/extension_updater_unittest.cc +++ b/chrome/browser/extensions/extension_updater_unittest.cc @@ -83,8 +83,8 @@ class MockService : public ExtensionUpdateService { last_ping_days_[extension_id] = time; } - virtual Time LastPingDay(const std::string& extension_id) { - std::map<std::string, Time>::iterator i = + virtual Time LastPingDay(const std::string& extension_id) const { + std::map<std::string, Time>::const_iterator i = last_ping_days_.find(extension_id); if (i != last_ping_days_.end()) return i->second; @@ -432,6 +432,7 @@ class ExtensionUpdaterTest : public testing::Test { EXPECT_EQ("com.google.crx.blacklist", params["id"]); EXPECT_EQ("0", params["v"]); EXPECT_EQ("", params["uc"]); + EXPECT_TRUE(ContainsKey(params, "ping")); } static void TestDetermineUpdates() { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 5bbb524..50d48d2 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -677,7 +677,8 @@ void ExtensionsService::SetLastPingDay(const std::string& extension_id, extension_prefs_->SetLastPingDay(extension_id, time); } -base::Time ExtensionsService::LastPingDay(const std::string& extension_id) { +base::Time ExtensionsService::LastPingDay( + const std::string& extension_id) const { return extension_prefs_->LastPingDay(extension_id); } diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 5bc356f..b56d7bd 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -83,7 +83,7 @@ class ExtensionUpdateService { // that we sent the 'ping' parameter during an update check. virtual void SetLastPingDay(const std::string& extension_id, const base::Time& time) = 0; - virtual base::Time LastPingDay(const std::string& extension_id) = 0; + virtual base::Time LastPingDay(const std::string& extension_id) const = 0; }; // Manages installed and running Chromium extensions. @@ -157,7 +157,7 @@ class ExtensionsService virtual void SetLastPingDay(const std::string& extension_id, const base::Time& time); - virtual base::Time LastPingDay(const std::string& extension_id); + virtual base::Time LastPingDay(const std::string& extension_id) const; // Whether this extension can run in an incognito window. bool IsIncognitoEnabled(const Extension* extension); |