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

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

Issue 49693003: Refactor RulesRegistryWithCache to RulesRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 7 years, 1 month 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/lazy_instance.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry. h" 12 #include "chrome/browser/extensions/api/declarative/rules_cache_delegate.h"
13 #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"
14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
15 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 15 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
(...skipping 15 matching lines...) Expand all
38 if (profile) { 38 if (profile) {
39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 39 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
40 content::Source<Profile>(profile->GetOriginalProfile())); 40 content::Source<Profile>(profile->GetOriginalProfile()));
41 RegisterDefaultRulesRegistries(); 41 RegisterDefaultRulesRegistries();
42 } 42 }
43 } 43 }
44 44
45 RulesRegistryService::~RulesRegistryService() {} 45 RulesRegistryService::~RulesRegistryService() {}
46 46
47 void RulesRegistryService::RegisterDefaultRulesRegistries() { 47 void RulesRegistryService::RegisterDefaultRulesRegistries() {
48 scoped_ptr<RulesRegistryWithCache::RuleStorageOnUI> ui_part; 48 scoped_ptr<RulesCacheDelegate> ui_part;
49 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 49 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
50 new WebRequestRulesRegistry(profile_, &ui_part)); 50 new WebRequestRulesRegistry(profile_, &ui_part));
51 ui_parts_of_registries_.push_back(ui_part.release()); 51 ui_parts_of_registries_.push_back(ui_part.release());
52 52
53 RegisterRulesRegistry(web_request_rules_registry); 53 RegisterRulesRegistry(web_request_rules_registry);
54 content::BrowserThread::PostTask( 54 content::BrowserThread::PostTask(
55 content::BrowserThread::IO, FROM_HERE, 55 content::BrowserThread::IO, FROM_HERE,
56 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 56 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
57 profile_, web_request_rules_registry)); 57 profile_, web_request_rules_registry));
58 58
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 // static 92 // static
93 RulesRegistryService* RulesRegistryService::Get(Profile* profile) { 93 RulesRegistryService* RulesRegistryService::Get(Profile* profile) {
94 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile); 94 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile);
95 } 95 }
96 96
97 void RulesRegistryService::RegisterRulesRegistry( 97 void RulesRegistryService::RegisterRulesRegistry(
98 scoped_refptr<RulesRegistry> rule_registry) { 98 scoped_refptr<RulesRegistry> rule_registry) {
99 const std::string event_name(rule_registry->event_name()); 99 const std::string event_name(rule_registry->event_name());
100 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); 100 DCHECK(rule_registries_.find(event_name) == rule_registries_.end());
101 rule_registries_[event_name] = 101 rule_registries_[event_name] = rule_registry;
102 make_scoped_refptr(new InitializingRulesRegistry(rule_registry));
103 } 102 }
104 103
105 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry( 104 scoped_refptr<RulesRegistry> RulesRegistryService::GetRulesRegistry(
106 const std::string& event_name) const { 105 const std::string& event_name) const {
107 RulesRegistryMap::const_iterator i = rule_registries_.find(event_name); 106 RulesRegistryMap::const_iterator i = rule_registries_.find(event_name);
108 if (i == rule_registries_.end()) 107 if (i == rule_registries_.end())
109 return scoped_refptr<RulesRegistry>(); 108 return scoped_refptr<RulesRegistry>();
110 return i->second; 109 return i->second;
111 } 110 }
112 111
(...skipping 30 matching lines...) Expand all
143 OnExtensionUnloaded(extension->id()); 142 OnExtensionUnloaded(extension->id());
144 break; 143 break;
145 } 144 }
146 default: 145 default:
147 NOTREACHED(); 146 NOTREACHED();
148 break; 147 break;
149 } 148 }
150 } 149 }
151 150
152 } // namespace extensions 151 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698