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

Unified Diff: chrome/browser/extensions/api/declarative/test_rules_registry.cc

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leaks Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/declarative/test_rules_registry.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/declarative/test_rules_registry.cc
diff --git a/chrome/browser/extensions/api/declarative/test_rules_registry.cc b/chrome/browser/extensions/api/declarative/test_rules_registry.cc
index f379c0b45ee14ebb93665371b4ee64a48abcb67a..6766c8e664798e2bc285be500a332443e6696aee 100644
--- a/chrome/browser/extensions/api/declarative/test_rules_registry.cc
+++ b/chrome/browser/extensions/api/declarative/test_rules_registry.cc
@@ -6,39 +6,33 @@
#include "base/logging.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/declarative/declarative_api_constants.h"
-
-namespace keys = extensions::declarative_api_constants;
+#include "content/public/browser/browser_thread.h"
namespace {
const char kSuccess[] = "";
const char kRuleNotFound[] = "Rule not found.";
-std::string GetRuleId(DictionaryValue* rule) {
- std::string rule_id;
- CHECK(rule->GetString(keys::kId, &rule_id));
- return rule_id;
-}
-
} // namespace
namespace extensions {
-TestRulesRegistry::TestRulesRegistry() {}
+TestRulesRegistry::TestRulesRegistry()
+ : owner_thread_(content::BrowserThread::UI) {}
TestRulesRegistry::~TestRulesRegistry() {}
std::string TestRulesRegistry::AddRules(
const std::string& extension_id,
- const std::vector<DictionaryValue*>& rules) {
+ const std::vector<linked_ptr<Rule> >& rules) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
// TODO(battre) this ignores the extension_id but should not.
- for (std::vector<DictionaryValue*>::const_iterator i =
+ for (std::vector<linked_ptr<Rule> >::const_iterator i =
rules.begin(); i != rules.end(); ++i) {
- std::string rule_id = GetRuleId(*i);
+ std::string rule_id = *((*i)->id);
// TODO: relax this (check first and abort with returning false).
CHECK(rules_.find(rule_id) == rules_.end());
- rules_[rule_id] = make_linked_ptr((*i)->DeepCopy());
+ rules_[rule_id] = *i;
}
return kSuccess;
}
@@ -46,6 +40,7 @@ std::string TestRulesRegistry::AddRules(
std::string TestRulesRegistry::RemoveRules(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
// TODO(battre) this ignores the extension_id but should not.
for (std::vector<std::string>::const_iterator i =
rule_identifiers.begin(); i != rule_identifiers.end(); ++i) {
@@ -58,6 +53,7 @@ std::string TestRulesRegistry::RemoveRules(
}
std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
// TODO(battre) this ignores the extension_id but should not.
rules_.clear();
return kSuccess;
@@ -66,33 +62,39 @@ std::string TestRulesRegistry::RemoveAllRules(const std::string& extension_id) {
std::string TestRulesRegistry::GetRules(
const std::string& extension_id,
const std::vector<std::string>& rule_identifiers,
- std::vector<DictionaryValue*>* out) {
+ std::vector<linked_ptr<RulesRegistry::Rule> >* out) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
// TODO(battre) this ignores the extension_id but should not.
for (std::vector<std::string>::const_iterator i = rule_identifiers.begin();
i != rule_identifiers.end(); ++i) {
RulesDictionary::iterator entry = rules_.find(*i);
if (entry == rules_.end())
return kRuleNotFound;
- out->push_back(entry->second->DeepCopy());
+ out->push_back(entry->second);
}
return kSuccess;
}
std::string TestRulesRegistry::GetAllRules(
const std::string& extension_id,
- std::vector<DictionaryValue*>* out) {
+ std::vector<linked_ptr<RulesRegistry::Rule> >* out) {
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
// TODO(battre): this ignores the extension_id.
for (RulesDictionary::const_iterator i = rules_.begin();
i != rules_.end(); ++i)
- out->push_back(i->second->DeepCopy());
+ out->push_back(i->second);
return kSuccess;
}
void TestRulesRegistry::OnExtensionUnloaded(const std::string& extension_id) {
- std::vector<std::string> no_rule_identifiers;
- std::string error = RemoveRules(extension_id, no_rule_identifiers);
+ DCHECK(content::BrowserThread::CurrentlyOn(GetOwnerThread()));
+ std::string error = RemoveAllRules(extension_id);
if (!error.empty())
LOG(ERROR) << error;
}
+content::BrowserThread::ID TestRulesRegistry::GetOwnerThread() const {
+ return owner_thread_;
+}
+
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/declarative/test_rules_registry.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698