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/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry.
h" | 9 #include "chrome/browser/extensions/api/declarative/initializing_rules_registry.
h" |
10 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg
ate.h" | 10 #include "chrome/browser/extensions/api/declarative/rules_registry_storage_deleg
ate.h" |
11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" | 11 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta
nts.h" |
12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_
registry.h" | 12 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_
registry.h" |
13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Returns the key to use for storing declarative rules in the state store. | 24 // Returns the key to use for storing declarative rules in the state store. |
25 std::string GetDeclarativeRuleStorageKey(const std::string& event_name) { | 25 std::string GetDeclarativeRuleStorageKey(const std::string& event_name, |
26 return "declarative_rules." + event_name; | 26 bool incognito) { |
| 27 if (incognito) |
| 28 return "declarative_rules.incognito." + event_name; |
| 29 else |
| 30 return "declarative_rules." + event_name; |
27 } | 31 } |
28 | 32 |
29 // Registers |web_request_rules_registry| on the IO thread. | 33 // Registers |web_request_rules_registry| on the IO thread. |
30 void RegisterToExtensionWebRequestEventRouterOnIO( | 34 void RegisterToExtensionWebRequestEventRouterOnIO( |
| 35 void* profile, |
31 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { | 36 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { |
32 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( | 37 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( |
33 web_request_rules_registry); | 38 profile, web_request_rules_registry); |
34 } | 39 } |
35 | 40 |
36 } // namespace | 41 } // namespace |
37 | 42 |
38 RulesRegistryService::RulesRegistryService(Profile* profile) | 43 RulesRegistryService::RulesRegistryService(Profile* profile) |
39 : profile_(profile) { | 44 : profile_(profile) { |
40 if (profile) { | 45 if (profile) { |
41 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 46 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
42 content::Source<Profile>(profile)); | 47 content::Source<Profile>(profile->GetOriginalProfile())); |
43 } | 48 } |
44 } | 49 } |
45 | 50 |
46 RulesRegistryService::~RulesRegistryService() { | 51 RulesRegistryService::~RulesRegistryService() { |
47 for (size_t i = 0; i < delegates_.size(); ++i) | 52 for (size_t i = 0; i < delegates_.size(); ++i) |
48 delegates_[i]->CleanupOnUIThread(); | 53 delegates_[i]->CleanupOnUIThread(); |
49 } | 54 } |
50 | 55 |
51 void RulesRegistryService::RegisterDefaultRulesRegistries() { | 56 void RulesRegistryService::RegisterDefaultRulesRegistries() { |
52 RulesRegistryStorageDelegate* delegate = new RulesRegistryStorageDelegate(); | 57 RulesRegistryStorageDelegate* delegate = new RulesRegistryStorageDelegate(); |
53 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( | 58 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( |
54 new WebRequestRulesRegistry(profile_, delegate)); | 59 new WebRequestRulesRegistry(profile_, delegate)); |
55 delegate->InitOnUIThread(profile_, web_request_rules_registry, | 60 delegate->InitOnUIThread(profile_, web_request_rules_registry, |
56 GetDeclarativeRuleStorageKey( | 61 GetDeclarativeRuleStorageKey( |
57 declarative_webrequest_constants::kOnRequest)); | 62 declarative_webrequest_constants::kOnRequest, |
| 63 profile_->IsOffTheRecord())); |
58 delegates_.push_back(delegate); | 64 delegates_.push_back(delegate); |
59 | 65 |
60 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest, | 66 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest, |
61 web_request_rules_registry); | 67 web_request_rules_registry); |
62 content::BrowserThread::PostTask( | 68 content::BrowserThread::PostTask( |
63 content::BrowserThread::IO, FROM_HERE, | 69 content::BrowserThread::IO, FROM_HERE, |
64 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, | 70 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, |
65 web_request_rules_registry)); | 71 profile_, web_request_rules_registry)); |
66 } | 72 } |
67 | 73 |
68 void RulesRegistryService::Shutdown() { | 74 void RulesRegistryService::Shutdown() { |
69 content::BrowserThread::PostTask( | 75 content::BrowserThread::PostTask( |
70 content::BrowserThread::IO, FROM_HERE, | 76 content::BrowserThread::IO, FROM_HERE, |
71 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, | 77 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, |
72 scoped_refptr<WebRequestRulesRegistry>(NULL))); | 78 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); |
73 } | 79 } |
74 | 80 |
75 void RulesRegistryService::RegisterRulesRegistry( | 81 void RulesRegistryService::RegisterRulesRegistry( |
76 const std::string& event_name, | 82 const std::string& event_name, |
77 scoped_refptr<RulesRegistry> rule_registry) { | 83 scoped_refptr<RulesRegistry> rule_registry) { |
78 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); | 84 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); |
79 rule_registries_[event_name] = | 85 rule_registries_[event_name] = |
80 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); | 86 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); |
81 } | 87 } |
82 | 88 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 OnExtensionUnloaded(extension->id()); | 126 OnExtensionUnloaded(extension->id()); |
121 break; | 127 break; |
122 } | 128 } |
123 default: | 129 default: |
124 NOTREACHED(); | 130 NOTREACHED(); |
125 break; | 131 break; |
126 } | 132 } |
127 } | 133 } |
128 | 134 |
129 } // namespace extensions | 135 } // namespace extensions |
OLD | NEW |