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

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: Fixed Created 7 years, 7 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 "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h" 11 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h"
11 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" 12 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h"
12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 14 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
(...skipping 10 matching lines...) Expand all
28 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( 29 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry(
29 profile, web_request_rules_registry); 30 profile, web_request_rules_registry);
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 RulesRegistryService::RulesRegistryService(Profile* profile) 35 RulesRegistryService::RulesRegistryService(Profile* profile)
35 : profile_(profile) { 36 : profile_(profile) {
36 if (profile) { 37 if (profile) {
37 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 38 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
38 content::Source<Profile>(profile->GetOriginalProfile())); 39 content::Source<Profile>(profile->GetOriginalProfile()));
40 RegisterDefaultRulesRegistries();
39 } 41 }
40 } 42 }
41 43
42 RulesRegistryService::~RulesRegistryService() {} 44 RulesRegistryService::~RulesRegistryService() {}
43 45
44 void RulesRegistryService::RegisterDefaultRulesRegistries() { 46 void RulesRegistryService::RegisterDefaultRulesRegistries() {
45 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; 47 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part;
46 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 48 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
47 new WebRequestRulesRegistry(profile_, &ui_part)); 49 new WebRequestRulesRegistry(profile_, &ui_part));
48 ui_parts_of_registries_.push_back(ui_part.release()); 50 ui_parts_of_registries_.push_back(ui_part.release());
(...skipping 14 matching lines...) Expand all
63 #endif // defined(ENABLE_EXTENSIONS) 65 #endif // defined(ENABLE_EXTENSIONS)
64 } 66 }
65 67
66 void RulesRegistryService::Shutdown() { 68 void RulesRegistryService::Shutdown() {
67 content::BrowserThread::PostTask( 69 content::BrowserThread::PostTask(
68 content::BrowserThread::IO, FROM_HERE, 70 content::BrowserThread::IO, FROM_HERE,
69 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 71 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
70 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); 72 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL)));
71 } 73 }
72 74
75 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> >
76 g_factory = LAZY_INSTANCE_INITIALIZER;
77
78 // static
79 ProfileKeyedAPIFactory<RulesRegistryService>*
80 RulesRegistryService::GetFactoryInstance() {
81 return &g_factory.Get();
82 }
83
84 // static
85 RulesRegistryService* RulesRegistryService::Get(Profile* profile) {
86 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile);
87 }
88
73 void RulesRegistryService::RegisterRulesRegistry( 89 void RulesRegistryService::RegisterRulesRegistry(
74 scoped_refptr<RulesRegistry> rule_registry) { 90 scoped_refptr<RulesRegistry> rule_registry) {
75 const std::string event_name(rule_registry->event_name()); 91 const std::string event_name(rule_registry->event_name());
76 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 92 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
77 rule_registries_[event_name] = 93 rule_registries_[event_name] =
78 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); 94 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
79 } 95 }
80 96
81 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( 97 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
82 const std::string& event_name) const { 98 const std::string& event_name) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 OnExtensionUnloaded(extension->id()); 135 OnExtensionUnloaded(extension->id());
120 break; 136 break;
121 } 137 }
122 default: 138 default:
123 NOTREACHED(); 139 NOTREACHED();
124 break; 140 break;
125 } 141 }
126 } 142 }
127 143
128 } // namespace extensions 144 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/declarative/rules_registry_service.h ('k') | chrome/browser/extensions/extension_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698