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

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

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leaks Created 8 years, 9 months 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/logging.h" 8 #include "base/logging.h"
8 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h" 9 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h"
9 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
11 #include "content/public/browser/notification_details.h" 12 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_source.h" 13 #include "content/public/browser/notification_source.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 RulesRegistryService::RulesRegistryService(Profile* profile) { 17 RulesRegistryService::RulesRegistryService(Profile* profile) {
17 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 18 if (profile) {
18 content::Source<Profile>(profile)); 19 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
20 content::Source<Profile>(profile));
21 }
19 } 22 }
20 23
21 RulesRegistryService::~RulesRegistryService() {} 24 RulesRegistryService::~RulesRegistryService() {}
22 25
23 void RulesRegistryService::RegisterRulesRegistry( 26 void RulesRegistryService::RegisterRulesRegistry(
24 const std::string& event_name, 27 const std::string& event_name,
25 scoped_ptr<RulesRegistry> rule_registry) { 28 scoped_refptr<RulesRegistry> rule_registry) {
26 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 29 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
27 rule_registries_[event_name] = 30 rule_registries_[event_name] =
28 make_linked_ptr(new InitializingRulesRegistry(rule_registry.Pass())); 31 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
29 } 32 }
30 33
31 RulesRegistry* RulesRegistryService::GetRulesRegistry( 34 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
32 const std::string& event_name) const { 35 const std::string& event_name) const {
33 RulesRegistryMap::const_iterator i = rule_registries_.find(event_name); 36 RulesRegistryMap::const_iterator i = rule_registries_.find(event_name);
34 if (i == rule_registries_.end()) 37 if (i == rule_registries_.end())
35 return NULL; 38 return scoped_refptr<RulesRegistry>();
36 return i->second.get(); 39 return i->second;
40 }
41
42 void RulesRegistryService::SimulateExtensionUnloaded(
43 const std::string& extension_id) {
44 OnExtensionUnloaded(extension_id);
37 } 45 }
38 46
39 void RulesRegistryService::OnExtensionUnloaded( 47 void RulesRegistryService::OnExtensionUnloaded(
40 const std::string& extension_id) { 48 const std::string& extension_id) {
41 RulesRegistryMap::iterator i; 49 RulesRegistryMap::iterator i;
42 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) 50 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) {
43 i->second->OnExtensionUnloaded(extension_id); 51 scoped_refptr<RulesRegistry> registry = i->second;
52 if (content::BrowserThread::CurrentlyOn(registry->GetOwnerThread())) {
53 registry->OnExtensionUnloaded(extension_id);
54 } else {
55 content::BrowserThread::PostTask(
56 registry->GetOwnerThread(), FROM_HERE,
57 base::Bind(&RulesRegistry::OnExtensionUnloaded, registry,
58 extension_id));
59 }
60 }
44 } 61 }
45 62
46 void RulesRegistryService::Observe( 63 void RulesRegistryService::Observe(
47 int type, 64 int type,
48 const content::NotificationSource& source, 65 const content::NotificationSource& source,
49 const content::NotificationDetails& details) { 66 const content::NotificationDetails& details) {
50 switch (type) { 67 switch (type) {
51 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { 68 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
52 const Extension* extension = 69 const Extension* extension =
53 content::Details<UnloadedExtensionInfo>(details)->extension; 70 content::Details<UnloadedExtensionInfo>(details)->extension;
54 OnExtensionUnloaded(extension->id()); 71 OnExtensionUnloaded(extension->id());
55 break; 72 break;
56 } 73 }
57 default: 74 default:
58 NOTREACHED(); 75 NOTREACHED();
76 break;
59 } 77 }
60 } 78 }
61 79
62 } // namespace extensions 80 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698