Chromium Code Reviews| 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)); |
| 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(bool incognito) { |
|
Matt Perry
2012/07/25 21:27:56
The incognito parameter is redundant. You can just
battre
2012/07/26 16:38:43
Done.
| |
| 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, incognito)); |
| 58 delegates_.push_back(delegate); | 63 delegates_.push_back(delegate); |
| 59 | 64 |
| 60 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest, | 65 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest, |
| 61 web_request_rules_registry); | 66 web_request_rules_registry); |
| 62 content::BrowserThread::PostTask( | 67 content::BrowserThread::PostTask( |
| 63 content::BrowserThread::IO, FROM_HERE, | 68 content::BrowserThread::IO, FROM_HERE, |
| 64 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, | 69 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, |
| 65 web_request_rules_registry)); | 70 profile_, web_request_rules_registry)); |
| 66 } | 71 } |
| 67 | 72 |
| 68 void RulesRegistryService::Shutdown() { | 73 void RulesRegistryService::Shutdown() { |
| 69 content::BrowserThread::PostTask( | 74 content::BrowserThread::PostTask( |
| 70 content::BrowserThread::IO, FROM_HERE, | 75 content::BrowserThread::IO, FROM_HERE, |
| 71 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, | 76 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, |
| 72 scoped_refptr<WebRequestRulesRegistry>(NULL))); | 77 profile_, scoped_refptr<WebRequestRulesRegistry>(NULL))); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void RulesRegistryService::RegisterRulesRegistry( | 80 void RulesRegistryService::RegisterRulesRegistry( |
| 76 const std::string& event_name, | 81 const std::string& event_name, |
| 77 scoped_refptr<RulesRegistry> rule_registry) { | 82 scoped_refptr<RulesRegistry> rule_registry) { |
| 78 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); | 83 DCHECK(rule_registries_.find(event_name) == rule_registries_.end()); |
| 79 rule_registries_[event_name] = | 84 rule_registries_[event_name] = |
| 80 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); | 85 make_scoped_refptr(new InitializingRulesRegistry(rule_registry)); |
| 81 } | 86 } |
| 82 | 87 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 OnExtensionUnloaded(extension->id()); | 125 OnExtensionUnloaded(extension->id()); |
| 121 break; | 126 break; |
| 122 } | 127 } |
| 123 default: | 128 default: |
| 124 NOTREACHED(); | 129 NOTREACHED(); |
| 125 break; | 130 break; |
| 126 } | 131 } |
| 127 } | 132 } |
| 128 | 133 |
| 129 } // namespace extensions | 134 } // namespace extensions |
| OLD | NEW |