| 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_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/api/declarative/declarative_manifest_data.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 kErrorCannotRemoveManifestRules[] = |
| 35 "Rules declared in the 'event_rules' manifest field cannot be removed"; |
| 30 | 36 |
| 31 scoped_ptr<base::Value> RulesToValue( | 37 scoped_ptr<base::Value> RulesToValue( |
| 32 const std::vector<linked_ptr<extensions::RulesRegistry::Rule> >& rules) { | 38 const std::vector<linked_ptr<RulesRegistry::Rule>>& rules) { |
| 33 scoped_ptr<base::ListValue> list(new base::ListValue()); | 39 scoped_ptr<base::ListValue> list(new base::ListValue()); |
| 34 for (size_t i = 0; i < rules.size(); ++i) | 40 for (size_t i = 0; i < rules.size(); ++i) |
| 35 list->Append(rules[i]->ToValue().release()); | 41 list->Append(rules[i]->ToValue().release()); |
| 36 return list.Pass(); | 42 return list.Pass(); |
| 37 } | 43 } |
| 38 | 44 |
| 39 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > RulesFromValue( | 45 std::vector<linked_ptr<RulesRegistry::Rule>> RulesFromValue( |
| 40 const base::Value* value) { | 46 const base::Value* value) { |
| 41 std::vector<linked_ptr<extensions::RulesRegistry::Rule> > rules; | 47 std::vector<linked_ptr<RulesRegistry::Rule>> rules; |
| 42 | 48 |
| 43 const base::ListValue* list = NULL; | 49 const base::ListValue* list = NULL; |
| 44 if (!value || !value->GetAsList(&list)) | 50 if (!value || !value->GetAsList(&list)) |
| 45 return rules; | 51 return rules; |
| 46 | 52 |
| 47 rules.reserve(list->GetSize()); | 53 rules.reserve(list->GetSize()); |
| 48 for (size_t i = 0; i < list->GetSize(); ++i) { | 54 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 49 const base::DictionaryValue* dict = NULL; | 55 const base::DictionaryValue* dict = NULL; |
| 50 if (!list->GetDictionary(i, &dict)) | 56 if (!list->GetDictionary(i, &dict)) |
| 51 continue; | 57 continue; |
| 52 linked_ptr<extensions::RulesRegistry::Rule> rule( | 58 linked_ptr<RulesRegistry::Rule> rule(new RulesRegistry::Rule()); |
| 53 new extensions::RulesRegistry::Rule()); | 59 if (RulesRegistry::Rule::Populate(*dict, rule.get())) |
| 54 if (extensions::RulesRegistry::Rule::Populate(*dict, rule.get())) | |
| 55 rules.push_back(rule); | 60 rules.push_back(rule); |
| 56 } | 61 } |
| 57 | 62 |
| 58 return rules; | 63 return rules; |
| 59 } | 64 } |
| 60 | 65 |
| 61 std::string ToId(int identifier) { | 66 std::string ToId(int identifier) { |
| 62 return base::StringPrintf("_%d_", identifier); | 67 return base::StringPrintf("_%d_", identifier); |
| 63 } | 68 } |
| 64 | 69 |
| 65 } // namespace | 70 } // namespace |
| 66 | 71 |
| 67 | 72 |
| 68 namespace extensions { | |
| 69 | |
| 70 // RulesRegistry | 73 // RulesRegistry |
| 71 | 74 |
| 72 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context, | 75 RulesRegistry::RulesRegistry(content::BrowserContext* browser_context, |
| 73 const std::string& event_name, | 76 const std::string& event_name, |
| 74 content::BrowserThread::ID owner_thread, | 77 content::BrowserThread::ID owner_thread, |
| 75 RulesCacheDelegate* cache_delegate, | 78 RulesCacheDelegate* cache_delegate, |
| 76 int id) | 79 int id) |
| 77 : browser_context_(browser_context), | 80 : browser_context_(browser_context), |
| 78 owner_thread_(owner_thread), | 81 owner_thread_(owner_thread), |
| 79 event_name_(event_name), | 82 event_name_(event_name), |
| 80 id_(id), | 83 id_(id), |
| 81 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache | 84 ready_(/*signaled=*/!cache_delegate), // Immediately ready if no cache |
| 82 // delegate to wait for. | 85 // delegate to wait for. |
| 83 last_generated_rule_identifier_id_(0), | 86 last_generated_rule_identifier_id_(0), |
| 84 weak_ptr_factory_(browser_context_ ? this : NULL) { | 87 weak_ptr_factory_(browser_context_ ? this : NULL) { |
| 85 if (cache_delegate) { | 88 if (cache_delegate) { |
| 86 cache_delegate_ = cache_delegate->GetWeakPtr(); | 89 cache_delegate_ = cache_delegate->GetWeakPtr(); |
| 87 cache_delegate->Init(this); | 90 cache_delegate->Init(this); |
| 88 } | 91 } |
| 89 } | 92 } |
| 90 | 93 |
| 91 std::string RulesRegistry::AddRulesNoFill( | 94 std::string RulesRegistry::AddRulesNoFill( |
| 92 const std::string& extension_id, | 95 const std::string& extension_id, |
| 93 const std::vector<linked_ptr<Rule> >& rules) { | 96 const std::vector<linked_ptr<Rule>>& rules, |
| 97 RulesDictionary* out) { |
| 94 DCHECK_CURRENTLY_ON(owner_thread()); | 98 DCHECK_CURRENTLY_ON(owner_thread()); |
| 95 | 99 |
| 96 // Verify that all rule IDs are new. | 100 // Verify that all rule IDs are new. |
| 97 for (std::vector<linked_ptr<Rule> >::const_iterator i = | 101 for (std::vector<linked_ptr<Rule> >::const_iterator i = |
| 98 rules.begin(); i != rules.end(); ++i) { | 102 rules.begin(); i != rules.end(); ++i) { |
| 99 const RuleId& rule_id = *((*i)->id); | 103 const RuleId& rule_id = *((*i)->id); |
| 100 // Every rule should have a priority assigned. | 104 // Every rule should have a priority assigned. |
| 101 DCHECK((*i)->priority); | 105 DCHECK((*i)->priority); |
| 102 RulesDictionaryKey key(extension_id, rule_id); | 106 RulesDictionaryKey key(extension_id, rule_id); |
| 103 if (rules_.find(key) != rules_.end()) | 107 if (rules_.find(key) != rules_.end() || |
| 108 manifest_rules_.find(key) != manifest_rules_.end()) |
| 104 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str()); | 109 return base::StringPrintf(kDuplicateRuleId, rule_id.c_str()); |
| 105 } | 110 } |
| 106 | 111 |
| 107 std::string error = AddRulesImpl(extension_id, rules); | 112 std::string error = AddRulesImpl(extension_id, rules); |
| 108 | 113 |
| 109 if (!error.empty()) | 114 if (!error.empty()) |
| 110 return error; | 115 return error; |
| 111 | 116 |
| 112 // Commit all rules into |rules_| on success. | 117 // Commit all rules into |rules_| on success. |
| 113 for (std::vector<linked_ptr<Rule> >::const_iterator i = | 118 for (std::vector<linked_ptr<Rule> >::const_iterator i = |
| 114 rules.begin(); i != rules.end(); ++i) { | 119 rules.begin(); i != rules.end(); ++i) { |
| 115 const RuleId& rule_id = *((*i)->id); | 120 const RuleId& rule_id = *((*i)->id); |
| 116 RulesDictionaryKey key(extension_id, rule_id); | 121 RulesDictionaryKey key(extension_id, rule_id); |
| 117 rules_[key] = *i; | 122 (*out)[key] = *i; |
| 118 } | 123 } |
| 119 | 124 |
| 120 MaybeProcessChangedRules(extension_id); | 125 MaybeProcessChangedRules(extension_id); |
| 121 return kSuccess; | 126 return kSuccess; |
| 122 } | 127 } |
| 123 | 128 |
| 124 std::string RulesRegistry::AddRules( | 129 std::string RulesRegistry::AddRules( |
| 125 const std::string& extension_id, | 130 const std::string& extension_id, |
| 126 const std::vector<linked_ptr<Rule> >& rules) { | 131 const std::vector<linked_ptr<Rule>>& rules) { |
| 132 return AddRulesInternal(extension_id, rules, &rules_); |
| 133 } |
| 134 |
| 135 std::string RulesRegistry::AddRulesInternal( |
| 136 const std::string& extension_id, |
| 137 const std::vector<linked_ptr<Rule>>& rules, |
| 138 RulesDictionary* out) { |
| 127 DCHECK_CURRENTLY_ON(owner_thread()); | 139 DCHECK_CURRENTLY_ON(owner_thread()); |
| 128 | 140 |
| 129 std::string error = CheckAndFillInOptionalRules(extension_id, rules); | 141 std::string error = CheckAndFillInOptionalRules(extension_id, rules); |
| 130 if (!error.empty()) | 142 if (!error.empty()) |
| 131 return error; | 143 return error; |
| 132 FillInOptionalPriorities(rules); | 144 FillInOptionalPriorities(rules); |
| 133 | 145 |
| 134 return AddRulesNoFill(extension_id, rules); | 146 return AddRulesNoFill(extension_id, rules, out); |
| 135 } | 147 } |
| 136 | 148 |
| 137 std::string RulesRegistry::RemoveRules( | 149 std::string RulesRegistry::RemoveRules( |
| 138 const std::string& extension_id, | 150 const std::string& extension_id, |
| 139 const std::vector<std::string>& rule_identifiers) { | 151 const std::vector<std::string>& rule_identifiers) { |
| 140 DCHECK_CURRENTLY_ON(owner_thread()); | 152 DCHECK_CURRENTLY_ON(owner_thread()); |
| 141 | 153 |
| 154 // Check if any of the rules are non-removable. |
| 155 for (RuleId rule_id : rule_identifiers) { |
| 156 RulesDictionaryKey lookup_key(extension_id, rule_id); |
| 157 RulesDictionary::iterator itr = manifest_rules_.find(lookup_key); |
| 158 if (itr != manifest_rules_.end()) |
| 159 return kErrorCannotRemoveManifestRules; |
| 160 } |
| 161 |
| 142 std::string error = RemoveRulesImpl(extension_id, rule_identifiers); | 162 std::string error = RemoveRulesImpl(extension_id, rule_identifiers); |
| 143 | 163 |
| 144 if (!error.empty()) | 164 if (!error.empty()) |
| 145 return error; | 165 return error; |
| 146 | 166 |
| 147 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); | 167 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); |
| 148 i != rule_identifiers.end(); | 168 i != rule_identifiers.end(); |
| 149 ++i) { | 169 ++i) { |
| 150 RulesDictionaryKey lookup_key(extension_id, *i); | 170 RulesDictionaryKey lookup_key(extension_id, *i); |
| 151 rules_.erase(lookup_key); | 171 rules_.erase(lookup_key); |
| 152 } | 172 } |
| 153 | 173 |
| 154 MaybeProcessChangedRules(extension_id); | 174 MaybeProcessChangedRules(extension_id); |
| 155 RemoveUsedRuleIdentifiers(extension_id, rule_identifiers); | 175 RemoveUsedRuleIdentifiers(extension_id, rule_identifiers); |
| 156 return kSuccess; | 176 return kSuccess; |
| 157 } | 177 } |
| 158 | 178 |
| 159 std::string RulesRegistry::RemoveAllRules(const std::string& extension_id) { | 179 std::string RulesRegistry::RemoveAllRules(const std::string& extension_id) { |
| 160 std::string result = RulesRegistry::RemoveAllRulesNoStoreUpdate(extension_id); | 180 std::string result = |
| 181 RulesRegistry::RemoveAllRulesNoStoreUpdate(extension_id, false); |
| 161 MaybeProcessChangedRules(extension_id); // Now update the prefs and store. | 182 MaybeProcessChangedRules(extension_id); // Now update the prefs and store. |
| 162 return result; | 183 return result; |
| 163 } | 184 } |
| 164 | 185 |
| 165 std::string RulesRegistry::RemoveAllRulesNoStoreUpdate( | 186 std::string RulesRegistry::RemoveAllRulesNoStoreUpdate( |
| 166 const std::string& extension_id) { | 187 const std::string& extension_id, |
| 188 bool remove_manifest_rules) { |
| 167 DCHECK_CURRENTLY_ON(owner_thread()); | 189 DCHECK_CURRENTLY_ON(owner_thread()); |
| 168 | 190 |
| 169 std::string error = RemoveAllRulesImpl(extension_id); | 191 std::string error = RemoveAllRulesImpl(extension_id); |
| 170 | 192 |
| 171 if (!error.empty()) | 193 if (!error.empty()) |
| 172 return error; | 194 return error; |
| 173 | 195 |
| 174 for (RulesDictionary::const_iterator i = rules_.begin(); | 196 auto remove_rules = [&extension_id](RulesDictionary& dictionary) { |
| 175 i != rules_.end();) { | 197 for (auto it = dictionary.begin(); it != dictionary.end();) { |
| 176 const RulesDictionaryKey& key = i->first; | 198 if (it->first.first == extension_id) |
| 177 ++i; | 199 dictionary.erase(it++); |
| 178 if (key.first == extension_id) | 200 else |
| 179 rules_.erase(key); | 201 ++it; |
| 180 } | 202 } |
| 203 }; |
| 204 remove_rules(rules_); |
| 205 if (remove_manifest_rules) |
| 206 remove_rules(manifest_rules_); |
| 181 | 207 |
| 182 RemoveAllUsedRuleIdentifiers(extension_id); | 208 RemoveAllUsedRuleIdentifiers(extension_id); |
| 183 return kSuccess; | 209 return kSuccess; |
| 184 } | 210 } |
| 185 | 211 |
| 186 void RulesRegistry::GetRules(const std::string& extension_id, | 212 void RulesRegistry::GetRules(const std::string& extension_id, |
| 187 const std::vector<std::string>& rule_identifiers, | 213 const std::vector<std::string>& rule_identifiers, |
| 188 std::vector<linked_ptr<Rule> >* out) { | 214 std::vector<linked_ptr<Rule> >* out) { |
| 189 DCHECK_CURRENTLY_ON(owner_thread()); | 215 DCHECK_CURRENTLY_ON(owner_thread()); |
| 190 | 216 |
| 191 for (std::vector<std::string>::const_iterator i = rule_identifiers.begin(); | 217 for (const auto& i : rule_identifiers) { |
| 192 i != rule_identifiers.end(); ++i) { | 218 RulesDictionaryKey lookup_key(extension_id, i); |
| 193 RulesDictionaryKey lookup_key(extension_id, *i); | |
| 194 RulesDictionary::iterator entry = rules_.find(lookup_key); | 219 RulesDictionary::iterator entry = rules_.find(lookup_key); |
| 195 if (entry != rules_.end()) | 220 if (entry != rules_.end()) |
| 196 out->push_back(entry->second); | 221 out->push_back(entry->second); |
| 222 entry = manifest_rules_.find(lookup_key); |
| 223 if (entry != manifest_rules_.end()) |
| 224 out->push_back(entry->second); |
| 225 } |
| 226 } |
| 227 |
| 228 void RulesRegistry::GetRules( |
| 229 const std::string& extension_id, |
| 230 RulesDictionary& rules, |
| 231 std::vector<linked_ptr<RulesRegistry::Rule>>* out) { |
| 232 for (const auto& i : rules) { |
| 233 const RulesDictionaryKey& key = i.first; |
| 234 if (key.first == extension_id) |
| 235 out->push_back(i.second); |
| 197 } | 236 } |
| 198 } | 237 } |
| 199 | 238 |
| 200 void RulesRegistry::GetAllRules(const std::string& extension_id, | 239 void RulesRegistry::GetAllRules(const std::string& extension_id, |
| 201 std::vector<linked_ptr<Rule> >* out) { | 240 std::vector<linked_ptr<Rule> >* out) { |
| 202 DCHECK_CURRENTLY_ON(owner_thread()); | 241 DCHECK_CURRENTLY_ON(owner_thread()); |
| 203 for (RulesDictionary::const_iterator i = rules_.begin(); | 242 GetRules(extension_id, manifest_rules_, out); |
| 204 i != rules_.end(); ++i) { | 243 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 } | 244 } |
| 210 | 245 |
| 211 void RulesRegistry::OnExtensionUnloaded(const std::string& extension_id) { | 246 void RulesRegistry::OnExtensionUnloaded(const Extension* extension) { |
| 212 DCHECK_CURRENTLY_ON(owner_thread()); | 247 DCHECK_CURRENTLY_ON(owner_thread()); |
| 213 std::string error = RemoveAllRulesImpl(extension_id); | 248 std::string error = RemoveAllRulesImpl(extension->id()); |
| 214 if (!error.empty()) | 249 if (!error.empty()) |
| 215 LOG(ERROR) << error; | 250 LOG(ERROR) << error; |
| 216 } | 251 } |
| 217 | 252 |
| 218 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { | 253 void RulesRegistry::OnExtensionUninstalled(const Extension* extension) { |
| 219 DCHECK_CURRENTLY_ON(owner_thread()); | 254 DCHECK_CURRENTLY_ON(owner_thread()); |
| 220 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); | 255 std::string error = RemoveAllRulesNoStoreUpdate(extension->id(), true); |
| 221 if (!error.empty()) | 256 if (!error.empty()) |
| 222 LOG(ERROR) << error; | 257 LOG(ERROR) << error; |
| 223 } | 258 } |
| 224 | 259 |
| 225 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { | 260 void RulesRegistry::OnExtensionLoaded(const Extension* extension) { |
| 226 DCHECK_CURRENTLY_ON(owner_thread()); | 261 DCHECK_CURRENTLY_ON(owner_thread()); |
| 227 std::vector<linked_ptr<Rule> > rules; | 262 std::vector<linked_ptr<Rule>> rules; |
| 228 GetAllRules(extension_id, &rules); | 263 GetAllRules(extension->id(), &rules); |
| 229 std::string error = AddRulesImpl(extension_id, rules); | 264 DeclarativeManifestData* declarative_data = |
| 265 DeclarativeManifestData::Get(extension); |
| 266 if (declarative_data) { |
| 267 std::vector<linked_ptr<Rule>>& manifest_rules = |
| 268 declarative_data->RulesForEvent(event_name_); |
| 269 if (manifest_rules.size()) { |
| 270 std::string error = |
| 271 AddRulesInternal(extension->id(), manifest_rules, &manifest_rules_); |
| 272 if (!error.empty()) |
| 273 LOG(ERROR) << error; |
| 274 } |
| 275 } |
| 276 std::string error = AddRulesImpl(extension->id(), rules); |
| 230 if (!error.empty()) | 277 if (!error.empty()) |
| 231 LOG(ERROR) << error; | 278 LOG(ERROR) << error; |
| 232 } | 279 } |
| 233 | 280 |
| 234 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { | 281 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { |
| 235 size_t entry_count = 0u; | 282 size_t entry_count = 0u; |
| 236 for (RuleIdentifiersMap::const_iterator extension = | 283 for (RuleIdentifiersMap::const_iterator extension = |
| 237 used_rule_identifiers_.begin(); | 284 used_rule_identifiers_.begin(); |
| 238 extension != used_rule_identifiers_.end(); | 285 extension != used_rule_identifiers_.end(); |
| 239 ++extension) { | 286 ++extension) { |
| 240 // Each extension is counted as 1 just for being there. Otherwise we miss | 287 // Each extension is counted as 1 just for being there. Otherwise we miss |
| 241 // keys with empty values. | 288 // keys with empty values. |
| 242 entry_count += 1u + extension->second.size(); | 289 entry_count += 1u + extension->second.size(); |
| 243 } | 290 } |
| 244 return entry_count; | 291 return entry_count; |
| 245 } | 292 } |
| 246 | 293 |
| 247 void RulesRegistry::DeserializeAndAddRules( | 294 void RulesRegistry::DeserializeAndAddRules( |
| 248 const std::string& extension_id, | 295 const std::string& extension_id, |
| 249 scoped_ptr<base::Value> rules) { | 296 scoped_ptr<base::Value> rules) { |
| 250 DCHECK_CURRENTLY_ON(owner_thread()); | 297 DCHECK_CURRENTLY_ON(owner_thread()); |
| 251 | 298 |
| 252 AddRulesNoFill(extension_id, RulesFromValue(rules.get())); | 299 AddRulesNoFill(extension_id, RulesFromValue(rules.get()), &rules_); |
| 253 } | 300 } |
| 254 | 301 |
| 255 RulesRegistry::~RulesRegistry() { | 302 RulesRegistry::~RulesRegistry() { |
| 256 } | 303 } |
| 257 | 304 |
| 258 void RulesRegistry::MarkReady(base::Time storage_init_time) { | 305 void RulesRegistry::MarkReady(base::Time storage_init_time) { |
| 259 DCHECK_CURRENTLY_ON(owner_thread()); | 306 DCHECK_CURRENTLY_ON(owner_thread()); |
| 260 | 307 |
| 261 if (!storage_init_time.is_null()) { | 308 if (!storage_init_time.is_null()) { |
| 262 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", | 309 UMA_HISTOGRAM_TIMES("Extensions.DeclarativeRulesStorageInitialization", |
| 263 base::Time::Now() - storage_init_time); | 310 base::Time::Now() - storage_init_time); |
| 264 } | 311 } |
| 265 | 312 |
| 266 ready_.Signal(); | 313 ready_.Signal(); |
| 267 } | 314 } |
| 268 | 315 |
| 269 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) { | 316 void RulesRegistry::ProcessChangedRules(const std::string& extension_id) { |
| 270 DCHECK_CURRENTLY_ON(owner_thread()); | 317 DCHECK_CURRENTLY_ON(owner_thread()); |
| 271 | 318 |
| 272 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id)); | 319 DCHECK(ContainsKey(process_changed_rules_requested_, extension_id)); |
| 273 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING; | 320 process_changed_rules_requested_[extension_id] = NOT_SCHEDULED_FOR_PROCESSING; |
| 274 | 321 |
| 275 std::vector<linked_ptr<Rule> > new_rules; | 322 std::vector<linked_ptr<Rule> > new_rules; |
| 276 GetAllRules(extension_id, &new_rules); | 323 GetRules(extension_id, rules_, &new_rules); |
| 277 content::BrowserThread::PostTask( | 324 content::BrowserThread::PostTask( |
| 278 content::BrowserThread::UI, | 325 content::BrowserThread::UI, FROM_HERE, |
| 279 FROM_HERE, | 326 base::Bind(&RulesCacheDelegate::WriteToStorage, cache_delegate_, |
| 280 base::Bind(&RulesCacheDelegate::WriteToStorage, | 327 extension_id, base::Passed(RulesToValue(new_rules)))); |
| 281 cache_delegate_, | |
| 282 extension_id, | |
| 283 base::Passed(RulesToValue(new_rules)))); | |
| 284 } | 328 } |
| 285 | 329 |
| 286 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { | 330 void RulesRegistry::MaybeProcessChangedRules(const std::string& extension_id) { |
| 287 // Read and initialize |process_changed_rules_requested_[extension_id]| if | 331 // Read and initialize |process_changed_rules_requested_[extension_id]| if |
| 288 // necessary. (Note that the insertion below will not overwrite | 332 // necessary. (Note that the insertion below will not overwrite |
| 289 // |process_changed_rules_requested_[extension_id]| if that already exists. | 333 // |process_changed_rules_requested_[extension_id]| if that already exists. |
| 290 std::pair<ProcessStateMap::iterator, bool> insertion = | 334 std::pair<ProcessStateMap::iterator, bool> insertion = |
| 291 process_changed_rules_requested_.insert(std::make_pair( | 335 process_changed_rules_requested_.insert(std::make_pair( |
| 292 extension_id, | 336 extension_id, |
| 293 browser_context_ ? NOT_SCHEDULED_FOR_PROCESSING : NEVER_PROCESS)); | 337 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) | 411 for (i = identifiers.begin(); i != identifiers.end(); ++i) |
| 368 used_rule_identifiers_[extension_id].erase(*i); | 412 used_rule_identifiers_[extension_id].erase(*i); |
| 369 } | 413 } |
| 370 | 414 |
| 371 void RulesRegistry::RemoveAllUsedRuleIdentifiers( | 415 void RulesRegistry::RemoveAllUsedRuleIdentifiers( |
| 372 const std::string& extension_id) { | 416 const std::string& extension_id) { |
| 373 used_rule_identifiers_.erase(extension_id); | 417 used_rule_identifiers_.erase(extension_id); |
| 374 } | 418 } |
| 375 | 419 |
| 376 } // namespace extensions | 420 } // namespace extensions |
| OLD | NEW |