Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative/declarative_api.cc |
| diff --git a/chrome/browser/extensions/api/declarative/declarative_api.cc b/chrome/browser/extensions/api/declarative/declarative_api.cc |
| index dcb79f387690caae3085e972255cef5714399ee0..14d31147d137c0e1b79da61f5adc8c1cd22da2cc 100644 |
| --- a/chrome/browser/extensions/api/declarative/declarative_api.cc |
| +++ b/chrome/browser/extensions/api/declarative/declarative_api.cc |
| @@ -4,30 +4,105 @@ |
| #include "chrome/browser/extensions/api/declarative/declarative_api.h" |
| +#include "base/bind.h" |
| #include "base/values.h" |
| +#include "chrome/browser/extensions/api/declarative/rules_registry.h" |
| +#include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| +#include "chrome/browser/extensions/api/declarative/rules_registry_service_factory.h" |
| namespace extensions { |
| bool AddRulesFunction::RunImpl() { |
| - // LOG(ERROR) << "AddRulesFunction called"; |
| + // The name of the event object which had the addRules() function that was |
| + // called. |
|
not at google - send to devlin
2012/02/02 11:59:16
This comment isn't entirely accurate, because the
battre
2012/02/02 19:12:36
Done.
|
| + std::string event_name; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); |
|
not at google - send to devlin
2012/02/02 11:59:16
Note: very soon you'll be able to use json_schema_
battre
2012/02/02 19:12:36
sounds awesome!!!
|
| ListValue* rules_list; |
| EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rules_list)); |
| - // TODO(battre): Generate unique IDs and priorities here. |
| + std::vector<DictionaryValue*> rules; |
| + for (ListValue::iterator i = rules_list->begin(); |
| + i != rules_list->end(); |
| + ++i) { |
| + DictionaryValue* rule; |
|
not at google - send to devlin
2012/02/02 11:59:16
= NULL
etc
battre
2012/02/02 19:12:36
Done.
|
| + EXTENSION_FUNCTION_VALIDATE((*i)->GetAsDictionary(&rule)); |
| + rules.push_back(rule); |
| + } |
| + |
| + RulesRegistryService* rules_registry = |
| + RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_); |
| + |
| + EXTENSION_FUNCTION_VALIDATE( |
| + rules_registry->AddRules( |
|
not at google - send to devlin
2012/02/02 11:59:16
EXTENSION_FUNCTION_VALIDATE is for validating that
battre
2012/02/02 19:12:36
Valid points. I have promoted this to graceful fai
|
| + event_name, |
| + extension_id(), |
| + rules, |
| + base::Bind(&AddRulesFunction::SetError, this))); |
| result_.reset(rules_list->DeepCopy()); |
| return true; |
| } |
| bool RemoveRulesFunction::RunImpl() { |
| - // LOG(ERROR) << "RemoveRulesFunction called"; |
| + std::string event_name; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); |
| + |
| + ListValue* rule_identifiers_list; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rule_identifiers_list)); |
| + |
| + std::vector<std::string> rule_identifiers; |
| + for (ListValue::iterator i = rule_identifiers_list->begin(); |
| + i != rule_identifiers_list->end(); |
| + ++i) { |
| + std::string rule_id; |
| + EXTENSION_FUNCTION_VALIDATE((*i)->GetAsString(&rule_id)); |
| + rule_identifiers.push_back(rule_id); |
| + } |
| + |
| + RulesRegistryService* rules_registry = |
| + RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_); |
| + |
| + EXTENSION_FUNCTION_VALIDATE( |
| + rules_registry->RemoveRules( |
| + event_name, |
| + extension_id(), |
| + rule_identifiers, |
| + base::Bind(&AddRulesFunction::SetError, this))); |
| + |
| return true; |
| } |
| bool GetRulesFunction::RunImpl() { |
| - // LOG(ERROR) << "GetRulesFunction called"; |
| - result_.reset(new ListValue()); |
| + std::string event_name; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name)); |
| + |
| + ListValue* rule_identifiers_list; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rule_identifiers_list)); |
| + |
| + std::vector<std::string> rule_identifiers; |
| + for (ListValue::iterator i = rule_identifiers_list->begin(); |
|
Aaron Boodman
2012/02/02 16:28:51
If you don't end up waiting on calamity@, you coul
|
| + i != rule_identifiers_list->end(); |
| + ++i) { |
| + std::string rule_id; |
| + EXTENSION_FUNCTION_VALIDATE((*i)->GetAsString(&rule_id)); |
| + rule_identifiers.push_back(rule_id); |
| + } |
| + |
| + RulesRegistryService* rules_registry = |
| + RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_); |
| + |
| + typedef std::vector<DictionaryValue*> RulesList; |
| + |
| + RulesList rules; |
| + rules_registry->GetRules( |
| + event_name, extension_id(), rule_identifiers, &rules); |
| + |
| + scoped_ptr<ListValue> result(new ListValue); |
| + for (RulesList::iterator i = rules.begin(); i != rules.end(); ++i) |
| + result->Append(*i); |
| + |
| + result_.reset(result.release()); |
| return true; |
| } |