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

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

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

Powered by Google App Engine
This is Rietveld 408576698