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 "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" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // Registers |web_request_rules_registry| on the IO thread. | 29 // Registers |web_request_rules_registry| on the IO thread. |
29 void RegisterToExtensionWebRequestEventRouterOnIO( | 30 void RegisterToExtensionWebRequestEventRouterOnIO( |
30 void* profile, | 31 void* profile, |
31 const RulesRegistryService::WebViewKey& webview_key, | 32 const RulesRegistryService::WebViewKey& webview_key, |
32 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { | 33 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { |
33 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( | 34 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( |
34 profile, webview_key, web_request_rules_registry); | 35 profile, webview_key, web_request_rules_registry); |
35 } | 36 } |
36 | 37 |
37 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { | 38 bool IsWebView(const RulesRegistryService::WebViewKey& webview_key) { |
38 return webview_key.embedder_process_id && webview_key.webview_instance_id; | 39 return webview_key.embedder_process_id && webview_key.webview_instance_id; |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 RulesRegistryService::RulesRegistryService(Profile* profile) | 44 RulesRegistryService::RulesRegistryService(content::BrowserContext* context) |
44 : content_rules_registry_(NULL), | 45 : content_rules_registry_(NULL), |
45 profile_(profile) { | 46 profile_(Profile::FromBrowserContext(context)) { |
46 if (profile) { | 47 if (profile_) { |
47 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 48 registrar_.Add(this, |
48 content::Source<Profile>(profile->GetOriginalProfile())); | 49 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 50 content::Source<Profile>(profile_->GetOriginalProfile())); |
50 content::Source<Profile>(profile->GetOriginalProfile())); | 51 registrar_.Add(this, |
| 52 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 53 content::Source<Profile>(profile_->GetOriginalProfile())); |
51 registrar_.Add(this, | 54 registrar_.Add(this, |
52 chrome::NOTIFICATION_EXTENSION_LOADED, | 55 chrome::NOTIFICATION_EXTENSION_LOADED, |
53 content::Source<Profile>(profile_->GetOriginalProfile())); | 56 content::Source<Profile>(profile_->GetOriginalProfile())); |
54 registrar_.Add( | 57 registrar_.Add( |
55 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 58 this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
56 content::NotificationService::AllBrowserContextsAndSources()); | 59 content::NotificationService::AllBrowserContextsAndSources()); |
57 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); | 60 EnsureDefaultRulesRegistriesRegistered(WebViewKey(0, 0)); |
58 } | 61 } |
59 } | 62 } |
60 | 63 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> > | 125 static base::LazyInstance<ProfileKeyedAPIFactory<RulesRegistryService> > |
123 g_factory = LAZY_INSTANCE_INITIALIZER; | 126 g_factory = LAZY_INSTANCE_INITIALIZER; |
124 | 127 |
125 // static | 128 // static |
126 ProfileKeyedAPIFactory<RulesRegistryService>* | 129 ProfileKeyedAPIFactory<RulesRegistryService>* |
127 RulesRegistryService::GetFactoryInstance() { | 130 RulesRegistryService::GetFactoryInstance() { |
128 return g_factory.Pointer(); | 131 return g_factory.Pointer(); |
129 } | 132 } |
130 | 133 |
131 // static | 134 // static |
132 RulesRegistryService* RulesRegistryService::Get(Profile* profile) { | 135 RulesRegistryService* RulesRegistryService::Get( |
133 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(profile); | 136 content::BrowserContext* context) { |
| 137 return ProfileKeyedAPIFactory<RulesRegistryService>::GetForProfile(context); |
134 } | 138 } |
135 | 139 |
136 void RulesRegistryService::RegisterRulesRegistry( | 140 void RulesRegistryService::RegisterRulesRegistry( |
137 scoped_refptr<RulesRegistry> rule_registry) { | 141 scoped_refptr<RulesRegistry> rule_registry) { |
138 const std::string event_name(rule_registry->event_name()); | 142 const std::string event_name(rule_registry->event_name()); |
139 RulesRegistryKey key(event_name, rule_registry->webview_key()); | 143 RulesRegistryKey key(event_name, rule_registry->webview_key()); |
140 DCHECK(rule_registries_.find(key) == rule_registries_.end()); | 144 DCHECK(rule_registries_.find(key) == rule_registries_.end()); |
141 rule_registries_[key] = rule_registry; | 145 rule_registries_[key] = rule_registry; |
142 } | 146 } |
143 | 147 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 RemoveWebViewRulesRegistries(process->GetID()); | 238 RemoveWebViewRulesRegistries(process->GetID()); |
235 break; | 239 break; |
236 } | 240 } |
237 default: | 241 default: |
238 NOTREACHED(); | 242 NOTREACHED(); |
239 break; | 243 break; |
240 } | 244 } |
241 } | 245 } |
242 | 246 |
243 } // namespace extensions | 247 } // namespace extensions |
OLD | NEW |