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

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: Moved functionality from InitForOTR into RulesRegistryService constructor 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 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 : 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 if (profile->HasOffTheRecordProfile() &&
41 profile->GetOffTheRecordProfile() == profile) {
42
43 // Only initialize the RulesRegistryService for a OTR profile
44 // if the regular ExtensionSystem has been initialized properly, as we
45 // depend on it. Some ChromeOS browser tests don't initialize the
46 // regular ExtensionSystem in login-tests. Currently these browser
47 // tests are EnterpriseLoginBlocksForEnterpriseUser and
Yoyo Zhou 2013/05/09 01:08:54 You don't have to name these tests here; this comm
48 // NormalLoginDoesntBlock.
49 if (ExtensionSystem::Get(profile)->extension_service())
50 RegisterDefaultRulesRegistries();
51 } else {
52 RegisterDefaultRulesRegistries();
53 }
39 } 54 }
40 } 55 }
41 56
42 RulesRegistryService::~RulesRegistryService() {} 57 RulesRegistryService::~RulesRegistryService() {}
43 58
44 void RulesRegistryService::RegisterDefaultRulesRegistries() { 59 void RulesRegistryService::RegisterDefaultRulesRegistries() {
45 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; 60 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part;
46 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 61 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
47 new WebRequestRulesRegistry(profile_, &ui_part)); 62 new WebRequestRulesRegistry(profile_, &ui_part));
48 ui_parts_of_registries_.push_back(ui_part.release()); 63 ui_parts_of_registries_.push_back(ui_part.release());
(...skipping 14 matching lines...) Expand all
63 #endif // defined(ENABLE_EXTENSIONS) 78 #endif // defined(ENABLE_EXTENSIONS)
64 } 79 }
65 80
66 void RulesRegistryService::Shutdown() { 81 void RulesRegistryService::Shutdown() {
67 content::BrowserThread::PostTask( 82 content::BrowserThread::PostTask(
68 content::BrowserThread::IO, FROM_HERE, 83 content::BrowserThread::IO, FROM_HERE,
69 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 84 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
70 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); 85 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL)));
71 } 86 }
72 87
88 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> >
89 g_factory = LAZY_INSTANCE_INITIALIZER;
90
91 // static
92 ProfileKeyedAPIFactory<RulesRegistryService>*
93 RulesRegistryService::GetFactoryInstance() {
94 return &g_factory.Get();
95 }
96
97 // static
98 RulesRegistryService* RulesRegistryService::Get(Profile* profile) {
99 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile);
100 }
101
73 void RulesRegistryService::RegisterRulesRegistry( 102 void RulesRegistryService::RegisterRulesRegistry(
74 scoped_refptr<RulesRegistry> rule_registry) { 103 scoped_refptr<RulesRegistry> rule_registry) {
75 const std::string event_name(rule_registry->event_name()); 104 const std::string event_name(rule_registry->event_name());
76 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 105 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
77 rule_registries_[event_name] = 106 rule_registries_[event_name] =
78 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); 107 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
79 } 108 }
80 109
81 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( 110 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
82 const std::string& event_name) const { 111 const std::string& event_name) const {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 OnExtensionUnloaded(extension->id()); 148 OnExtensionUnloaded(extension->id());
120 break; 149 break;
121 } 150 }
122 default: 151 default:
123 NOTREACHED(); 152 NOTREACHED();
124 break; 153 break;
125 } 154 }
126 } 155 }
127 156
128 } // namespace extensions 157 } // 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