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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_cache_delegate.h

Issue 53273002: Decouple RulesCacheDelegate from RulesRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_rules_registry_with_cache
Patch Set: Merge with ToT Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
16 16
17 class Profile; 17 class Profile;
18 18
19 namespace extensions { 19 namespace extensions {
20 20
21 class RulesRegistry; 21 class RulesRegistry;
22 22
23 // RulesCacheDelegate implements the part of the RulesRegistry which works on 23 // RulesCacheDelegate implements the part of the RulesRegistry which works on
24 // the UI thread. It should only be used on the UI thread. It gets created 24 // the UI thread. It should only be used on the UI thread. It gets created
25 // by the RulesRegistry, but right after that it changes owner to the 25 // by the RulesRegistry, but right after that it changes owner to the
Jeffrey Yasskin 2013/11/01 00:15:09 Is "It gets created by the RulesRegistry" still tr
Fady Samuel 2013/11/01 15:13:39 No. Removed.
26 // RulesRegistryService, and is deleted by the service. 26 // RulesRegistryService, and is deleted by the service.
27 // If |log_storage_init_delay| is set, the delay caused by loading and 27 // If |log_storage_init_delay| is set, the delay caused by loading and
28 // registering rules on initialization will be logged with UMA. 28 // registering rules on initialization will be logged with UMA.
29 class RulesCacheDelegate : public content::NotificationObserver { 29 class RulesCacheDelegate : public content::NotificationObserver {
30 public: 30 public:
31
31 // |event_name| identifies the JavaScript event for which rules are 32 // |event_name| identifies the JavaScript event for which rules are
32 // registered. For example, for WebRequestRulesRegistry the name is 33 // registered. For example, for WebRequestRulesRegistry the name is
33 // "declarativeWebRequest.onRequest". 34 // "declarativeWebRequest.onRequest".
34 RulesCacheDelegate(Profile* profile, 35 RulesCacheDelegate(base::WeakPtr<RulesRegistry> registry,
35 const std::string& event_name,
36 content::BrowserThread::ID rules_registry_thread,
37 base::WeakPtr<RulesRegistry> registry,
38 bool log_storage_init_delay); 36 bool log_storage_init_delay);
39 37
40 virtual ~RulesCacheDelegate(); 38 virtual ~RulesCacheDelegate();
41 39
42 // Returns a key for the state store. The associated preference is a boolean 40 // Returns a key for the state store. The associated preference is a boolean
43 // indicating whether there are some declarative rules stored in the rule 41 // indicating whether there are some declarative rules stored in the rule
44 // store. 42 // store.
45 static std::string GetRulesStoredKey(const std::string& event_name, 43 static std::string GetRulesStoredKey(const std::string& event_name,
46 bool incognito); 44 bool incognito);
47 45
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 scoped_ptr<base::Value> value); 82 scoped_ptr<base::Value> value);
85 83
86 // Check the preferences whether the extension with |extension_id| has some 84 // Check the preferences whether the extension with |extension_id| has some
87 // rules stored on disk. If this information is not in the preferences, true 85 // rules stored on disk. If this information is not in the preferences, true
88 // is returned as a safe default value. 86 // is returned as a safe default value.
89 bool GetDeclarativeRulesStored(const std::string& extension_id) const; 87 bool GetDeclarativeRulesStored(const std::string& extension_id) const;
90 // Modify the preference to |rules_stored|. 88 // Modify the preference to |rules_stored|.
91 void SetDeclarativeRulesStored(const std::string& extension_id, 89 void SetDeclarativeRulesStored(const std::string& extension_id,
92 bool rules_stored); 90 bool rules_stored);
93 91
92 // Deserialize the rules from the given Value object and add them to the
93 // RulesRegistry.
94 static void DeserializeAndAddRules(base::WeakPtr<RulesRegistry> registry,
95 const std::string& extension_id,
96 scoped_ptr<base::Value> rules);
97
94 content::NotificationRegistrar registrar_; 98 content::NotificationRegistrar registrar_;
95 99
96 Profile* profile_; 100 Profile* profile_;
97 101
98 // The key under which rules are stored. 102 // The key under which rules are stored.
99 const std::string storage_key_; 103 const std::string storage_key_;
100 104
101 // The key under which we store whether the rules have been stored. 105 // The key under which we store whether the rules have been stored.
102 const std::string rules_stored_key_; 106 const std::string rules_stored_key_;
103 107
(...skipping 14 matching lines...) Expand all
118 // We notified the RulesRegistry that the rules are loaded. 122 // We notified the RulesRegistry that the rules are loaded.
119 bool notified_registry_; 123 bool notified_registry_;
120 124
121 // Use this factory to generate weak pointers bound to the UI thread. 125 // Use this factory to generate weak pointers bound to the UI thread.
122 base::WeakPtrFactory<RulesCacheDelegate> weak_ptr_factory_; 126 base::WeakPtrFactory<RulesCacheDelegate> weak_ptr_factory_;
123 }; 127 };
124 128
125 } // namespace extensions 129 } // namespace extensions
126 130
127 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__ 131 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_CACHE_DELEGATE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698