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 "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_registry.h" | |
22 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
23 #include "extensions/browser/state_store.h" | 24 #include "extensions/browser/state_store.h" |
24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
26 #include "extensions/common/manifest_constants.h" | |
27 | |
28 namespace extensions { | |
25 | 29 |
26 namespace { | 30 namespace { |
27 | 31 |
28 const char kSuccess[] = ""; | 32 const char kSuccess[] = ""; |
29 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; | 33 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; |
34 const char kErrorNonRemovableRules[] = "List contains non-removable rules"; | |
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 |
62 return rules; | |
63 } | |
64 | |
65 scoped_ptr<base::ListValue> ConvertListFromManifest( | |
66 const base::ListValue* list) { | |
67 scoped_ptr<base::ListValue> result(new base::ListValue); | |
68 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); | |
69 ++it) { | |
70 base::DictionaryValue* dictionary = nullptr; | |
71 if (!(*it)->GetAsDictionary(&dictionary)) | |
72 continue; | |
73 std::string type; | |
74 if (!dictionary->GetString("type", &type)) | |
75 continue; | |
76 scoped_ptr<base::DictionaryValue> copy = dictionary->CreateDeepCopy(); | |
77 copy->Remove("type", NULL); | |
78 copy->SetString("instanceType", type); | |
79 result->Append(copy.Pass()); | |
80 } | |
81 return result.Pass(); | |
82 } | |
83 | |
84 std::vector<linked_ptr<RulesRegistry::Rule>> RulesFromManifest( | |
85 const base::Value* value, | |
86 const std::string& event_name) { | |
87 std::vector<linked_ptr<RulesRegistry::Rule>> rules; | |
88 | |
89 const base::ListValue* list = nullptr; | |
90 if (!value || !value->GetAsList(&list)) | |
91 return rules; | |
92 | |
93 for (size_t i = 0; i < list->GetSize(); ++i) { | |
94 const base::DictionaryValue* dict = nullptr; | |
95 if (!list->GetDictionary(i, &dict)) | |
96 continue; | |
97 std::string event; | |
98 if (!dict->GetString("event", &event)) | |
99 continue; | |
100 if (event_name != event) | |
101 continue; | |
102 const base::ListValue* list; | |
103 if (!dict->GetList("conditions", &list) || !list->GetSize()) | |
104 continue; | |
105 scoped_ptr<base::ListValue> conditions = ConvertListFromManifest(list); | |
106 if (!conditions->GetSize()) | |
107 continue; | |
108 if (!dict->GetList("actions", &list) || !list->GetSize()) | |
109 continue; | |
110 scoped_ptr<base::ListValue> actions = ConvertListFromManifest(list); | |
111 if (!actions->GetSize()) | |
112 continue; | |
113 scoped_ptr<base::DictionaryValue> rule_dict(new base::DictionaryValue); | |
114 rule_dict->Set("conditions", conditions.Pass()); | |
115 rule_dict->Set("actions", actions.Pass()); | |
116 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule()); | |
117 if (RulesRegistry::Rule::Populate(*rule_dict, rule.get())) | |
118 rules.push_back(rule); | |
119 } | |
120 | |
58 return rules; | 121 return rules; |
59 } | 122 } |
60 | 123 |
61 std::string ToId(int identifier) { | 124 std::string ToId(int identifier) { |
62 return base::StringPrintf("_%d_", identifier); | 125 return base::StringPrintf("_%d_", identifier); |
63 } | 126 } |
64 | 127 |
65 } // namespace | 128 } // namespace |
66 | 129 |
67 | 130 |
68 namespace extensions { | |
69 | |
70 // RulesRegistry | 131 // RulesRegistry |
71 | 132 |
72 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context, | 133 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context, |
73 const std::string& event_name, | 134 const std::string& event_name, |
74 content::BrowserThread::ID owner_thread, | 135 content::BrowserThread::ID owner_thread, |
75 RulesCacheDelegate* cache_delegate, | 136 RulesCacheDelegate* cache_delegate, |
76 int id) | 137 int id) |
77 : browser_context_(browser_context), | 138 : browser_context_(browser_context), |
78 owner_thread_(owner_thread), | 139 owner_thread_(owner_thread), |
79 event_name_(event_name), | 140 event_name_(event_name), |
80 id_(id), | 141 id_(id), |
81 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache | 142 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache |
82 // delegate to wait for. | 143 // delegate to wait for. |
83 last_generated_rule_identifier_id_(0), | 144 last_generated_rule_identifier_id_(0), |
84 weak_ptr_factory_(browser_context_ ? this : NULL) { | 145 weak_ptr_factory_(browser_context_ ? this : NULL) { |
85 if (cache_delegate) { | 146 if (cache_delegate) { |
86 cache_delegate_ = cache_delegate->GetWeakPtr(); | 147 cache_delegate_ = cache_delegate->GetWeakPtr(); |
87 cache_delegate->Init(this); | 148 cache_delegate->Init(this); |
88 } | 149 } |
89 } | 150 } |
90 | 151 |
91 std::string RulesRegistry::AddRulesNoFill( | 152 std::string RulesRegistry::AddRulesNoFill( |
92 const std::string& extension_id, | 153 const std::string& extension_id, |
93 const std::vector<linked_ptr<Rule> >& rules) { | 154 const std::vector<linked_ptr<Rule>>& rules, |
155 bool from_manifest) { | |
94 DCHECK_CURRENTLY_ON(owner_thread()); | 156 DCHECK_CURRENTLY_ON(owner_thread()); |
95 | 157 |
96 // Verify that all rule IDs are new. | 158 // Verify that all rule IDs are new. |
97 for (std::vector<linked_ptr<Rule> >::const_iterator i = | 159 for (std::vector<linked_ptr<Rule> >::const_iterator i = |
98 rules.begin(); i != rules.end(); ++i) { | 160 rules.begin(); i != rules.end(); ++i) { |
99 const RuleId& rule_id = *((*i)->id); | 161 const RuleId& rule_id = *((*i)->id); |
100 // Every rule should have a priority assigned. | 162 // Every rule should have a priority assigned. |
101 DCHECK((*i)->priority); | 163 DCHECK((*i)->priority); |
102 RulesDictionaryKey key(extension_id, rule_id); | 164 RulesDictionaryKey key(extension_id, rule_id); |
165 if (from_manifest) | |
166 manifest_rule_ids_.insert(key); | |
103 if (rules_.find(key) != rules_.end()) | 167 if (rules_.find(key) != rules_.end()) |
104 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str()); | 168 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str()); |
105 } | 169 } |
106 | 170 |
107 std::string error = AddRulesImpl(extension_id, rules); | 171 std::string error = AddRulesImpl(extension_id, rules); |
108 | 172 |
109 if (!error.empty()) | 173 if (!error.empty()) |
110 return error; | 174 return error; |
111 | 175 |
112 // Commit all rules into |rules_| on success. | 176 // Commit all rules into |rules_| on success. |
113 for (std::vector<linked_ptr<Rule> >::const_iterator i = | 177 for (std::vector<linked_ptr<Rule> >::const_iterator i = |
114 rules.begin(); i != rules.end(); ++i) { | 178 rules.begin(); i != rules.end(); ++i) { |
115 const RuleId& rule_id = *((*i)->id); | 179 const RuleId& rule_id = *((*i)->id); |
116 RulesDictionaryKey key(extension_id, rule_id); | 180 RulesDictionaryKey key(extension_id, rule_id); |
117 rules_[key] = *i; | 181 rules_[key] = *i; |
118 } | 182 } |
119 | 183 |
120 MaybeProcessChangedRules(extension_id); | 184 MaybeProcessChangedRules(extension_id); |
121 return kSuccess; | 185 return kSuccess; |
122 } | 186 } |
123 | 187 |
124 std::string RulesRegistry::AddRules( | 188 std::string RulesRegistry::AddRules(const std::string& extension_id, |
125 const std::string& extension_id, | 189 const std::vector<linked_ptr<Rule>>& rules, |
126 const std::vector<linked_ptr<Rule> >& rules) { | 190 bool from_manifest) { |
127 DCHECK_CURRENTLY_ON(owner_thread()); | 191 DCHECK_CURRENTLY_ON(owner_thread()); |
128 | 192 |
129 std::string error = CheckAndFillInOptionalRules(extension_id, rules); | 193 std::string error = CheckAndFillInOptionalRules(extension_id, rules); |
130 if (!error.empty()) | 194 if (!error.empty()) |
131 return error; | 195 return error; |
132 FillInOptionalPriorities(rules); | 196 FillInOptionalPriorities(rules); |
133 | 197 |
134 return AddRulesNoFill(extension_id, rules); | 198 return AddRulesNoFill(extension_id, rules, from_manifest); |
135 } | 199 } |
136 | 200 |
137 std::string RulesRegistry::RemoveRules( | 201 std::string RulesRegistry::RemoveRules( |
138 const std::string& extension_id, | 202 const std::string& extension_id, |
139 const std::vector<std::string>& rule_identifiers) { | 203 const std::vector<std::string>& rule_identifiers) { |
140 DCHECK_CURRENTLY_ON(owner_thread()); | 204 DCHECK_CURRENTLY_ON(owner_thread()); |
141 | 205 |
206 // Check if any of the rules are non-removable. | |
207 for (RuleId rule_id : rule_identifiers) { | |
208 RulesDictionaryKey lookup_key(extension_id, rule_id); | |
209 RuleIdSet::iterator itr = manifest_rule_ids_.find(lookup_key); | |
210 if (itr != manifest_rule_ids_.end()) | |
211 return kErrorNonRemovableRules; | |
212 } | |
213 | |
142 std::string error = RemoveRulesImpl(extension_id, rule_identifiers); | 214 std::string error = RemoveRulesImpl(extension_id, rule_identifiers); |
143 | 215 |
144 if (!error.empty()) | 216 if (!error.empty()) |
145 return error; | 217 return error; |
146 | 218 |
147 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); | 219 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); |
148 i != rule_identifiers.end(); | 220 i != rule_identifiers.end(); |
149 ++i) { | 221 ++i) { |
150 RulesDictionaryKey lookup_key(extension_id, *i); | 222 RulesDictionaryKey lookup_key(extension_id, *i); |
151 rules_.erase(lookup_key); | 223 rules_.erase(lookup_key); |
(...skipping 16 matching lines...) Expand all Loading... | |
168 | 240 |
169 std::string error = RemoveAllRulesImpl(extension_id); | 241 std::string error = RemoveAllRulesImpl(extension_id); |
170 | 242 |
171 if (!error.empty()) | 243 if (!error.empty()) |
172 return error; | 244 return error; |
173 | 245 |
174 for (RulesDictionary::const_iterator i = rules_.begin(); | 246 for (RulesDictionary::const_iterator i = rules_.begin(); |
175 i != rules_.end();) { | 247 i != rules_.end();) { |
176 const RulesDictionaryKey& key = i->first; | 248 const RulesDictionaryKey& key = i->first; |
177 ++i; | 249 ++i; |
178 if (key.first == extension_id) | 250 if (key.first == extension_id) { |
179 rules_.erase(key); | 251 rules_.erase(key); |
252 manifest_rule_ids_.erase(key); | |
253 } | |
180 } | 254 } |
181 | 255 |
182 RemoveAllUsedRuleIdentifiers(extension_id); | 256 RemoveAllUsedRuleIdentifiers(extension_id); |
183 return kSuccess; | 257 return kSuccess; |
184 } | 258 } |
185 | 259 |
186 void RulesRegistry::GetRules(const std::string& extension_id, | 260 void RulesRegistry::GetRules(const std::string& extension_id, |
187 const std::vector<std::string>& rule_identifiers, | 261 const std::vector<std::string>& rule_identifiers, |
188 std::vector<linked_ptr<Rule> >* out) { | 262 std::vector<linked_ptr<Rule> >* out) { |
189 DCHECK_CURRENTLY_ON(owner_thread()); | 263 DCHECK_CURRENTLY_ON(owner_thread()); |
190 | 264 |
191 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); | 265 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); |
192 i != rule_identifiers.end(); ++i) { | 266 i != rule_identifiers.end(); ++i) { |
193 RulesDictionaryKey lookup_key(extension_id, *i); | 267 RulesDictionaryKey lookup_key(extension_id, *i); |
194 RulesDictionary::iterator entry = rules_.find(lookup_key); | 268 RulesDictionary::iterator entry = rules_.find(lookup_key); |
195 if (entry != rules_.end()) | 269 if (entry != rules_.end()) |
196 out->push_back(entry->second); | 270 out->push_back(entry->second); |
197 } | 271 } |
198 } | 272 } |
199 | 273 |
200 void RulesRegistry::GetAllRules(const std::string& extension_id, | 274 void RulesRegistry::GetAllRules(const std::string& extension_id, |
201 std::vector<linked_ptr<Rule> >* out) { | 275 std::vector<linked_ptr<Rule> >* out) { |
202 DCHECK_CURRENTLY_ON(owner_thread()); | 276 DCHECK_CURRENTLY_ON(owner_thread()); |
203 for (RulesDictionary::const_iterator i = rules_.begin(); | 277 for (RulesDictionary::const_iterator i = rules_.begin(); |
204 i != rules_.end(); ++i) { | 278 i != rules_.end(); ++i) { |
not at google - send to devlin
2015/06/04 22:00:50
here and in GetRules, augment the list you return
not at google - send to devlin
2015/06/04 22:01:20
where manifest rules are a different set of rules.
danduong
2015/06/04 22:02:33
They should already be in there. The manifest rule
not at google - send to devlin
2015/06/04 22:09:28
yes. don't put them in rules.
danduong
2015/06/04 23:06:37
Done.
| |
205 const RulesDictionaryKey& key = i->first; | 279 const RulesDictionaryKey& key = i->first; |
206 if (key.first == extension_id) | 280 if (key.first == extension_id) |
207 out->push_back(i->second); | 281 out->push_back(i->second); |
208 } | 282 } |
209 } | 283 } |
210 | 284 |
211 void RulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { | 285 void RulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { |
212 DCHECK_CURRENTLY_ON(owner_thread()); | 286 DCHECK_CURRENTLY_ON(owner_thread()); |
213 std::string error = RemoveAllRulesImpl(extension_id); | 287 std::string error = RemoveAllRulesImpl(extension_id); |
214 if (!error.empty()) | 288 if (!error.empty()) |
215 LOG(ERROR) << error; | 289 LOG(ERROR) << error; |
216 } | 290 } |
217 | 291 |
218 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { | 292 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { |
219 DCHECK_CURRENTLY_ON(owner_thread()); | 293 DCHECK_CURRENTLY_ON(owner_thread()); |
220 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); | 294 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); |
221 if (!error.empty()) | 295 if (!error.empty()) |
222 LOG(ERROR) << error; | 296 LOG(ERROR) << error; |
223 } | 297 } |
224 | 298 |
225 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { | 299 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { |
226 DCHECK_CURRENTLY_ON(owner_thread()); | 300 DCHECK_CURRENTLY_ON(owner_thread()); |
227 std::vector<linked_ptr<Rule> > rules; | 301 const Extension* extension = |
302 ExtensionRegistry::Get(browser_context()) | |
303 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | |
304 const base::ListValue* value = NULL; | |
305 if (extension->manifest()->GetList(manifest_keys::kEventRules, &value)) { | |
306 std::string error = | |
307 AddRules(extension_id, RulesFromManifest(value, event_name_), true); | |
308 if (!error.empty()) | |
309 LOG(ERROR) << error; | |
310 } | |
311 std::vector<linked_ptr<Rule>> rules; | |
228 GetAllRules(extension_id, &rules); | 312 GetAllRules(extension_id, &rules); |
229 std::string error = AddRulesImpl(extension_id, rules); | 313 std::string error = AddRulesImpl(extension_id, rules); |
230 if (!error.empty()) | 314 if (!error.empty()) |
231 LOG(ERROR) << error; | 315 LOG(ERROR) << error; |
232 } | 316 } |
233 | 317 |
234 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { | 318 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { |
235 size_t entry_count = 0u; | 319 size_t entry_count = 0u; |
236 for (RuleIdentifiersMap::const_iterator extension = | 320 for (RuleIdentifiersMap::const_iterator extension = |
237 used_rule_identifiers_.begin(); | 321 used_rule_identifiers_.begin(); |
238 extension != used_rule_identifiers_.end(); | 322 extension != used_rule_identifiers_.end(); |
239 ++extension) { | 323 ++extension) { |
240 // Each extension is counted as 1 just for being there. Otherwise we miss | 324 // Each extension is counted as 1 just for being there. Otherwise we miss |
241 // keys with empty values. | 325 // keys with empty values. |
242 entry_count += 1u + extension->second.size(); | 326 entry_count += 1u + extension->second.size(); |
243 } | 327 } |
244 return entry_count; | 328 return entry_count; |
245 } | 329 } |
246 | 330 |
247 void RulesRegistry::DeserializeAndAddRules( | 331 void RulesRegistry::DeserializeAndAddRules( |
248 const std::string& extension_id, | 332 const std::string& extension_id, |
249 scoped_ptr<base::Value> rules) { | 333 scoped_ptr<base::Value> rules) { |
250 DCHECK_CURRENTLY_ON(owner_thread()); | 334 DCHECK_CURRENTLY_ON(owner_thread()); |
251 | 335 |
252 AddRulesNoFill(extension_id, RulesFromValue(rules.get())); | 336 AddRulesNoFill(extension_id, RulesFromValue(rules.get()), false); |
253 } | 337 } |
254 | 338 |
255 RulesRegistry::~RulesRegistry() { | 339 RulesRegistry::~RulesRegistry() { |
256 } | 340 } |
257 | 341 |
258 void RulesRegistry::MarkReady(base::Time storage_init_time) { | 342 void RulesRegistry::MarkReady(base::Time storage_init_time) { |
259 DCHECK_CURRENTLY_ON(owner_thread()); | 343 DCHECK_CURRENTLY_ON(owner_thread()); |
260 | 344 |
261 if (!storage_init_time.is_null()) { | 345 if (!storage_init_time.is_null()) { |
262 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", | 346 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", |
263 base::Time::Now() - storage_init_time); | 347 base::Time::Now() - storage_init_time); |
264 } | 348 } |
265 | 349 |
266 ready_.Signal(); | 350 ready_.Signal(); |
267 } | 351 } |
268 | 352 |
269 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) { | 353 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) { |
270 DCHECK_CURRENTLY_ON(owner_thread()); | 354 DCHECK_CURRENTLY_ON(owner_thread()); |
271 | 355 |
272 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id)); | 356 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id)); |
273 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING; | 357 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING; |
274 | 358 |
275 std::vector<linked_ptr<Rule> > new_rules; | 359 std::vector<linked_ptr<Rule> > new_rules; |
276 GetAllRules(extension_id, &new_rules); | 360 GetAllRules(extension_id, &new_rules); |
361 std::vector<linked_ptr<Rule>> rules_to_write; | |
362 for (auto rule : new_rules) { | |
363 const RuleId& rule_id = *(rule->id); | |
364 RulesDictionaryKey key(extension_id, rule_id); | |
365 // Only write rules that were added programmatically. | |
366 if (manifest_rule_ids_.find(key) == manifest_rule_ids_.end()) | |
367 rules_to_write.push_back(rule); | |
368 } | |
277 content::BrowserThread::PostTask( | 369 content::BrowserThread::PostTask( |
278 content::BrowserThread::UI, | 370 content::BrowserThread::UI, FROM_HERE, |
279 FROM_HERE, | 371 base::Bind(&RulesCacheDelegate::WriteToStorage, cache_delegate_, |
280 base::Bind(&RulesCacheDelegate::WriteToStorage, | 372 extension_id, base::Passed(RulesToValue(rules_to_write)))); |
281 cache_delegate_, | |
282 extension_id, | |
283 base::Passed(RulesToValue(new_rules)))); | |
284 } | 373 } |
285 | 374 |
286 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { | 375 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { |
287 // Read and initialize |process_changed_rules_requested_[extension_id]| if | 376 // Read and initialize |process_changed_rules_requested_[extension_id]| if |
288 // necessary. (Note that the insertion below will not overwrite | 377 // necessary. (Note that the insertion below will not overwrite |
289 // |process_changed_rules_requested_[extension_id]| if that already exists. | 378 // |process_changed_rules_requested_[extension_id]| if that already exists. |
290 std::pair<ProcessStateMap::iterator, bool> insertion = | 379 std::pair<ProcessStateMap::iterator, bool> insertion = |
291 process_changed_rules_requested_.insert(std::make_pair( | 380 process_changed_rules_requested_.insert(std::make_pair( |
292 extension_id, | 381 extension_id, |
293 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS)); | 382 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 for (i = identifiers.begin(); i != identifiers.end(); ++i) | 456 for (i = identifiers.begin(); i != identifiers.end(); ++i) |
368 used_rule_identifiers_[extension_id].erase(*i); | 457 used_rule_identifiers_[extension_id].erase(*i); |
369 } | 458 } |
370 | 459 |
371 void RulesRegistry::RemoveAllUsedRuleIdentifiers( | 460 void RulesRegistry::RemoveAllUsedRuleIdentifiers( |
372 const std::string& extension_id) { | 461 const std::string& extension_id) { |
373 used_rule_identifiers_.erase(extension_id); | 462 used_rule_identifiers_.erase(extension_id); |
374 } | 463 } |
375 | 464 |
376 } // namespace extensions | 465 } // namespace extensions |
OLD | NEW |