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

Unified Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10941003: Reset registered events and dispatch runtime.onInstalled to all extensions when (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ? Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_prefs.cc
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 3b536c0064e02ec4ec87ea3d52e3432c1f82d19b..8ffc17960ca975fbedb83bdf370bcd4bb8cbd0ba 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -4,9 +4,11 @@
#include "chrome/browser/extensions/extension_prefs.h"
+#include "base/command_line.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "base/version.h"
#include "chrome/browser/extensions/admin_policy.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/browser/extensions/extension_pref_store.h"
@@ -15,6 +17,8 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/extension_switch_utils.h"
#include "chrome/common/extensions/manifest.h"
#include "chrome/common/extensions/permissions/permission_set.h"
@@ -205,6 +209,9 @@ const char kMediaGalleryIdKey[] = "id";
// Key for Media Gallery Permission Value.
const char kMediaGalleryHasPermissionKey[] = "has_permission";
+// Key for what version chrome was last time the extension prefs were loaded.
+const char kExtensionsLastChromeVersion[] = "extensions.last_chrome_version";
+
// Provider of write access to a dictionary storing extension prefs.
class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
public:
@@ -960,6 +967,17 @@ void ExtensionPrefs::MigrateDisableReasons(
}
}
+void ExtensionPrefs::ClearRegisteredEvents() {
+ const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
+ if (!extensions)
+ return;
+
+ for (DictionaryValue::key_iterator it = extensions->begin_keys();
+ it != extensions->end_keys(); ++it) {
+ UpdateExtensionPref(*it, kRegisteredEvents, NULL);
+ }
+}
+
PermissionSet* ExtensionPrefs::GetGrantedPermissions(
const std::string& extension_id) {
CHECK(Extension::IdIsValid(extension_id));
@@ -1015,6 +1033,30 @@ void ExtensionPrefs::SetActivePermissions(
extension_id, kPrefActivePermissions, permissions);
}
+bool ExtensionPrefs::CheckRegisteredEventsUpToDate() {
+ // If we're running inside a test, then assume prefs are all up-to-date.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType))
Matt Perry 2012/09/19 23:32:46 I had to add this bit to fix the chromeos tests. C
+ return true;
+
+ Version version;
+ if (prefs_->HasPrefPath(kExtensionsLastChromeVersion)) {
+ std::string version_str = prefs_->GetString(kExtensionsLastChromeVersion);
+ version = Version(version_str);
+ }
+
+ chrome::VersionInfo current_version_info;
+ std::string current_version = current_version_info.Version();
+ prefs_->SetString(kExtensionsLastChromeVersion, current_version);
+
+ // If there was no version string in prefs, assume we're out of date.
+ if (!version.IsValid() || version.IsOlderThan(current_version)) {
+ ClearRegisteredEvents();
+ return false;
+ }
+
+ return true;
+}
+
std::set<std::string> ExtensionPrefs::GetRegisteredEvents(
const std::string& extension_id) {
std::set<std::string> events;
@@ -2140,6 +2182,9 @@ void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
PrefService::UNSYNCABLE_PREF);
prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
PrefService::UNSYNCABLE_PREF);
+ prefs->RegisterStringPref(kExtensionsLastChromeVersion,
+ std::string(), // default value
+ PrefService::UNSYNCABLE_PREF);
}
ExtensionPrefs::ExtensionIds ExtensionPrefs::GetExtensionPrefAsVector(
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698