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

Side by Side Diff: chrome/browser/extensions/api/declarative/declarative_api.cc

Issue 9315010: RulesRegistry for declarative APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implemented ID and priority generation 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/api/declarative/declarative_api.h" 5 #include "chrome/browser/extensions/api/declarative/declarative_api.h"
6 6
7 #include "base/bind.h"
7 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
10 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h"
11 #include "chrome/browser/extensions/api/declarative/rules_registry_service_facto ry.h"
8 12
9 namespace extensions { 13 namespace extensions {
10 14
11 bool AddRulesFunction::RunImpl() { 15 bool AddRulesFunction::RunImpl() {
12 // LOG(ERROR) << "AddRulesFunction called"; 16 // The name of the event object which had the addRules() function that was
17 // 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.
18 std::string event_name;
19 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!!!
13 20
14 ListValue* rules_list; 21 ListValue* rules_list;
15 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rules_list)); 22 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rules_list));
16 23
17 // TODO(battre): Generate unique IDs and priorities here. 24 std::vector<DictionaryValue*> rules;
25 for (ListValue::iterator i = rules_list->begin();
26 i != rules_list->end();
27 ++i) {
28 DictionaryValue* rule;
not at google - send to devlin 2012/02/02 11:59:16 = NULL etc
battre 2012/02/02 19:12:36 Done.
29 EXTENSION_FUNCTION_VALIDATE((*i)->GetAsDictionary(&rule));
30 rules.push_back(rule);
31 }
32
33 RulesRegistryService* rules_registry =
34 RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_);
35
36 EXTENSION_FUNCTION_VALIDATE(
37 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
38 event_name,
39 extension_id(),
40 rules,
41 base::Bind(&AddRulesFunction::SetError, this)));
18 42
19 result_.reset(rules_list->DeepCopy()); 43 result_.reset(rules_list->DeepCopy());
20 return true; 44 return true;
21 } 45 }
22 46
23 bool RemoveRulesFunction::RunImpl() { 47 bool RemoveRulesFunction::RunImpl() {
24 // LOG(ERROR) << "RemoveRulesFunction called"; 48 std::string event_name;
49 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name));
50
51 ListValue* rule_identifiers_list;
52 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rule_identifiers_list));
53
54 std::vector<std::string> rule_identifiers;
55 for (ListValue::iterator i = rule_identifiers_list->begin();
56 i != rule_identifiers_list->end();
57 ++i) {
58 std::string rule_id;
59 EXTENSION_FUNCTION_VALIDATE((*i)->GetAsString(&rule_id));
60 rule_identifiers.push_back(rule_id);
61 }
62
63 RulesRegistryService* rules_registry =
64 RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_);
65
66 EXTENSION_FUNCTION_VALIDATE(
67 rules_registry->RemoveRules(
68 event_name,
69 extension_id(),
70 rule_identifiers,
71 base::Bind(&AddRulesFunction::SetError, this)));
72
25 return true; 73 return true;
26 } 74 }
27 75
28 bool GetRulesFunction::RunImpl() { 76 bool GetRulesFunction::RunImpl() {
29 // LOG(ERROR) << "GetRulesFunction called"; 77 std::string event_name;
30 result_.reset(new ListValue()); 78 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &event_name));
79
80 ListValue* rule_identifiers_list;
81 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &rule_identifiers_list));
82
83 std::vector<std::string> rule_identifiers;
84 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
85 i != rule_identifiers_list->end();
86 ++i) {
87 std::string rule_id;
88 EXTENSION_FUNCTION_VALIDATE((*i)->GetAsString(&rule_id));
89 rule_identifiers.push_back(rule_id);
90 }
91
92 RulesRegistryService* rules_registry =
93 RulesRegistryServiceFactory::GetInstance()->GetForProfile(profile_);
94
95 typedef std::vector<DictionaryValue*> RulesList;
96
97 RulesList rules;
98 rules_registry->GetRules(
99 event_name, extension_id(), rule_identifiers, &rules);
100
101 scoped_ptr<ListValue> result(new ListValue);
102 for (RulesList::iterator i = rules.begin(); i != rules.end(); ++i)
103 result->Append(*i);
104
105 result_.reset(result.release());
31 return true; 106 return true;
32 } 107 }
33 108
34 } // namespace extensions 109 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698