Chromium Code Reviews| 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" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const char kSuccess[] = ""; | 29 const char kSuccess[] = ""; |
| 29 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; | 30 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; |
| 30 | 31 |
| 31 scoped_ptr<base::Value> RulesToValue( | 32 scoped_ptr<base::Value> RulesToValue( |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 LOG(ERROR) << error; | 216 LOG(ERROR) << error; |
| 216 } | 217 } |
| 217 | 218 |
| 218 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { | 219 void RulesRegistry::OnExtensionUninstalled(const std::string& extension_id) { |
| 219 DCHECK_CURRENTLY_ON(owner_thread()); | 220 DCHECK_CURRENTLY_ON(owner_thread()); |
| 220 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); | 221 std::string error = RemoveAllRulesNoStoreUpdate(extension_id); |
| 221 if (!error.empty()) | 222 if (!error.empty()) |
| 222 LOG(ERROR) << error; | 223 LOG(ERROR) << error; |
| 223 } | 224 } |
| 224 | 225 |
| 225 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { | 226 void RulesRegistry::OnExtensionLoaded(const std::string& extension_id) { |
|
not at google - send to devlin
2015/06/02 22:44:50
Could you update OnExtensionUnloaded/Uninstalled/L
danduong
2015/06/05 06:41:57
Done.
| |
| 226 DCHECK_CURRENTLY_ON(owner_thread()); | 227 DCHECK_CURRENTLY_ON(owner_thread()); |
| 227 std::vector<linked_ptr<Rule> > rules; | 228 std::vector<linked_ptr<Rule> > rules; |
| 228 GetAllRules(extension_id, &rules); | 229 GetAllRules(extension_id, &rules); |
| 229 std::string error = AddRulesImpl(extension_id, rules); | 230 if (rules.empty()) { |
| 230 if (!error.empty()) | 231 // If no rules have been registered yet, check if there are any rules |
|
not at google - send to devlin
2015/06/02 22:44:50
Why only if there are no rules registered yet? It
danduong
2015/06/04 23:06:37
Done.
| |
| 231 LOG(ERROR) << error; | 232 // defined in the extension manifest to add. |
| 233 const Extension* extension = | |
| 234 ExtensionRegistry::Get(browser_context()) | |
| 235 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); | |
| 236 const base::ListValue* value = NULL; | |
| 237 if (extension->manifest()->GetList(event_name_, &value)) { | |
| 238 AddRules(extension_id, RulesFromValue(value)); | |
| 239 } | |
| 240 } else { | |
| 241 std::string error = AddRulesImpl(extension_id, rules); | |
| 242 if (!error.empty()) | |
| 243 LOG(ERROR) << error; | |
| 244 } | |
| 232 } | 245 } |
| 233 | 246 |
| 234 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { | 247 size_t RulesRegistry::GetNumberOfUsedRuleIdentifiersForTesting() const { |
| 235 size_t entry_count = 0u; | 248 size_t entry_count = 0u; |
| 236 for (RuleIdentifiersMap::const_iterator extension = | 249 for (RuleIdentifiersMap::const_iterator extension = |
| 237 used_rule_identifiers_.begin(); | 250 used_rule_identifiers_.begin(); |
| 238 extension != used_rule_identifiers_.end(); | 251 extension != used_rule_identifiers_.end(); |
| 239 ++extension) { | 252 ++extension) { |
| 240 // Each extension is counted as 1 just for being there. Otherwise we miss | 253 // Each extension is counted as 1 just for being there. Otherwise we miss |
| 241 // keys with empty values. | 254 // keys with empty values. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 for (i = identifiers.begin(); i != identifiers.end(); ++i) | 380 for (i = identifiers.begin(); i != identifiers.end(); ++i) |
| 368 used_rule_identifiers_[extension_id].erase(*i); | 381 used_rule_identifiers_[extension_id].erase(*i); |
| 369 } | 382 } |
| 370 | 383 |
| 371 void RulesRegistry::RemoveAllUsedRuleIdentifiers( | 384 void RulesRegistry::RemoveAllUsedRuleIdentifiers( |
| 372 const std::string& extension_id) { | 385 const std::string& extension_id) { |
| 373 used_rule_identifiers_.erase(extension_id); | 386 used_rule_identifiers_.erase(extension_id); |
| 374 } | 387 } |
| 375 | 388 |
| 376 } // namespace extensions | 389 } // namespace extensions |
| OLD | NEW |