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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_cache_delegate.cc

Issue 52743002: Declarative rules should be removed on uninstalling, not unloading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further comments addressed Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/api/declarative/rules_cache_delegate.h" 5 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/api/declarative/rules_registry.h" 8 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 profile_->IsOffTheRecord()); 72 profile_->IsOffTheRecord());
73 rules_stored_key_ = GetRulesStoredKey(registry->event_name(), 73 rules_stored_key_ = GetRulesStoredKey(registry->event_name(),
74 profile_->IsOffTheRecord()); 74 profile_->IsOffTheRecord());
75 rules_registry_thread_ = registry->owner_thread(); 75 rules_registry_thread_ = registry->owner_thread();
76 76
77 ExtensionSystem& system = *ExtensionSystem::Get(profile_); 77 ExtensionSystem& system = *ExtensionSystem::Get(profile_);
78 extensions::StateStore* store = system.rules_store(); 78 extensions::StateStore* store = system.rules_store();
79 if (store) 79 if (store)
80 store->RegisterKey(storage_key_); 80 store->RegisterKey(storage_key_);
81 81
82 registrar_.Add(this,
83 chrome::NOTIFICATION_EXTENSION_LOADED,
84 content::Source<Profile>(profile_->GetOriginalProfile()));
85
86 if (profile_->IsOffTheRecord()) 82 if (profile_->IsOffTheRecord())
87 log_storage_init_delay_ = false; 83 log_storage_init_delay_ = false;
88 84
89 system.ready().Post( 85 system.ready().Post(
90 FROM_HERE, 86 FROM_HERE,
91 base::Bind(&RulesCacheDelegate::ReadRulesForInstalledExtensions, 87 base::Bind(&RulesCacheDelegate::ReadRulesForInstalledExtensions,
92 weak_ptr_factory_.GetWeakPtr())); 88 weak_ptr_factory_.GetWeakPtr()));
93 system.ready().Post(FROM_HERE, 89 system.ready().Post(FROM_HERE,
94 base::Bind(&RulesCacheDelegate::CheckIfReady, 90 base::Bind(&RulesCacheDelegate::CheckIfReady,
95 weak_ptr_factory_.GetWeakPtr())); 91 weak_ptr_factory_.GetWeakPtr()));
(...skipping 11 matching lines...) Expand all
107 bool store_rules = !rules->empty(); 103 bool store_rules = !rules->empty();
108 SetDeclarativeRulesStored(extension_id, store_rules); 104 SetDeclarativeRulesStored(extension_id, store_rules);
109 if (!rules_stored_previously && !store_rules) 105 if (!rules_stored_previously && !store_rules)
110 return; 106 return;
111 107
112 StateStore* store = ExtensionSystem::Get(profile_)->rules_store(); 108 StateStore* store = ExtensionSystem::Get(profile_)->rules_store();
113 if (store) 109 if (store)
114 store->SetExtensionValue(extension_id, storage_key_, value.Pass()); 110 store->SetExtensionValue(extension_id, storage_key_, value.Pass());
115 } 111 }
116 112
117 void RulesCacheDelegate::Observe(
118 int type,
119 const content::NotificationSource& source,
120 const content::NotificationDetails& details) {
121 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
122 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_LOADED, type);
123
124 const extensions::Extension* extension =
125 content::Details<const extensions::Extension>(details).ptr();
126 // TODO(mpcomplete): This API check should generalize to any use of
127 // declarative rules, not just webRequest.
128 if (extension->HasAPIPermission(APIPermission::kDeclarativeContent) ||
129 extension->HasAPIPermission(APIPermission::kDeclarativeWebRequest)) {
130 InfoMap* extension_info_map = ExtensionSystem::Get(profile_)->info_map();
131 if (profile_->IsOffTheRecord() &&
132 !extension_info_map->IsIncognitoEnabled(extension->id())) {
133 // Ignore this extension.
134 } else {
135 ReadFromStorage(extension->id());
136 }
137 }
138 }
139
140 void RulesCacheDelegate::CheckIfReady() { 113 void RulesCacheDelegate::CheckIfReady() {
141 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
142 if (notified_registry_ || !waiting_for_extensions_.empty()) 115 if (notified_registry_ || !waiting_for_extensions_.empty())
143 return; 116 return;
144 117
145 content::BrowserThread::PostTask( 118 content::BrowserThread::PostTask(
146 rules_registry_thread_, 119 rules_registry_thread_,
147 FROM_HERE, 120 FROM_HERE,
148 base::Bind( 121 base::Bind(
149 &RulesRegistry::MarkReady, registry_, storage_init_time_)); 122 &RulesRegistry::MarkReady, registry_, storage_init_time_));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 bool rules_stored) { 214 bool rules_stored) {
242 CHECK(profile_); 215 CHECK(profile_);
243 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_); 216 ExtensionScopedPrefs* extension_prefs = ExtensionPrefs::Get(profile_);
244 extension_prefs->UpdateExtensionPref( 217 extension_prefs->UpdateExtensionPref(
245 extension_id, 218 extension_id,
246 rules_stored_key_, 219 rules_stored_key_,
247 new base::FundamentalValue(rules_stored)); 220 new base::FundamentalValue(rules_stored));
248 } 221 }
249 222
250 } // namespace extensions 223 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698