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

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

Issue 52743002: Declarative rules should be removed on uninstalling, not unloading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rewritten and rebased off https://codereview.chromium.org/64093010/ Created 7 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_registry_service.h" 5 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 RulesRegistryService::RulesRegistryService(Profile* profile) 43 RulesRegistryService::RulesRegistryService(Profile* profile)
44 : content_rules_registry_(NULL), 44 : content_rules_registry_(NULL),
45 profile_(profile) { 45 profile_(profile) {
46 if (profile) { 46 if (profile) {
47 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 47 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
48 content::Source<Profile>(profile->GetOriginalProfile())); 48 content::Source<Profile>(profile->GetOriginalProfile()));
49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
50 content::Source<Profile>(profile->GetOriginalProfile()));
51 registrar_.Add(this,
52 chrome::NOTIFICATION_EXTENSION_LOADED,
53 content::Source<Profile>(profile_->GetOriginalProfile()));
49 registrar_.Add( 54 registrar_.Add(
50 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 55 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
51 content::NotificationService::AllBrowserContextsAndSources()); 56 content::NotificationService::AllBrowserContextsAndSources());
52 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); 57 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0));
53 } 58 }
54 } 59 }
55 60
56 RulesRegistryService::~RulesRegistryService() {} 61 RulesRegistryService::~RulesRegistryService() {}
57 62
58 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered( 63 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Modifying the container while iterating is bad so we'll save the keys we 173 // Modifying the container while iterating is bad so we'll save the keys we
169 // wish to delete in another container, and delete them in another loop. 174 // wish to delete in another container, and delete them in another loop.
170 registries_to_delete.insert(key); 175 registries_to_delete.insert(key);
171 } 176 }
172 for (std::set<RulesRegistryKey>::iterator it = registries_to_delete.begin(); 177 for (std::set<RulesRegistryKey>::iterator it = registries_to_delete.begin();
173 it != registries_to_delete.end(); ++it) { 178 it != registries_to_delete.end(); ++it) {
174 rule_registries_.erase(*it); 179 rule_registries_.erase(*it);
175 } 180 }
176 } 181 }
177 182
178 void RulesRegistryService::SimulateExtensionUnloaded( 183 void RulesRegistryService::SimulateExtensionUninstalled(
179 const std::string& extension_id) { 184 const std::string& extension_id) {
180 OnExtensionUnloaded(extension_id); 185 OnExtensionUninstalled(extension_id);
181 } 186 }
182 187
183 void RulesRegistryService::OnExtensionUnloaded( 188 void RulesRegistryService::NotifyRegistriesHelper(
189 void (RulesRegistry::*notification_callback)(const std::string&),
184 const std::string& extension_id) { 190 const std::string& extension_id) {
185 RulesRegistryMap::iterator i; 191 RulesRegistryMap::iterator i;
186 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) { 192 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) {
187 scoped_refptr<RulesRegistry> registry = i->second; 193 scoped_refptr<RulesRegistry> registry = i->second;
188 if (content::BrowserThread::CurrentlyOn(registry->owner_thread())) { 194 if (content::BrowserThread::CurrentlyOn(registry->owner_thread())) {
189 registry->OnExtensionUnloaded(extension_id); 195 (registry->*notification_callback)(extension_id);
190 } else { 196 } else {
191 content::BrowserThread::PostTask( 197 content::BrowserThread::PostTask(
192 registry->owner_thread(), 198 registry->owner_thread(),
193 FROM_HERE, 199 FROM_HERE,
194 base::Bind( 200 base::Bind(notification_callback, registry, extension_id));
195 &RulesRegistry::OnExtensionUnloaded, registry, extension_id));
196 } 201 }
197 } 202 }
198 } 203 }
199 204
205 void RulesRegistryService::OnExtensionUninstalled(
Jeffrey Yasskin 2013/11/20 05:55:28 I would consider inlining these 1-line functions t
206 const std::string& extension_id) {
207 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension_id);
208 }
209
210 void RulesRegistryService::OnExtensionUnloaded(
211 const std::string& extension_id) {
212 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, extension_id);
213 }
214
215 void RulesRegistryService::OnExtensionLoaded(const std::string& extension_id) {
216 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, extension_id);
217 }
218
200 void RulesRegistryService::Observe( 219 void RulesRegistryService::Observe(
201 int type, 220 int type,
202 const content::NotificationSource& source, 221 const content::NotificationSource& source,
203 const content::NotificationDetails& details) { 222 const content::NotificationDetails& details) {
204 switch (type) { 223 switch (type) {
205 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 224 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
206 const Extension* extension = 225 const Extension* extension =
207 content::Details<UnloadedExtensionInfo>(details)->extension; 226 content::Details<UnloadedExtensionInfo>(details)->extension;
208 OnExtensionUnloaded(extension->id()); 227 OnExtensionUnloaded(extension->id());
209 break; 228 break;
210 } 229 }
230 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
231 const Extension* extension =
232 content::Details<const Extension>(details).ptr();
233 OnExtensionUninstalled(extension->id());
234 break;
235 }
236 case chrome::NOTIFICATION_EXTENSION_LOADED: {
237 const Extension* extension =
238 content::Details<const Extension>(details).ptr();
239 OnExtensionLoaded(extension->id());
240 break;
241 }
211 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 242 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
212 content::RenderProcessHost* process = 243 content::RenderProcessHost* process =
213 content::Source<content::RenderProcessHost>(source).ptr(); 244 content::Source<content::RenderProcessHost>(source).ptr();
214 RemoveWebViewRulesRegistries(process->GetID()); 245 RemoveWebViewRulesRegistries(process->GetID());
215 break; 246 break;
216 } 247 }
217 default: 248 default:
218 NOTREACHED(); 249 NOTREACHED();
219 break; 250 break;
220 } 251 }
221 } 252 }
222 253
223 } // namespace extensions 254 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698