| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 NotifyRegistriesHelper(&RulesRegistry::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 |
| 200 void RulesRegistryService::Observe( | 205 void RulesRegistryService::Observe( |
| 201 int type, | 206 int type, |
| 202 const content::NotificationSource& source, | 207 const content::NotificationSource& source, |
| 203 const content::NotificationDetails& details) { | 208 const content::NotificationDetails& details) { |
| 204 switch (type) { | 209 switch (type) { |
| 205 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 210 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 206 const Extension* extension = | 211 const Extension* extension = |
| 207 content::Details<UnloadedExtensionInfo>(details)->extension; | 212 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 208 OnExtensionUnloaded(extension->id()); | 213 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, |
| 214 extension->id()); |
| 215 break; |
| 216 } |
| 217 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
| 218 const Extension* extension = |
| 219 content::Details<const Extension>(details).ptr(); |
| 220 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, |
| 221 extension->id()); |
| 222 break; |
| 223 } |
| 224 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
| 225 const Extension* extension = |
| 226 content::Details<const Extension>(details).ptr(); |
| 227 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, |
| 228 extension->id()); |
| 209 break; | 229 break; |
| 210 } | 230 } |
| 211 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | 231 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 212 content::RenderProcessHost* process = | 232 content::RenderProcessHost* process = |
| 213 content::Source<content::RenderProcessHost>(source).ptr(); | 233 content::Source<content::RenderProcessHost>(source).ptr(); |
| 214 RemoveWebViewRulesRegistries(process->GetID()); | 234 RemoveWebViewRulesRegistries(process->GetID()); |
| 215 break; | 235 break; |
| 216 } | 236 } |
| 217 default: | 237 default: |
| 218 NOTREACHED(); | 238 NOTREACHED(); |
| 219 break; | 239 break; |
| 220 } | 240 } |
| 221 } | 241 } |
| 222 | 242 |
| 223 } // namespace extensions | 243 } // namespace extensions |
| OLD | NEW |