OLD | NEW |
---|---|
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 "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" |
11 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" | |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
14 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
15 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
18 #include "extensions/browser/api/declarative/rules_cache_delegate.h" | 17 #include "extensions/browser/api/declarative/rules_cache_delegate.h" |
18 #include "extensions/browser/api/declarative_content/content_rules_registry.h" | |
19 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 19 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
20 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" | 20 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" |
21 #include "extensions/browser/api/extensions_api_client.h" | |
21 #include "extensions/browser/api/web_request/web_request_api.h" | 22 #include "extensions/browser/api/web_request/web_request_api.h" |
22 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
24 | 25 |
25 namespace extensions { | 26 namespace extensions { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Registers |web_request_rules_registry| on the IO thread. | 30 // Registers |web_request_rules_registry| on the IO thread. |
30 void RegisterToExtensionWebRequestEventRouterOnIO( | 31 void RegisterToExtensionWebRequestEventRouterOnIO( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 content::BrowserThread::PostTask( | 85 content::BrowserThread::PostTask( |
85 content::BrowserThread::IO, FROM_HERE, | 86 content::BrowserThread::IO, FROM_HERE, |
86 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, | 87 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, |
87 browser_context_, webview_key, web_request_rules_registry)); | 88 browser_context_, webview_key, web_request_rules_registry)); |
88 | 89 |
89 // Only create a ContentRulesRegistry for regular pages and not webviews. | 90 // Only create a ContentRulesRegistry for regular pages and not webviews. |
90 if (!IsWebView(webview_key)) { | 91 if (!IsWebView(webview_key)) { |
91 RulesCacheDelegate* content_rules_cache_delegate = | 92 RulesCacheDelegate* content_rules_cache_delegate = |
92 new RulesCacheDelegate(false /*log_storage_init_delay*/); | 93 new RulesCacheDelegate(false /*log_storage_init_delay*/); |
93 cache_delegates_.push_back(content_rules_cache_delegate); | 94 cache_delegates_.push_back(content_rules_cache_delegate); |
94 scoped_refptr<ContentRulesRegistry> content_rules_registry( | 95 scoped_refptr<ContentRulesRegistry> content_rules_registry = |
95 new ContentRulesRegistry(browser_context_, | 96 ExtensionsAPIClient::Get()->GetContentRulesRegistry( |
Fady Samuel
2014/09/23 15:04:50
nit: Could we please rename this CreateContentRule
wjmaclean
2014/09/23 15:19:04
Sure, good point!
Done.
| |
96 content_rules_cache_delegate)); | 97 browser_context_, content_rules_cache_delegate); |
97 RegisterRulesRegistry(content_rules_registry); | 98 RegisterRulesRegistry(content_rules_registry); |
98 content_rules_registry_ = content_rules_registry.get(); | 99 content_rules_registry_ = content_rules_registry.get(); |
99 } | 100 } |
100 } | 101 } |
101 | 102 |
102 void RulesRegistryService::Shutdown() { | 103 void RulesRegistryService::Shutdown() { |
103 // Release the references to all registries. This would happen soon during | 104 // Release the references to all registries. This would happen soon during |
104 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to | 105 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to |
105 // be the last to reference the WebRequestRulesRegistry objects, so that | 106 // be the last to reference the WebRequestRulesRegistry objects, so that |
106 // the posted task below causes their destruction on the IO thread, not on UI | 107 // the posted task below causes their destruction on the IO thread, not on UI |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 const content::NotificationSource& source, | 225 const content::NotificationSource& source, |
225 const content::NotificationDetails& details) { | 226 const content::NotificationDetails& details) { |
226 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, type); | 227 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, type); |
227 | 228 |
228 content::RenderProcessHost* process = | 229 content::RenderProcessHost* process = |
229 content::Source<content::RenderProcessHost>(source).ptr(); | 230 content::Source<content::RenderProcessHost>(source).ptr(); |
230 RemoveWebViewRulesRegistries(process->GetID()); | 231 RemoveWebViewRulesRegistries(process->GetID()); |
231 } | 232 } |
232 | 233 |
233 } // namespace extensions | 234 } // namespace extensions |
OLD | NEW |