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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/content_rules_registry.h

Issue 53273002: Decouple RulesCacheDelegate from RulesRegistry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor_rules_registry_with_cache
Patch Set: Updated 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 (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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGISTRY _H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // ContentRuleActions. 57 // ContentRuleActions.
58 // 58 //
59 // The evaluation of URL related condition attributes (host_suffix, path_prefix) 59 // The evaluation of URL related condition attributes (host_suffix, path_prefix)
60 // is delegated to a URLMatcher, because this is capable of evaluating many 60 // is delegated to a URLMatcher, because this is capable of evaluating many
61 // of such URL related condition attributes in parallel. 61 // of such URL related condition attributes in parallel.
62 class ContentRulesRegistry : public RulesRegistry, 62 class ContentRulesRegistry : public RulesRegistry,
63 public content::NotificationObserver { 63 public content::NotificationObserver {
64 public: 64 public:
65 // For testing, |ui_part| can be NULL. In that case it constructs the 65 // For testing, |ui_part| can be NULL. In that case it constructs the
66 // registry with storage functionality suspended. 66 // registry with storage functionality suspended.
67 ContentRulesRegistry(Profile* profile, 67 ContentRulesRegistry(Profile* profile, RulesCacheDelegate* cache_delegate);
68 scoped_ptr<RulesCacheDelegate>* ui_part);
69 68
70 // Applies all content rules given an update (CSS match change or 69 // Applies all content rules given an update (CSS match change or
71 // page navigation, for now) from the renderer. 70 // page navigation, for now) from the renderer.
72 void Apply(content::WebContents* contents, 71 void Apply(content::WebContents* contents,
73 const std::vector<std::string>& matching_css_selectors); 72 const std::vector<std::string>& matching_css_selectors);
74 73
75 // Applies all content rules given that a tab was just navigated. 74 // Applies all content rules given that a tab was just navigated.
76 void DidNavigateMainFrame(content::WebContents* tab, 75 void DidNavigateMainFrame(content::WebContents* tab,
77 const content::LoadCommittedDetails& details, 76 const content::LoadCommittedDetails& details,
78 const content::FrameNavigateParams& params); 77 const content::FrameNavigateParams& params);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void UpdateConditionCache(); 113 void UpdateConditionCache();
115 114
116 // Tells a renderer what page attributes to watch for using an 115 // Tells a renderer what page attributes to watch for using an
117 // ExtensionMsg_WatchPages. 116 // ExtensionMsg_WatchPages.
118 void InstructRenderProcess(content::RenderProcessHost* process); 117 void InstructRenderProcess(content::RenderProcessHost* process);
119 118
120 typedef std::map<URLMatcherConditionSet::ID, ContentRule*> URLMatcherIdToRule; 119 typedef std::map<URLMatcherConditionSet::ID, ContentRule*> URLMatcherIdToRule;
121 typedef std::map<ContentRule::GlobalRuleId, linked_ptr<ContentRule> > 120 typedef std::map<ContentRule::GlobalRuleId, linked_ptr<ContentRule> >
122 RulesMap; 121 RulesMap;
123 122
124 Profile* const profile_;
125
126 // Map that tells us which ContentRules may match under the condition that 123 // Map that tells us which ContentRules may match under the condition that
127 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|. 124 // the URLMatcherConditionSet::ID was returned by the |url_matcher_|.
128 URLMatcherIdToRule match_id_to_rule_; 125 URLMatcherIdToRule match_id_to_rule_;
129 126
130 RulesMap content_rules_; 127 RulesMap content_rules_;
131 128
132 // Maps tab_id to the set of rules that match on that tab. This 129 // Maps tab_id to the set of rules that match on that tab. This
133 // lets us call Revert as appropriate. 130 // lets us call Revert as appropriate.
134 std::map<int, std::set<ContentRule*> > active_rules_; 131 std::map<int, std::set<ContentRule*> > active_rules_;
135 132
136 // Matches URLs for the page_url condition. 133 // Matches URLs for the page_url condition.
137 URLMatcher url_matcher_; 134 URLMatcher url_matcher_;
138 135
139 // All CSS selectors any rule's conditions watch for. 136 // All CSS selectors any rule's conditions watch for.
140 std::vector<std::string> watched_css_selectors_; 137 std::vector<std::string> watched_css_selectors_;
141 138
142 // Manages our notification registrations. 139 // Manages our notification registrations.
143 content::NotificationRegistrar registrar_; 140 content::NotificationRegistrar registrar_;
144 141
145 scoped_refptr<ExtensionInfoMap> extension_info_map_; 142 scoped_refptr<ExtensionInfoMap> extension_info_map_;
146 143
147 DISALLOW_COPY_AND_ASSIGN(ContentRulesRegistry); 144 DISALLOW_COPY_AND_ASSIGN(ContentRulesRegistry);
148 }; 145 };
149 146
150 } // namespace extensions 147 } // namespace extensions
151 148
152 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGIS TRY_H_ 149 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_RULES_REGIS TRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698