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

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

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add thread safety to extensionregistry notifications Created 5 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
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 "extensions/browser/api/declarative/rules_registry_service.h" 5 #include "extensions/browser/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"
(...skipping 14 matching lines...) Expand all
25 25
26 // Registers |web_request_rules_registry| on the IO thread. 26 // Registers |web_request_rules_registry| on the IO thread.
27 void RegisterToExtensionWebRequestEventRouterOnIO( 27 void RegisterToExtensionWebRequestEventRouterOnIO(
28 content::BrowserContext* browser_context, 28 content::BrowserContext* browser_context,
29 int rules_registry_id, 29 int rules_registry_id,
30 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { 30 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) {
31 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( 31 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry(
32 browser_context, rules_registry_id, web_request_rules_registry); 32 browser_context, rules_registry_id, web_request_rules_registry);
33 } 33 }
34 34
35 void NotifyWithExtensionSafe(
36 scoped_refptr<const Extension> extension,
37 void (RulesRegistry::*notification_callback)(const Extension*),
38 scoped_refptr<RulesRegistry> registry) {
39 (registry.get()->*notification_callback)(extension.get());
40 }
41
35 } // namespace 42 } // namespace
36 43
37 const int RulesRegistryService::kDefaultRulesRegistryID = 0; 44 const int RulesRegistryService::kDefaultRulesRegistryID = 0;
38 const int RulesRegistryService::kInvalidRulesRegistryID = -1; 45 const int RulesRegistryService::kInvalidRulesRegistryID = -1;
39 46
40 RulesRegistryService::RulesRegistryService(content::BrowserContext* context) 47 RulesRegistryService::RulesRegistryService(content::BrowserContext* context)
41 : current_rules_registry_id_(kDefaultRulesRegistryID), 48 : current_rules_registry_id_(kDefaultRulesRegistryID),
42 content_rules_registry_(NULL), 49 content_rules_registry_(NULL),
43 extension_registry_observer_(this), 50 extension_registry_observer_(this),
44 browser_context_(context) { 51 browser_context_(context) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 registries_to_delete.insert(key); 169 registries_to_delete.insert(key);
163 } 170 }
164 171
165 for (std::set<RulesRegistryKey>::iterator it = registries_to_delete.begin(); 172 for (std::set<RulesRegistryKey>::iterator it = registries_to_delete.begin();
166 it != registries_to_delete.end(); ++it) { 173 it != registries_to_delete.end(); ++it) {
167 rule_registries_.erase(*it); 174 rule_registries_.erase(*it);
168 } 175 }
169 } 176 }
170 177
171 void RulesRegistryService::SimulateExtensionUninstalled( 178 void RulesRegistryService::SimulateExtensionUninstalled(
172 const std::string& extension_id) { 179 const Extension* extension) {
173 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension_id); 180 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension);
174 } 181 }
175 182
176 void RulesRegistryService::NotifyRegistriesHelper( 183 void RulesRegistryService::NotifyRegistriesHelper(
177 void (RulesRegistry::*notification_callback)(const std::string&), 184 void (RulesRegistry::*notification_callback)(const Extension*),
178 const std::string& extension_id) { 185 const Extension* extension) {
179 RulesRegistryMap::iterator i; 186 RulesRegistryMap::iterator i;
180 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) { 187 for (i = rule_registries_.begin(); i != rule_registries_.end(); ++i) {
181 scoped_refptr<RulesRegistry> registry = i->second; 188 scoped_refptr<RulesRegistry> registry = i->second;
182 if (content::BrowserThread::CurrentlyOn(registry->owner_thread())) { 189 if (content::BrowserThread::CurrentlyOn(registry->owner_thread())) {
183 (registry.get()->*notification_callback)(extension_id); 190 (registry.get()->*notification_callback)(extension);
184 } else { 191 } else {
185 content::BrowserThread::PostTask( 192 content::BrowserThread::PostTask(
186 registry->owner_thread(), 193 registry->owner_thread(), FROM_HERE,
187 FROM_HERE, 194 base::Bind(&NotifyWithExtensionSafe, make_scoped_refptr(extension),
188 base::Bind(notification_callback, registry, extension_id)); 195 notification_callback, registry));
189 } 196 }
190 } 197 }
191 } 198 }
192 199
193 void RulesRegistryService::OnExtensionLoaded( 200 void RulesRegistryService::OnExtensionLoaded(
194 content::BrowserContext* browser_context, 201 content::BrowserContext* browser_context,
195 const Extension* extension) { 202 const Extension* extension) {
196 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, extension->id()); 203 NotifyRegistriesHelper(&RulesRegistry::OnExtensionLoaded, extension);
197 } 204 }
198 205
199 void RulesRegistryService::OnExtensionUnloaded( 206 void RulesRegistryService::OnExtensionUnloaded(
200 content::BrowserContext* browser_context, 207 content::BrowserContext* browser_context,
201 const Extension* extension, 208 const Extension* extension,
202 UnloadedExtensionInfo::Reason reason) { 209 UnloadedExtensionInfo::Reason reason) {
203 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, extension->id()); 210 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUnloaded, extension);
204 } 211 }
205 212
206 void RulesRegistryService::OnExtensionUninstalled( 213 void RulesRegistryService::OnExtensionUninstalled(
207 content::BrowserContext* browser_context, 214 content::BrowserContext* browser_context,
208 const Extension* extension, 215 const Extension* extension,
209 extensions::UninstallReason reason) { 216 extensions::UninstallReason reason) {
210 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, 217 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension);
211 extension->id());
212 } 218 }
213 219
214 } // namespace extensions 220 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698