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

Side by Side Diff: extensions/browser/api/declarative/rules_registry.cc

Issue 1158693006: Create a mechanism define declarative rules via the extension manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 5 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
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 "extensions/browser/api/declarative/rules_registry.h" 5 #include "extensions/browser/api/declarative/rules_registry.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
20 #include "extensions/browser/api/declarative/rules_cache_delegate.h" 20 #include "extensions/browser/api/declarative/rules_cache_delegate.h"
21 #include "extensions/browser/extension_prefs.h" 21 #include "extensions/browser/extension_prefs.h"
22 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
23 #include "extensions/browser/state_store.h" 23 #include "extensions/browser/state_store.h"
24 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
25 #include "extensions/common/manifest_constants.h"
26
27 namespace extensions {
25 28
26 namespace { 29 namespace {
27 30
28 const char kSuccess[] = ""; 31 const char kSuccess[] = "";
29 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; 32 const char kDuplicateRuleId[] = "Duplicate rule ID: %s";
33 const char kErrorCannotRemoveManifestRules[] =
34 "Rules declared in the 'event_rules' manifest field cannot be removed";
30 35
31 scoped_ptr<base::Value> RulesToValue( 36 scoped_ptr<base::Value> RulesToValue(
32 const std::vector<linked_ptr<extensions::RulesRegistry::Rule> >& rules) { 37 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules) {
33 scoped_ptr<base::ListValue> list(new base::ListValue()); 38 scoped_ptr<base::ListValue> list(new base::ListValue());
34 for (size_t i = 0; i < rules.size(); ++i) 39 for (size_t i = 0; i < rules.size(); ++i)
35 list->Append(rules[i]->ToValue().release()); 40 list->Append(rules[i]->ToValue().release());
36 return list.Pass(); 41 return list.Pass();
37 } 42 }
38 43
39 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > RulesFromValue( 44 std::vector<linked_ptr<RulesRegistry::Rule>> RulesFromValue(
40 const base::Value* value) { 45 const base::Value* value) {
41 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > rules; 46 std::vector<linked_ptr<RulesRegistry::Rule>> rules;
42 47
43 const base::ListValue* list = NULL; 48 const base::ListValue* list = NULL;
44 if (!value || !value->GetAsList(&list)) 49 if (!value || !value->GetAsList(&list))
45 return rules; 50 return rules;
46 51
47 rules.reserve(list->GetSize()); 52 rules.reserve(list->GetSize());
48 for (size_t i = 0; i < list->GetSize(); ++i) { 53 for (size_t i = 0; i < list->GetSize(); ++i) {
49 const base::DictionaryValue* dict = NULL; 54 const base::DictionaryValue* dict = NULL;
50 if (!list->GetDictionary(i, &dict)) 55 if (!list->GetDictionary(i, &dict))
51 continue; 56 continue;
52 linked_ptr<extensions::RulesRegistry::Rule> rule( 57 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule());
53 new extensions::RulesRegistry::Rule()); 58 if (RulesRegistry::Rule::Populate(*dict, rule.get()))
54 if (extensions::RulesRegistry::Rule::Populate(*dict, rule.get()))
55 rules.push_back(rule); 59 rules.push_back(rule);
56 } 60 }
57 61
58 return rules; 62 return rules;
59 } 63 }
60 64
65 // Converts a rule defined in the manifest into a JSON internal format. The
66 // difference is that actions and conditions use a "type" key to define the
67 // type of rule/condition, while the internal format uses a "instanceType" key
68 // for this. This function walks through all the conditions and rules to swap
69 // the manifest key for the internal key.
70 bool ConvertManifestRule(const linked_ptr<RulesRegistry::Rule>& rule) {
71 auto convert_list = [](std::vector<linked_ptr<base::Value>>& list) {
72 for (const linked_ptr<base::Value>& value : list) {
73 base::DictionaryValue* dictionary = nullptr;
74 if (!value->GetAsDictionary(&dictionary))
75 return false;
76 std::string type;
77 if (!dictionary->GetString("type", &type))
78 return false;
79 dictionary->Remove("type", nullptr);
80 dictionary->SetString("instanceType", type);
81 }
82 return true;
83 };
84 return convert_list(rule->actions) && convert_list(rule->conditions);
85 }
86
87 std::vector<linked_ptr<RulesRegistry::Rule>> RulesFromManifest(
88 const base::Value* value,
89 const std::string& event_name) {
90 std::vector<linked_ptr<RulesRegistry::Rule>> rules;
91
92 // The following is an example of how an event programmatic rule definition
Mike Wittman 2015/06/05 23:15:58 You'll need to add something like this to the mani
93 // translates to a manifest definition.
94 //
95 // From javascript:
96 //
97 // chrome.declarativeContent.onPageChanged.addRules([{
98 // actions: [
99 // new chrome.declarativeContent.ShowPageAction()
100 // ],
101 // conditions: [
102 // new chrome.declarativeContent.PageStateMatcher({css: ["video"]})
103 // ]
104 // }]);
105 //
106 // In manifest:
107 //
108 // "event_rules": [{
109 // "event" : "declarativeContent.onPageChanged",
110 // "actions" : [{
111 // "type": "declarativeContent.ShowPageAction"
112 // }],
113 // "conditions" : [{
114 // "css": ["video"],
115 // "type" : "declarativeContent.PageStateMatcher"
116 // }]
117 // }]
118 //
119 // The javascript objects get translated into JSON objects with a "type"
120 // field to indicate the instance type. Instead of adding rules to a
121 // specific event list, each rule has an "event" field to indicate which
122 // event it applies to.
123 //
124 const base::ListValue* list = nullptr;
125 if (!value->GetAsList(&list))
126 return rules;
127
128 for (size_t i = 0; i < list->GetSize(); ++i) {
129 const base::DictionaryValue* dict = nullptr;
130 if (!list->GetDictionary(i, &dict))
131 continue;
132 std::string event;
133 if (!dict->GetString("event", &event) || event_name != event) {
134 continue;
135 }
136 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule());
137 if (RulesRegistry::Rule::Populate(*dict, rule.get()) &&
138 ConvertManifestRule(rule)) {
139 rules.push_back(rule);
140 }
141 }
142
143 return rules;
144 }
145
61 std::string ToId(int identifier) { 146 std::string ToId(int identifier) {
62 return base::StringPrintf("_%d_", identifier); 147 return base::StringPrintf("_%d_", identifier);
63 } 148 }
64 149
65 } // namespace 150 } // namespace
66 151
67 152
68 namespace extensions {
69
70 // RulesRegistry 153 // RulesRegistry
71 154
72 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context, 155 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context,
73 const std::string& event_name, 156 const std::string& event_name,
74 content::BrowserThread::ID owner_thread, 157 content::BrowserThread::ID owner_thread,
75 RulesCacheDelegate* cache_delegate, 158 RulesCacheDelegate* cache_delegate,
76 int id) 159 int id)
77 : browser_context_(browser_context), 160 : browser_context_(browser_context),
78 owner_thread_(owner_thread), 161 owner_thread_(owner_thread),
79 event_name_(event_name), 162 event_name_(event_name),
80 id_(id), 163 id_(id),
81 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache 164 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache
82 // delegate to wait for. 165 // delegate to wait for.
83 last_generated_rule_identifier_id_(0), 166 last_generated_rule_identifier_id_(0),
84 weak_ptr_factory_(browser_context_ ? this : NULL) { 167 weak_ptr_factory_(browser_context_ ? this : NULL) {
85 if (cache_delegate) { 168 if (cache_delegate) {
86 cache_delegate_ = cache_delegate->GetWeakPtr(); 169 cache_delegate_ = cache_delegate->GetWeakPtr();
87 cache_delegate->Init(this); 170 cache_delegate->Init(this);
88 } 171 }
89 } 172 }
90 173
91 std::string RulesRegistry::AddRulesNoFill( 174 std::string RulesRegistry::AddRulesNoFill(
92 const std::string& extension_id, 175 const std::string& extension_id,
93 const std::vector<linked_ptr<Rule> >& rules) { 176 const std::vector<linked_ptr<Rule>>& rules,
177 RulesDictionary& out) {
94 DCHECK_CURRENTLY_ON(owner_thread()); 178 DCHECK_CURRENTLY_ON(owner_thread());
95 179
96 // Verify that all rule IDs are new. 180 // Verify that all rule IDs are new.
97 for (std::vector<linked_ptr<Rule> >::const_iterator i = 181 for (std::vector<linked_ptr<Rule> >::const_iterator i =
98 rules.begin(); i != rules.end(); ++i) { 182 rules.begin(); i != rules.end(); ++i) {
99 const RuleId& rule_id = *((*i)->id); 183 const RuleId& rule_id = *((*i)->id);
100 // Every rule should have a priority assigned. 184 // Every rule should have a priority assigned.
101 DCHECK((*i)->priority); 185 DCHECK((*i)->priority);
102 RulesDictionaryKey key(extension_id, rule_id); 186 RulesDictionaryKey key(extension_id, rule_id);
103 if (rules_.find(key) != rules_.end()) 187 if (rules_.find(key) != rules_.end() ||
188 manifest_rules_.find(key) != manifest_rules_.end())
104 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str()); 189 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str());
105 } 190 }
106 191
107 std::string error = AddRulesImpl(extension_id, rules); 192 std::string error = AddRulesImpl(extension_id, rules);
108 193
109 if (!error.empty()) 194 if (!error.empty())
110 return error; 195 return error;
111 196
112 // Commit all rules into |rules_| on success. 197 // Commit all rules into |rules_| on success.
113 for (std::vector<linked_ptr<Rule> >::const_iterator i = 198 for (std::vector<linked_ptr<Rule> >::const_iterator i =
114 rules.begin(); i != rules.end(); ++i) { 199 rules.begin(); i != rules.end(); ++i) {
115 const RuleId& rule_id = *((*i)->id); 200 const RuleId& rule_id = *((*i)->id);
116 RulesDictionaryKey key(extension_id, rule_id); 201 RulesDictionaryKey key(extension_id, rule_id);
117 rules_[key] = *i; 202 out[key] = *i;
118 } 203 }
119 204
120 MaybeProcessChangedRules(extension_id); 205 MaybeProcessChangedRules(extension_id);
121 return kSuccess; 206 return kSuccess;
122 } 207 }
123 208
124 std::string RulesRegistry::AddRules( 209 std::string RulesRegistry::AddRules(
125 const std::string& extension_id, 210 const std::string& extension_id,
126 const std::vector<linked_ptr<Rule> >& rules) { 211 const std::vector<linked_ptr<Rule>>& rules) {
212 return AddRulesInternal(extension_id, rules, rules_);
213 }
214
215 std::string RulesRegistry::AddRulesInternal(
216 const std::string& extension_id,
217 const std::vector<linked_ptr<Rule>>& rules,
218 RulesDictionary& out) {
127 DCHECK_CURRENTLY_ON(owner_thread()); 219 DCHECK_CURRENTLY_ON(owner_thread());
128 220
129 std::string error = CheckAndFillInOptionalRules(extension_id, rules); 221 std::string error = CheckAndFillInOptionalRules(extension_id, rules);
130 if (!error.empty()) 222 if (!error.empty())
131 return error; 223 return error;
132 FillInOptionalPriorities(rules); 224 FillInOptionalPriorities(rules);
133 225
134 return AddRulesNoFill(extension_id, rules); 226 return AddRulesNoFill(extension_id, rules, out);
135 } 227 }
136 228
137 std::string RulesRegistry::RemoveRules( 229 std::string RulesRegistry::RemoveRules(
138 const std::string& extension_id, 230 const std::string& extension_id,
139 const std::vector<std::string>& rule_identifiers) { 231 const std::vector<std::string>& rule_identifiers) {
140 DCHECK_CURRENTLY_ON(owner_thread()); 232 DCHECK_CURRENTLY_ON(owner_thread());
141 233
234 // Check if any of the rules are non-removable.
235 for (RuleId rule_id : rule_identifiers) {
236 RulesDictionaryKey lookup_key(extension_id, rule_id);
237 RulesDictionary::iterator itr = manifest_rules_.find(lookup_key);
238 if (itr != manifest_rules_.end())
239 return kErrorCannotRemoveManifestRules;
240 }
241
142 std::string error = RemoveRulesImpl(extension_id, rule_identifiers); 242 std::string error = RemoveRulesImpl(extension_id, rule_identifiers);
143 243
144 if (!error.empty()) 244 if (!error.empty())
145 return error; 245 return error;
146 246
147 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); 247 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
148 i != rule_identifiers.end(); 248 i != rule_identifiers.end();
149 ++i) { 249 ++i) {
150 RulesDictionaryKey lookup_key(extension_id, *i); 250 RulesDictionaryKey lookup_key(extension_id, *i);
151 rules_.erase(lookup_key); 251 rules_.erase(lookup_key);
152 } 252 }
153 253
154 MaybeProcessChangedRules(extension_id); 254 MaybeProcessChangedRules(extension_id);
155 RemoveUsedRuleIdentifiers(extension_id, rule_identifiers); 255 RemoveUsedRuleIdentifiers(extension_id, rule_identifiers);
156 return kSuccess; 256 return kSuccess;
157 } 257 }
158 258
159 std::string RulesRegistry::RemoveAllRules(const std::string& extension_id) { 259 std::string RulesRegistry::RemoveAllRules(const std::string& extension_id) {
160 std::string result = RulesRegistry::RemoveAllRulesNoStoreUpdate(extension_id); 260 std::string result =
261 RulesRegistry::RemoveAllRulesNoStoreUpdate(extension_id, false);
161 MaybeProcessChangedRules(extension_id); // Now update the prefs and store. 262 MaybeProcessChangedRules(extension_id); // Now update the prefs and store.
162 return result; 263 return result;
163 } 264 }
164 265
165 std::string RulesRegistry::RemoveAllRulesNoStoreUpdate( 266 std::string RulesRegistry::RemoveAllRulesNoStoreUpdate(
166 const std::string& extension_id) { 267 const std::string& extension_id,
268 bool uninstall) {
167 DCHECK_CURRENTLY_ON(owner_thread()); 269 DCHECK_CURRENTLY_ON(owner_thread());
168 270
169 std::string error = RemoveAllRulesImpl(extension_id); 271 std::string error = RemoveAllRulesImpl(extension_id);
170 272
171 if (!error.empty()) 273 if (!error.empty())
172 return error; 274 return error;
173 275
174 for (RulesDictionary::const_iterator i = rules_.begin(); 276 auto remove_rules = [&extension_id](RulesDictionary& dictionary) {
175 i != rules_.end();) { 277 for (auto it = dictionary.begin(); it != dictionary.end();) {
176 const RulesDictionaryKey& key = i->first; 278 if (it->first.first == extension_id)
177 ++i; 279 dictionary.erase(it++);
178 if (key.first == extension_id) 280 else
179 rules_.erase(key); 281 ++it;
180 } 282 }
283 };
284 remove_rules(rules_);
285 if (uninstall)
286 remove_rules(manifest_rules_);
181 287
182 RemoveAllUsedRuleIdentifiers(extension_id); 288 RemoveAllUsedRuleIdentifiers(extension_id);
183 return kSuccess; 289 return kSuccess;
184 } 290 }
185 291
186 void RulesRegistry::GetRules(const std::string& extension_id, 292 void RulesRegistry::GetRules(const std::string& extension_id,
187 const std::vector<std::string>& rule_identifiers, 293 const std::vector<std::string>& rule_identifiers,
188 std::vector<linked_ptr<Rule> >* out) { 294 std::vector<linked_ptr<Rule> >* out) {
189 DCHECK_CURRENTLY_ON(owner_thread()); 295 DCHECK_CURRENTLY_ON(owner_thread());
190 296
191 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); 297 for (const auto& i : rule_identifiers) {
192 i != rule_identifiers.end(); ++i) { 298 RulesDictionaryKey lookup_key(extension_id, i);
193 RulesDictionaryKey lookup_key(extension_id, *i);
194 RulesDictionary::iterator entry = rules_.find(lookup_key); 299 RulesDictionary::iterator entry = rules_.find(lookup_key);
300 if (entry == rules_.end())
301 entry = manifest_rules_.find(lookup_key);
195 if (entry != rules_.end()) 302 if (entry != rules_.end())
196 out->push_back(entry->second); 303 out->push_back(entry->second);
197 } 304 }
198 } 305 }
199 306
307 void RulesRegistry::GetRules(
308 const std::string& extension_id,
309 RulesDictionary& rules,
310 std::vector<linked_ptr<RulesRegistry::Rule>>* out) {
311 for (const auto& i : rules) {
312 const RulesDictionaryKey& key = i.first;
313 if (key.first == extension_id)
314 out->push_back(i.second);
315 }
316 }
317
200 void RulesRegistry::GetAllRules(const std::string& extension_id, 318 void RulesRegistry::GetAllRules(const std::string& extension_id,
201 std::vector<linked_ptr<Rule> >* out) { 319 std::vector<linked_ptr<Rule> >* out) {
202 DCHECK_CURRENTLY_ON(owner_thread()); 320 DCHECK_CURRENTLY_ON(owner_thread());
203 for (RulesDictionary::const_iterator i = rules_.begin(); 321 GetRules(extension_id, manifest_rules_, out);
204 i != rules_.end(); ++i) { 322 GetRules(extension_id, rules_, out);
205 const RulesDictionaryKey& key = i->first;
206 if (key.first == extension_id)
207 out->push_back(i->second);
208 }
209 } 323 }
210 324
211 void RulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { 325 void RulesRegistry::OnExtensionUnloaded(const Extension* extension) {
212 DCHECK_CURRENTLY_ON(owner_thread()); 326 DCHECK_CURRENTLY_ON(owner_thread());
213 std::string error = RemoveAllRulesImpl(extension_id); 327 std::string error = RemoveAllRulesImpl(extension->id());
214 if (!error.empty()) 328 if (!error.empty())
215 LOG(ERROR) << error; 329 LOG(ERROR) << error;
216 } 330 }
217 331
218 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { 332 void RulesRegistry::OnExtensionUninstalled(const Extension* extension) {
219 DCHECK_CURRENTLY_ON(owner_thread()); 333 DCHECK_CURRENTLY_ON(owner_thread());
220 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); 334 std::string error = RemoveAllRulesNoStoreUpdate(extension->id(), true);
221 if (!error.empty()) 335 if (!error.empty())
222 LOG(ERROR) << error; 336 LOG(ERROR) << error;
223 } 337 }
224 338
225 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { 339 void RulesRegistry::OnExtensionLoaded(const Extension* extension) {
226 DCHECK_CURRENTLY_ON(owner_thread()); 340 DCHECK_CURRENTLY_ON(owner_thread());
227 std::vector<linked_ptr<Rule> > rules; 341 std::vector<linked_ptr<Rule>> rules;
228 GetAllRules(extension_id, &rules); 342 GetAllRules(extension->id(), &rules);
229 std::string error = AddRulesImpl(extension_id, rules); 343 const base::ListValue* value = NULL;
344 if (extension->manifest()->GetList(manifest_keys::kEventRules, &value)) {
345 std::string error =
346 AddRulesInternal(extension->id(), RulesFromManifest(value, event_name_),
347 manifest_rules_);
348 if (!error.empty())
349 LOG(ERROR) << error;
350 }
351 std::string error = AddRulesImpl(extension->id(), rules);
230 if (!error.empty()) 352 if (!error.empty())
231 LOG(ERROR) << error; 353 LOG(ERROR) << error;
232 } 354 }
233 355
234 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { 356 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const {
235 size_t entry_count = 0u; 357 size_t entry_count = 0u;
236 for (RuleIdentifiersMap::const_iterator extension = 358 for (RuleIdentifiersMap::const_iterator extension =
237 used_rule_identifiers_.begin(); 359 used_rule_identifiers_.begin();
238 extension != used_rule_identifiers_.end(); 360 extension != used_rule_identifiers_.end();
239 ++extension) { 361 ++extension) {
240 // Each extension is counted as 1 just for being there. Otherwise we miss 362 // Each extension is counted as 1 just for being there. Otherwise we miss
241 // keys with empty values. 363 // keys with empty values.
242 entry_count += 1u + extension->second.size(); 364 entry_count += 1u + extension->second.size();
243 } 365 }
244 return entry_count; 366 return entry_count;
245 } 367 }
246 368
247 void RulesRegistry::DeserializeAndAddRules( 369 void RulesRegistry::DeserializeAndAddRules(
248 const std::string& extension_id, 370 const std::string& extension_id,
249 scoped_ptr<base::Value> rules) { 371 scoped_ptr<base::Value> rules) {
250 DCHECK_CURRENTLY_ON(owner_thread()); 372 DCHECK_CURRENTLY_ON(owner_thread());
251 373
252 AddRulesNoFill(extension_id, RulesFromValue(rules.get())); 374 AddRulesNoFill(extension_id, RulesFromValue(rules.get()), rules_);
253 } 375 }
254 376
255 RulesRegistry::~RulesRegistry() { 377 RulesRegistry::~RulesRegistry() {
256 } 378 }
257 379
258 void RulesRegistry::MarkReady(base::Time storage_init_time) { 380 void RulesRegistry::MarkReady(base::Time storage_init_time) {
259 DCHECK_CURRENTLY_ON(owner_thread()); 381 DCHECK_CURRENTLY_ON(owner_thread());
260 382
261 if (!storage_init_time.is_null()) { 383 if (!storage_init_time.is_null()) {
262 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", 384 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization",
263 base::Time::Now() - storage_init_time); 385 base::Time::Now() - storage_init_time);
264 } 386 }
265 387
266 ready_.Signal(); 388 ready_.Signal();
267 } 389 }
268 390
269 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) { 391 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) {
270 DCHECK_CURRENTLY_ON(owner_thread()); 392 DCHECK_CURRENTLY_ON(owner_thread());
271 393
272 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id)); 394 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id));
273 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING; 395 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING;
274 396
275 std::vector<linked_ptr<Rule> > new_rules; 397 std::vector<linked_ptr<Rule> > new_rules;
276 GetAllRules(extension_id, &new_rules); 398 GetRules(extension_id, rules_, &new_rules);
277 content::BrowserThread::PostTask( 399 content::BrowserThread::PostTask(
278 content::BrowserThread::UI, 400 content::BrowserThread::UI, FROM_HERE,
279 FROM_HERE, 401 base::Bind(&RulesCacheDelegate::WriteToStorage, cache_delegate_,
280 base::Bind(&RulesCacheDelegate::WriteToStorage, 402 extension_id, base::Passed(RulesToValue(new_rules))));
281 cache_delegate_,
282 extension_id,
283 base::Passed(RulesToValue(new_rules))));
284 } 403 }
285 404
286 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { 405 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) {
287 // Read and initialize |process_changed_rules_requested_[extension_id]| if 406 // Read and initialize |process_changed_rules_requested_[extension_id]| if
288 // necessary. (Note that the insertion below will not overwrite 407 // necessary. (Note that the insertion below will not overwrite
289 // |process_changed_rules_requested_[extension_id]| if that already exists. 408 // |process_changed_rules_requested_[extension_id]| if that already exists.
290 std::pair<ProcessStateMap::iterator, bool> insertion = 409 std::pair<ProcessStateMap::iterator, bool> insertion =
291 process_changed_rules_requested_.insert(std::make_pair( 410 process_changed_rules_requested_.insert(std::make_pair(
292 extension_id, 411 extension_id,
293 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS)); 412 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 for (i = identifiers.begin(); i != identifiers.end(); ++i) 486 for (i = identifiers.begin(); i != identifiers.end(); ++i)
368 used_rule_identifiers_[extension_id].erase(*i); 487 used_rule_identifiers_[extension_id].erase(*i);
369 } 488 }
370 489
371 void RulesRegistry::RemoveAllUsedRuleIdentifiers( 490 void RulesRegistry::RemoveAllUsedRuleIdentifiers(
372 const std::string& extension_id) { 491 const std::string& extension_id) {
373 used_rule_identifiers_.erase(extension_id); 492 used_rule_identifiers_.erase(extension_id);
374 } 493 }
375 494
376 } // namespace extensions 495 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/declarative/rules_registry.h ('k') | extensions/browser/api/declarative/rules_registry_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698