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

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

Issue 535203003: Replace Profile* in declarative_api with BrowserContext* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove changes to unit-test; those have to wait until move. Created 6 years, 3 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/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/rules_cache_delegate.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_consta nts.h" 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 15 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
16 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 16 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
22 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
23 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
24 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
25 24
26 namespace extensions { 25 namespace extensions {
27 26
28 namespace { 27 namespace {
29 28
30 // Registers |web_request_rules_registry| on the IO thread. 29 // Registers |web_request_rules_registry| on the IO thread.
31 void RegisterToExtensionWebRequestEventRouterOnIO( 30 void RegisterToExtensionWebRequestEventRouterOnIO(
32 void* profile, 31 content::BrowserContext* browser_context,
33 const RulesRegistryService::WebViewKey& webview_key, 32 const RulesRegistryService::WebViewKey& webview_key,
34 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { 33 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) {
35 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( 34 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry(
36 profile, webview_key, web_request_rules_registry); 35 browser_context, webview_key, web_request_rules_registry);
37 } 36 }
38 37
39 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { 38 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) {
40 return webview_key.embedder_process_id && webview_key.webview_instance_id; 39 return webview_key.embedder_process_id && webview_key.webview_instance_id;
41 } 40 }
42 41
43 } // namespace 42 } // namespace
44 43
45 RulesRegistryService::RulesRegistryService(content::BrowserContext* context) 44 RulesRegistryService::RulesRegistryService(content::BrowserContext* context)
46 : content_rules_registry_(NULL), 45 : content_rules_registry_(NULL),
47 extension_registry_observer_(this), 46 extension_registry_observer_(this),
48 profile_(Profile::FromBrowserContext(context)) { 47 browser_context_(context) {
49 if (profile_) { 48 if (browser_context_) {
50 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); 49 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
51 registrar_.Add( 50 registrar_.Add(
52 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 51 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
53 content::NotificationService::AllBrowserContextsAndSources()); 52 content::NotificationService::AllBrowserContextsAndSources());
54 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); 53 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0));
55 } 54 }
56 } 55 }
57 56
58 RulesRegistryService::~RulesRegistryService() {} 57 RulesRegistryService::~RulesRegistryService() {}
59 58
60 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered( 59 void RulesRegistryService::EnsureDefaultRulesRegistriesRegistered(
61 const WebViewKey& webview_key) { 60 const WebViewKey& webview_key) {
62 if (!profile_) 61 if (!browser_context_)
63 return; 62 return;
64 63
65 RulesRegistryKey key(declarative_webrequest_constants::kOnRequest, 64 RulesRegistryKey key(declarative_webrequest_constants::kOnRequest,
66 webview_key); 65 webview_key);
67 // If we can find the key in the |rule_registries_| then we have already 66 // If we can find the key in the |rule_registries_| then we have already
68 // installed the default registries. 67 // installed the default registries.
69 if (ContainsKey(rule_registries_, key)) 68 if (ContainsKey(rule_registries_, key))
70 return; 69 return;
71 70
72 71
73 RulesCacheDelegate* web_request_cache_delegate = NULL; 72 RulesCacheDelegate* web_request_cache_delegate = NULL;
74 if (!IsWebView(webview_key)) { 73 if (!IsWebView(webview_key)) {
75 web_request_cache_delegate = 74 web_request_cache_delegate =
76 new RulesCacheDelegate(true /*log_storage_init_delay*/); 75 new RulesCacheDelegate(true /*log_storage_init_delay*/);
77 cache_delegates_.push_back(web_request_cache_delegate); 76 cache_delegates_.push_back(web_request_cache_delegate);
78 } 77 }
79 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 78 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
80 new WebRequestRulesRegistry(profile_, 79 new WebRequestRulesRegistry(browser_context_,
81 web_request_cache_delegate, 80 web_request_cache_delegate,
82 webview_key)); 81 webview_key));
83 82
84 RegisterRulesRegistry(web_request_rules_registry); 83 RegisterRulesRegistry(web_request_rules_registry);
85 content::BrowserThread::PostTask( 84 content::BrowserThread::PostTask(
86 content::BrowserThread::IO, FROM_HERE, 85 content::BrowserThread::IO, FROM_HERE,
87 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 86 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
88 profile_, webview_key, web_request_rules_registry)); 87 browser_context_, webview_key, web_request_rules_registry));
89 88
90 // Only create a ContentRulesRegistry for regular pages and not webviews. 89 // Only create a ContentRulesRegistry for regular pages and not webviews.
91 if (!IsWebView(webview_key)) { 90 if (!IsWebView(webview_key)) {
92 RulesCacheDelegate* content_rules_cache_delegate = 91 RulesCacheDelegate* content_rules_cache_delegate =
93 new RulesCacheDelegate(false /*log_storage_init_delay*/); 92 new RulesCacheDelegate(false /*log_storage_init_delay*/);
94 cache_delegates_.push_back(content_rules_cache_delegate); 93 cache_delegates_.push_back(content_rules_cache_delegate);
95 scoped_refptr<ContentRulesRegistry> content_rules_registry( 94 scoped_refptr<ContentRulesRegistry> content_rules_registry(
96 new ContentRulesRegistry(profile_, content_rules_cache_delegate)); 95 new ContentRulesRegistry(browser_context_,
96 content_rules_cache_delegate));
97 RegisterRulesRegistry(content_rules_registry); 97 RegisterRulesRegistry(content_rules_registry);
98 content_rules_registry_ = content_rules_registry.get(); 98 content_rules_registry_ = content_rules_registry.get();
99 } 99 }
100 } 100 }
101 101
102 void RulesRegistryService::Shutdown() { 102 void RulesRegistryService::Shutdown() {
103 // Release the references to all registries. This would happen soon during 103 // Release the references to all registries. This would happen soon during
104 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to 104 // destruction of |*this|, but we need the ExtensionWebRequestEventRouter to
105 // be the last to reference the WebRequestRulesRegistry objects, so that 105 // 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 106 // the posted task below causes their destruction on the IO thread, not on UI
107 // where the destruction of |*this| takes place. 107 // where the destruction of |*this| takes place.
108 // TODO(vabr): Remove once http://crbug.com/218451#c6 gets addressed. 108 // TODO(vabr): Remove once http://crbug.com/218451#c6 gets addressed.
109 rule_registries_.clear(); 109 rule_registries_.clear();
110 content::BrowserThread::PostTask( 110 content::BrowserThread::PostTask(
111 content::BrowserThread::IO, FROM_HERE, 111 content::BrowserThread::IO, FROM_HERE,
112 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 112 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
113 profile_, WebViewKey(0, 0), 113 browser_context_, WebViewKey(0, 0),
114 scoped_refptr<WebRequestRulesRegistry>(NULL))); 114 scoped_refptr<WebRequestRulesRegistry>(NULL)));
115 } 115 }
116 116
117 static base::LazyInstance<BrowserContextKeyedAPIFactory<RulesRegistryService> > 117 static base::LazyInstance<BrowserContextKeyedAPIFactory<RulesRegistryService> >
118 g_factory = LAZY_INSTANCE_INITIALIZER; 118 g_factory = LAZY_INSTANCE_INITIALIZER;
119 119
120 // static 120 // static
121 BrowserContextKeyedAPIFactory<RulesRegistryService>* 121 BrowserContextKeyedAPIFactory<RulesRegistryService>*
122 RulesRegistryService::GetFactoryInstance() { 122 RulesRegistryService::GetFactoryInstance() {
123 return g_factory.Pointer(); 123 return g_factory.Pointer();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 const content::NotificationSource& source, 224 const content::NotificationSource& source,
225 const content::NotificationDetails& details) { 225 const content::NotificationDetails& details) {
226 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, type); 226 DCHECK_EQ(content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, type);
227 227
228 content::RenderProcessHost* process = 228 content::RenderProcessHost* process =
229 content::Source<content::RenderProcessHost>(source).ptr(); 229 content::Source<content::RenderProcessHost>(source).ptr();
230 RemoveWebViewRulesRegistries(process->GetID()); 230 RemoveWebViewRulesRegistries(process->GetID());
231 } 231 }
232 232
233 } // namespace extensions 233 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698