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

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

Issue 13825014: Change RulesRegistryService to use ProfileKeyedAPI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added static comment Created 7 years, 8 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
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/logging.h" 9 #include "base/logging.h"
9 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h" 10 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h"
10 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg ate.h" 11 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg ate.h"
11 #include "chrome/browser/extensions/api/declarative_content/content_constants.h" 12 #include "chrome/browser/extensions/api/declarative_content/content_constants.h"
12 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" 13 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h"
13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
15 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
(...skipping 22 matching lines...) Expand all
40 profile, web_request_rules_registry); 41 profile, web_request_rules_registry);
41 } 42 }
42 43
43 } // namespace 44 } // namespace
44 45
45 RulesRegistryService::RulesRegistryService(Profile* profile) 46 RulesRegistryService::RulesRegistryService(Profile* profile)
46 : profile_(profile) { 47 : profile_(profile) {
47 if (profile) { 48 if (profile) {
48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
49 content::Source<Profile>(profile->GetOriginalProfile())); 50 content::Source<Profile>(profile->GetOriginalProfile()));
51 RegisterDefaultRulesRegistries();
50 } 52 }
51 } 53 }
52 54
53 RulesRegistryService::~RulesRegistryService() { 55 RulesRegistryService::~RulesRegistryService() {
54 for (size_t i = 0; i < delegates_.size(); ++i) 56 for (size_t i = 0; i < delegates_.size(); ++i)
55 delegates_[i]->CleanupOnUIThread(); 57 delegates_[i]->CleanupOnUIThread();
56 } 58 }
57 59
58 void RulesRegistryService::RegisterDefaultRulesRegistries() { 60 void RulesRegistryService::RegisterDefaultRulesRegistries() {
59 RulesRegistryStorageDelegate* delegate = new RulesRegistryStorageDelegate(); 61 RulesRegistryStorageDelegate* delegate = new RulesRegistryStorageDelegate();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 #endif // defined(ENABLE_EXTENSIONS) 94 #endif // defined(ENABLE_EXTENSIONS)
93 } 95 }
94 96
95 void RulesRegistryService::Shutdown() { 97 void RulesRegistryService::Shutdown() {
96 content::BrowserThread::PostTask( 98 content::BrowserThread::PostTask(
97 content::BrowserThread::IO, FROM_HERE, 99 content::BrowserThread::IO, FROM_HERE,
98 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 100 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
99 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); 101 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL)));
100 } 102 }
101 103
104 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> >
105 g_factory = LAZY_INSTANCE_INITIALIZER;
106
107 // static
108 ProfileKeyedAPIFactory<RulesRegistryService>*
109 RulesRegistryService::GetFactoryInstance() {
110 return &g_factory.Get();
111 }
112
113 // static
114 RulesRegistryService* RulesRegistryService::Get(Profile* profile) {
115 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile);
116 }
117
102 void RulesRegistryService::RegisterRulesRegistry( 118 void RulesRegistryService::RegisterRulesRegistry(
103 const std::string& event_name, 119 const std::string& event_name,
104 scoped_refptr<RulesRegistry> rule_registry) { 120 scoped_refptr<RulesRegistry> rule_registry) {
105 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 121 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
106 rule_registries_[event_name] = 122 rule_registries_[event_name] =
107 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); 123 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
108 } 124 }
109 125
110 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( 126 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
111 const std::string& event_name) const { 127 const std::string& event_name) const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 OnExtensionUnloaded(extension->id()); 163 OnExtensionUnloaded(extension->id());
148 break; 164 break;
149 } 165 }
150 default: 166 default:
151 NOTREACHED(); 167 NOTREACHED();
152 break; 168 break;
153 } 169 }
154 } 170 }
155 171
156 } // namespace extensions 172 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698