| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace extensions { | 32 namespace extensions { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 const char kSuccess[] = ""; | 36 const char kSuccess[] = ""; |
| 37 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; | 37 const char kDuplicateRuleId[] = "Duplicate rule ID: %s"; |
| 38 const char kErrorCannotRemoveManifestRules[] = | 38 const char kErrorCannotRemoveManifestRules[] = |
| 39 "Rules declared in the 'event_rules' manifest field cannot be removed"; | 39 "Rules declared in the 'event_rules' manifest field cannot be removed"; |
| 40 | 40 |
| 41 scoped_ptr<base::Value> RulesToValue( | 41 std::unique_ptr<base::Value> RulesToValue( |
| 42 const std::vector<linked_ptr<api::events::Rule>>& rules) { | 42 const std::vector<linked_ptr<api::events::Rule>>& rules) { |
| 43 scoped_ptr<base::ListValue> list(new base::ListValue()); | 43 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 44 for (size_t i = 0; i < rules.size(); ++i) | 44 for (size_t i = 0; i < rules.size(); ++i) |
| 45 list->Append(rules[i]->ToValue().release()); | 45 list->Append(rules[i]->ToValue().release()); |
| 46 return std::move(list); | 46 return std::move(list); |
| 47 } | 47 } |
| 48 | 48 |
| 49 std::vector<linked_ptr<api::events::Rule>> RulesFromValue( | 49 std::vector<linked_ptr<api::events::Rule>> RulesFromValue( |
| 50 const base::Value* value) { | 50 const base::Value* value) { |
| 51 std::vector<linked_ptr<api::events::Rule>> rules; | 51 std::vector<linked_ptr<api::events::Rule>> rules; |
| 52 | 52 |
| 53 const base::ListValue* list = NULL; | 53 const base::ListValue* list = NULL; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 used_rule_identifiers_.begin(); | 290 used_rule_identifiers_.begin(); |
| 291 extension != used_rule_identifiers_.end(); | 291 extension != used_rule_identifiers_.end(); |
| 292 ++extension) { | 292 ++extension) { |
| 293 // Each extension is counted as 1 just for being there. Otherwise we miss | 293 // Each extension is counted as 1 just for being there. Otherwise we miss |
| 294 // keys with empty values. | 294 // keys with empty values. |
| 295 entry_count += 1u + extension->second.size(); | 295 entry_count += 1u + extension->second.size(); |
| 296 } | 296 } |
| 297 return entry_count; | 297 return entry_count; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void RulesRegistry::DeserializeAndAddRules( | 300 void RulesRegistry::DeserializeAndAddRules(const std::string& extension_id, |
| 301 const std::string& extension_id, | 301 std::unique_ptr<base::Value> rules) { |
| 302 scoped_ptr<base::Value> rules) { | |
| 303 DCHECK_CURRENTLY_ON(owner_thread()); | 302 DCHECK_CURRENTLY_ON(owner_thread()); |
| 304 | 303 |
| 305 std::string error = | 304 std::string error = |
| 306 AddRulesNoFill(extension_id, RulesFromValue(rules.get()), &rules_); | 305 AddRulesNoFill(extension_id, RulesFromValue(rules.get()), &rules_); |
| 307 if (!error.empty()) | 306 if (!error.empty()) |
| 308 ReportInternalError(extension_id, error); | 307 ReportInternalError(extension_id, error); |
| 309 } | 308 } |
| 310 | 309 |
| 311 void RulesRegistry::ReportInternalError(const std::string& extension_id, | 310 void RulesRegistry::ReportInternalError(const std::string& extension_id, |
| 312 const std::string& error) { | 311 const std::string& error) { |
| 313 scoped_ptr<ExtensionError> error_instance(new InternalError( | 312 std::unique_ptr<ExtensionError> error_instance(new InternalError( |
| 314 extension_id, base::ASCIIToUTF16(error), logging::LOG_ERROR)); | 313 extension_id, base::ASCIIToUTF16(error), logging::LOG_ERROR)); |
| 315 ExtensionsBrowserClient::Get()->ReportError(browser_context_, | 314 ExtensionsBrowserClient::Get()->ReportError(browser_context_, |
| 316 std::move(error_instance)); | 315 std::move(error_instance)); |
| 317 } | 316 } |
| 318 | 317 |
| 319 RulesRegistry::~RulesRegistry() { | 318 RulesRegistry::~RulesRegistry() { |
| 320 } | 319 } |
| 321 | 320 |
| 322 void RulesRegistry::MarkReady(base::Time storage_init_time) { | 321 void RulesRegistry::MarkReady(base::Time storage_init_time) { |
| 323 DCHECK_CURRENTLY_ON(owner_thread()); | 322 DCHECK_CURRENTLY_ON(owner_thread()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 for (i = identifiers.begin(); i != identifiers.end(); ++i) | 427 for (i = identifiers.begin(); i != identifiers.end(); ++i) |
| 429 used_rule_identifiers_[extension_id].erase(*i); | 428 used_rule_identifiers_[extension_id].erase(*i); |
| 430 } | 429 } |
| 431 | 430 |
| 432 void RulesRegistry::RemoveAllUsedRuleIdentifiers( | 431 void RulesRegistry::RemoveAllUsedRuleIdentifiers( |
| 433 const std::string& extension_id) { | 432 const std::string& extension_id) { |
| 434 used_rule_identifiers_.erase(extension_id); | 433 used_rule_identifiers_.erase(extension_id); |
| 435 } | 434 } |
| 436 | 435 |
| 437 } // namespace extensions | 436 } // namespace extensions |
| OLD | NEW |