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

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

Issue 11415216: Make Blacklist::IsBlacklist asynchronous (it will need to be for safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another test Created 8 years 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_prefs_unittest.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 346133dce690ee6a59a9c85cbbf9a63e2ab63867..b55643949a3ac08ca4d808f096f0567640ba204e 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -748,57 +748,48 @@ void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) {
UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL);
}
-void ExtensionPrefs::UpdateBlacklist(
- const std::set<std::string>& blacklist_set) {
- ExtensionIdList remove_pref_ids;
- std::set<std::string> used_id_set;
+std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() {
+ std::set<std::string> ids;
+
const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
+ if (!extensions)
+ return ids;
- if (extensions) {
- for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
- extension_id != extensions->end_keys(); ++extension_id) {
- const DictionaryValue* ext;
- if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) {
- NOTREACHED() << "Invalid pref for extension " << *extension_id;
- continue;
- }
- const std::string& id(*extension_id);
- if (blacklist_set.find(id) == blacklist_set.end()) {
- if (!IsBlacklistBitSet(ext)) {
- // This extension is not in blacklist. And it was not blacklisted
- // before.
- continue;
- } else {
- if (ext->size() == 1) {
- // We should remove the entry if the only flag here is blacklist.
- remove_pref_ids.push_back(id);
- } else {
- // Remove the blacklist bit.
- UpdateExtensionPref(id, kPrefBlacklist, NULL);
- }
- }
- } else {
- if (!IsBlacklistBitSet(ext)) {
- // Only set the blacklist if it was not set.
- UpdateExtensionPref(id, kPrefBlacklist,
- Value::CreateBooleanValue(true));
- }
- // Keep the record if this extension is already processed.
- used_id_set.insert(id);
- }
+ for (DictionaryValue::Iterator it(*extensions); it.HasNext(); it.Advance()) {
+ if (!it.value().IsType(Value::TYPE_DICTIONARY)) {
+ NOTREACHED() << "Invalid pref for extension " << it.key();
+ continue;
}
+ if (IsBlacklistBitSet(static_cast<const DictionaryValue*>(&it.value())))
+ ids.insert(it.key());
}
- // Iterate the leftovers to set blacklist in pref
- std::set<std::string>::const_iterator set_itr = blacklist_set.begin();
- for (; set_itr != blacklist_set.end(); ++set_itr) {
- if (used_id_set.find(*set_itr) == used_id_set.end()) {
- UpdateExtensionPref(*set_itr, kPrefBlacklist,
- Value::CreateBooleanValue(true));
- }
+ return ids;
+}
+
+void ExtensionPrefs::SetExtensionBlacklisted(const std::string& extension_id,
+ bool is_blacklisted) {
+ bool currently_blacklisted = IsExtensionBlacklisted(extension_id);
+ if (is_blacklisted == currently_blacklisted) {
+ NOTREACHED() << extension_id << " is " <<
+ (currently_blacklisted ? "already" : "not") <<
+ " blacklisted";
+ return;
}
- for (size_t i = 0; i < remove_pref_ids.size(); ++i) {
- DeleteExtensionPrefs(remove_pref_ids[i]);
+
+ // Always make sure the "acknowledged" bit is cleared since the blacklist bit
+ // is changing.
+ UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, NULL);
+
+ if (is_blacklisted) {
+ UpdateExtensionPref(extension_id,
+ kPrefBlacklist,
+ new base::FundamentalValue(true));
+ } else {
+ UpdateExtensionPref(extension_id, kPrefBlacklist, NULL);
+ const DictionaryValue* dict = GetExtensionPref(extension_id);
+ if (dict && dict->empty())
+ DeleteExtensionPrefs(extension_id);
}
}
@@ -1656,8 +1647,6 @@ scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
if (!extensions ||
!extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
return scoped_ptr<ExtensionInfo>();
- if (IsBlacklistBitSet(ext))
- return scoped_ptr<ExtensionInfo>();
int state_value;
if (!ext->GetInteger(kPrefState, &state_value) ||
state_value == Extension::ENABLED_COMPONENT) {
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698