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

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

Issue 10560013: Persist declarative rules to the extension state store. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RegisterKey Created 8 years, 6 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 | Annotate | Revision Log
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/logging.h" 8 #include "base/logging.h"
9 #include "content/public/browser/browser_thread.h"
10 #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"
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/notification_details.h" 17 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace { 22 namespace {
22 23
24 // Returns the key to use for storing declarative rules in the state store.
25 std::string GetDeclarativeRuleStorageKey(const std::string& event_name) {
26 return "declarative_rules." + event_name;
27 }
28
23 // Registers |web_request_rules_registry| on the IO thread. 29 // Registers |web_request_rules_registry| on the IO thread.
24 void RegisterToExtensionWebRequestEventRouterOnIO( 30 void RegisterToExtensionWebRequestEventRouterOnIO(
25 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) { 31 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry) {
26 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry( 32 ExtensionWebRequestEventRouter::GetInstance()->RegisterRulesRegistry(
27 web_request_rules_registry); 33 web_request_rules_registry);
28 } 34 }
29 35
30 } // namespace 36 } // namespace
31 37
32 RulesRegistryService::RulesRegistryService(Profile* profile) 38 RulesRegistryService::RulesRegistryService(Profile* profile)
33 : profile_(profile) { 39 : profile_(profile) {
34 if (profile) { 40 if (profile) {
35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 41 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
36 content::Source<Profile>(profile)); 42 content::Source<Profile>(profile));
37 } 43 }
38 } 44 }
39 45
40 RulesRegistryService::~RulesRegistryService() {} 46 RulesRegistryService::~RulesRegistryService() {}
41 47
42 void RulesRegistryService::RegisterDefaultRulesRegistries() { 48 void RulesRegistryService::RegisterDefaultRulesRegistries() {
49 RulesRegistryStorageDelegate* delegate = new RulesRegistryStorageDelegate();
43 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry( 50 scoped_refptr<WebRequestRulesRegistry> web_request_rules_registry(
44 new WebRequestRulesRegistry(profile_)); 51 new WebRequestRulesRegistry(profile_, delegate));
52 delegate->Init(profile_, web_request_rules_registry,
53 GetDeclarativeRuleStorageKey(
54 declarative_webrequest_constants::kOnRequest));
55
45 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest, 56 RegisterRulesRegistry(declarative_webrequest_constants::kOnRequest,
46 web_request_rules_registry); 57 web_request_rules_registry);
47 content::BrowserThread::PostTask( 58 content::BrowserThread::PostTask(
48 content::BrowserThread::IO, FROM_HERE, 59 content::BrowserThread::IO, FROM_HERE,
49 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO, 60 base::Bind(&RegisterToExtensionWebRequestEventRouterOnIO,
50 web_request_rules_registry)); 61 web_request_rules_registry));
51 } 62 }
52 63
53 void RulesRegistryService::Shutdown() { 64 void RulesRegistryService::Shutdown() {
54 content::BrowserThread::PostTask( 65 content::BrowserThread::PostTask(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 OnExtensionUnloaded(extension->id()); 116 OnExtensionUnloaded(extension->id());
106 break; 117 break;
107 } 118 }
108 default: 119 default:
109 NOTREACHED(); 120 NOTREACHED();
110 break; 121 break;
111 } 122 }
112 } 123 }
113 124
114 } // namespace extensions 125 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698