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

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

Issue 2773593003: Revert of Extensions: Only create Web request rules registry if Declarative Web Request is enabled. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | extensions/common/features/complex_feature.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
15 #include "extensions/browser/api/declarative/rules_cache_delegate.h" 15 #include "extensions/browser/api/declarative/rules_cache_delegate.h"
16 #include "extensions/browser/api/declarative_content/content_rules_registry.h" 16 #include "extensions/browser/api/declarative_content/content_rules_registry.h"
17 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 17 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
18 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" 18 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h"
19 #include "extensions/browser/api/extensions_api_client.h" 19 #include "extensions/browser/api/extensions_api_client.h"
20 #include "extensions/browser/api/web_request/web_request_api.h" 20 #include "extensions/browser/api/web_request/web_request_api.h"
21 #include "extensions/browser/extension_registry.h" 21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
23 #include "extensions/common/features/feature_channel.h"
24 #include "extensions/common/features/feature_provider.h"
25 23
26 namespace extensions { 24 namespace extensions {
27 25
28 namespace { 26 namespace {
29 27
30 // Registers |web_request_rules_registry| on the IO thread. 28 // Registers |web_request_rules_registry| on the IO thread.
31 void RegisterToExtensionWebRequestEventRouterOnIO( 29 void RegisterToExtensionWebRequestEventRouterOnIO(
32 content::BrowserContext* browser_context, 30 content::BrowserContext* browser_context,
33 int rules_registry_id, 31 int rules_registry_id,
34 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { 32 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 int rules_registry_id) { 67 int rules_registry_id) {
70 if (!browser_context_) 68 if (!browser_context_)
71 return; 69 return;
72 RulesRegistryKey key(declarative_webrequest_constants::kOnRequest, 70 RulesRegistryKey key(declarative_webrequest_constants::kOnRequest,
73 rules_registry_id); 71 rules_registry_id);
74 // If we can find the key in the |rule_registries_| then we have already 72 // If we can find the key in the |rule_registries_| then we have already
75 // installed the default registries. 73 // installed the default registries.
76 if (ContainsKey(rule_registries_, key)) 74 if (ContainsKey(rule_registries_, key))
77 return; 75 return;
78 76
79 // Create a web request rules registry if declarative web request is enabled 77 // Only cache rules for regular pages.
80 // on the current channel. 78 RulesCacheDelegate* web_request_cache_delegate = NULL;
81 const Feature* declarative_web_request = 79 if (rules_registry_id == kDefaultRulesRegistryID) {
82 FeatureProvider::GetAPIFeature("declarativeWebRequest"); 80 // Create a RulesCacheDelegate.
83 if (declarative_web_request->IsAvailableToChannel(GetCurrentChannel()) 81 web_request_cache_delegate =
84 .is_available()) { 82 new RulesCacheDelegate(true /*log_storage_init_delay*/);
85 // Only cache rules for regular pages. 83 cache_delegates_.push_back(base::WrapUnique(web_request_cache_delegate));
86 RulesCacheDelegate* web_request_cache_delegate = nullptr; 84 }
87 if (rules_registry_id == kDefaultRulesRegistryID) { 85 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
88 // Create a RulesCacheDelegate. 86 new WebRequestRulesRegistry(browser_context_, web_request_cache_delegate,
89 web_request_cache_delegate = 87 rules_registry_id));
90 new RulesCacheDelegate(true /*log_storage_init_delay*/);
91 cache_delegates_.push_back(base::WrapUnique(web_request_cache_delegate));
92 }
93 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
94 new WebRequestRulesRegistry(
95 browser_context_, web_request_cache_delegate, rules_registry_id));
96 88
97 RegisterRulesRegistry(web_request_rules_registry); 89 RegisterRulesRegistry(web_request_rules_registry);
98 content::BrowserThread::PostTask( 90 content::BrowserThread::PostTask(
99 content::BrowserThread::IO, FROM_HERE, 91 content::BrowserThread::IO, FROM_HERE,
100 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 92 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
101 browser_context_, rules_registry_id, 93 browser_context_, rules_registry_id,
102 web_request_rules_registry)); 94 web_request_rules_registry));
103 }
104 95
105 // Only create a ContentRulesRegistry for regular pages. 96 // Only create a ContentRulesRegistry for regular pages.
106 if (rules_registry_id == kDefaultRulesRegistryID) { 97 if (rules_registry_id == kDefaultRulesRegistryID) {
107 RulesCacheDelegate* content_rules_cache_delegate = 98 RulesCacheDelegate* content_rules_cache_delegate =
108 new RulesCacheDelegate(false /*log_storage_init_delay*/); 99 new RulesCacheDelegate(false /*log_storage_init_delay*/);
109 cache_delegates_.push_back(base::WrapUnique(content_rules_cache_delegate)); 100 cache_delegates_.push_back(base::WrapUnique(content_rules_cache_delegate));
110 scoped_refptr<ContentRulesRegistry> content_rules_registry = 101 scoped_refptr<ContentRulesRegistry> content_rules_registry =
111 ExtensionsAPIClient::Get()->CreateContentRulesRegistry( 102 ExtensionsAPIClient::Get()->CreateContentRulesRegistry(
112 browser_context_, content_rules_cache_delegate); 103 browser_context_, content_rules_cache_delegate);
113 if (content_rules_registry.get() != nullptr) { 104 if (content_rules_registry.get() != nullptr) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 220 }
230 221
231 void RulesRegistryService::OnExtensionUninstalled( 222 void RulesRegistryService::OnExtensionUninstalled(
232 content::BrowserContext* browser_context, 223 content::BrowserContext* browser_context,
233 const Extension* extension, 224 const Extension* extension,
234 extensions::UninstallReason reason) { 225 extensions::UninstallReason reason) {
235 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension); 226 NotifyRegistriesHelper(&RulesRegistry::OnExtensionUninstalled, extension);
236 } 227 }
237 228
238 } // namespace extensions 229 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/common/features/complex_feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698