| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry.
h" |
| 9 #include "chrome/common/chrome_notification_types.h" |
| 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "content/public/browser/notification_details.h" |
| 12 #include "content/public/browser/notification_source.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 RulesRegistryService::RulesRegistryService(Profile* profile) { |
| 17 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 18 content::Source<Profile>(profile)); |
| 19 } |
| 20 |
| 21 RulesRegistryService::~RulesRegistryService() {} |
| 22 |
| 23 void RulesRegistryService::RegisterRulesRegistry( |
| 24 const std::string& event_name, |
| 25 scoped_ptr<RulesRegistry> rule_registry) { |
| 26 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); |
| 27 rule_registries_[event_name] = |
| 28 make_linked_ptr(new InitializingRulesRegistry(rule_registry.Pass())); |
| 29 } |
| 30 |
| 31 RulesRegistry* RulesRegistryService::GetRulesRegistry( |
| 32 const std::string& event_name) const { |
| 33 RulesRegistryMap::const_iterator i = rule_registries_.find(event_name); |
| 34 if (i == rule_registries_.end()) |
| 35 return NULL; |
| 36 return i->second.get(); |
| 37 } |
| 38 |
| 39 void RulesRegistryService::OnExtensionUnloaded( |
| 40 const std::string& extension_id) { |
| 41 RulesRegistryMap::iterator i; |
| 42 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) |
| 43 i->second->OnExtensionUnloaded(extension_id); |
| 44 } |
| 45 |
| 46 void RulesRegistryService::Observe( |
| 47 int type, |
| 48 const content::NotificationSource& source, |
| 49 const content::NotificationDetails& details) { |
| 50 switch (type) { |
| 51 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
| 52 const Extension* extension = |
| 53 content::Details<UnloadedExtensionInfo>(details)->extension; |
| 54 OnExtensionUnloaded(extension->id()); |
| 55 break; |
| 56 } |
| 57 default: |
| 58 NOTREACHED(); |
| 59 } |
| 60 } |
| 61 |
| 62 } // namespace extensions |
| OLD | NEW |