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

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

Issue 16087006: Revert "Revert 202751 "Change RulesRegistryService to use ProfileKeyedAPI."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/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 11 matching lines...) Expand all
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 : content_rules_registry_(NULL), 36 : content_rules_registry_(NULL),
36 profile_(profile) { 37 profile_(profile) {
37 if (profile) { 38 if (profile) {
38 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
39 content::Source<Profile>(profile->GetOriginalProfile())); 40 content::Source<Profile>(profile->GetOriginalProfile()));
41 RegisterDefaultRulesRegistries();
40 } 42 }
41 } 43 }
42 44
43 RulesRegistryService::~RulesRegistryService() {} 45 RulesRegistryService::~RulesRegistryService() {}
44 46
45 void RulesRegistryService::RegisterDefaultRulesRegistries() { 47 void RulesRegistryService::RegisterDefaultRulesRegistries() {
46 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; 48 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part;
47 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 49 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
48 new WebRequestRulesRegistry(profile_, &ui_part)); 50 new WebRequestRulesRegistry(profile_, &ui_part));
49 ui_parts_of_registries_.push_back(ui_part.release()); 51 ui_parts_of_registries_.push_back(ui_part.release());
(...skipping 14 matching lines...) Expand all
64 #endif // defined(ENABLE_EXTENSIONS) 66 #endif // defined(ENABLE_EXTENSIONS)
65 } 67 }
66 68
67 void RulesRegistryService::Shutdown() { 69 void RulesRegistryService::Shutdown() {
68 content::BrowserThread::PostTask( 70 content::BrowserThread::PostTask(
69 content::BrowserThread::IO, FROM_HERE, 71 content::BrowserThread::IO, FROM_HERE,
70 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 72 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
71 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); 73 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL)));
72 } 74 }
73 75
76 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> >
77 g_factory = LAZY_INSTANCE_INITIALIZER;
78
79 // static
80 ProfileKeyedAPIFactory<RulesRegistryService>*
81 RulesRegistryService::GetFactoryInstance() {
82 return &g_factory.Get();
83 }
84
85 // static
86 RulesRegistryService* RulesRegistryService::Get(Profile* profile) {
87 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile);
88 }
89
74 void RulesRegistryService::RegisterRulesRegistry( 90 void RulesRegistryService::RegisterRulesRegistry(
75 scoped_refptr<RulesRegistry> rule_registry) { 91 scoped_refptr<RulesRegistry> rule_registry) {
76 const std::string event_name(rule_registry->event_name()); 92 const std::string event_name(rule_registry->event_name());
77 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 93 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
78 rule_registries_[event_name] = 94 rule_registries_[event_name] =
79 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); 95 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
80 } 96 }
81 97
82 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( 98 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
83 const std::string& event_name) const { 99 const std::string& event_name) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 OnExtensionUnloaded(extension->id()); 136 OnExtensionUnloaded(extension->id());
121 break; 137 break;
122 } 138 }
123 default: 139 default:
124 NOTREACHED(); 140 NOTREACHED();
125 break; 141 break;
126 } 142 }
127 } 143 }
128 144
129 } // namespace extensions 145 } // 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