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 "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/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 base::PostTaskAndReplyWithResult( | 54 base::PostTaskAndReplyWithResult( |
55 message_loop_proxy, | 55 message_loop_proxy, |
56 FROM_HERE, | 56 FROM_HERE, |
57 base::Bind(&RulesFunction::RunImplOnCorrectThread, this), | 57 base::Bind(&RulesFunction::RunImplOnCorrectThread, this), |
58 base::Bind(&RulesFunction::SendResponse, this)); | 58 base::Bind(&RulesFunction::SendResponse, this)); |
59 } | 59 } |
60 | 60 |
61 return true; | 61 return true; |
62 } | 62 } |
63 | 63 |
64 bool EventsAddRulesFunction::RunImplOnCorrectThread() { | 64 bool AddRulesFunction::RunImplOnCorrectThread() { |
65 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); | 65 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); |
66 EXTENSION_FUNCTION_VALIDATE(params.get()); | 66 EXTENSION_FUNCTION_VALIDATE(params.get()); |
67 | 67 |
68 error_ = rules_registry_->AddRules(extension_id(), params->rules); | 68 error_ = rules_registry_->AddRules(extension_id(), params->rules); |
69 | 69 |
70 if (error_.empty()) | 70 if (error_.empty()) |
71 results_ = AddRules::Results::Create(params->rules); | 71 results_ = AddRules::Results::Create(params->rules); |
72 | 72 |
73 return error_.empty(); | 73 return error_.empty(); |
74 } | 74 } |
75 | 75 |
76 bool EventsRemoveRulesFunction::RunImplOnCorrectThread() { | 76 bool RemoveRulesFunction::RunImplOnCorrectThread() { |
77 scoped_ptr<RemoveRules::Params> params(RemoveRules::Params::Create(*args_)); | 77 scoped_ptr<RemoveRules::Params> params(RemoveRules::Params::Create(*args_)); |
78 EXTENSION_FUNCTION_VALIDATE(params.get()); | 78 EXTENSION_FUNCTION_VALIDATE(params.get()); |
79 | 79 |
80 if (params->rule_identifiers.get()) { | 80 if (params->rule_identifiers.get()) { |
81 error_ = rules_registry_->RemoveRules(extension_id(), | 81 error_ = rules_registry_->RemoveRules(extension_id(), |
82 *params->rule_identifiers); | 82 *params->rule_identifiers); |
83 } else { | 83 } else { |
84 error_ = rules_registry_->RemoveAllRules(extension_id()); | 84 error_ = rules_registry_->RemoveAllRules(extension_id()); |
85 } | 85 } |
86 | 86 |
87 return error_.empty(); | 87 return error_.empty(); |
88 } | 88 } |
89 | 89 |
90 bool EventsGetRulesFunction::RunImplOnCorrectThread() { | 90 bool GetRulesFunction::RunImplOnCorrectThread() { |
91 scoped_ptr<GetRules::Params> params(GetRules::Params::Create(*args_)); | 91 scoped_ptr<GetRules::Params> params(GetRules::Params::Create(*args_)); |
92 EXTENSION_FUNCTION_VALIDATE(params.get()); | 92 EXTENSION_FUNCTION_VALIDATE(params.get()); |
93 | 93 |
94 std::vector<linked_ptr<Rule> > rules; | 94 std::vector<linked_ptr<Rule> > rules; |
95 if (params->rule_identifiers.get()) { | 95 if (params->rule_identifiers.get()) { |
96 error_ = rules_registry_->GetRules(extension_id(), | 96 error_ = rules_registry_->GetRules(extension_id(), |
97 *params->rule_identifiers, | 97 *params->rule_identifiers, |
98 &rules); | 98 &rules); |
99 } else { | 99 } else { |
100 error_ = rules_registry_->GetAllRules(extension_id(), &rules); | 100 error_ = rules_registry_->GetAllRules(extension_id(), &rules); |
101 } | 101 } |
102 | 102 |
103 if (error_.empty()) | 103 if (error_.empty()) |
104 results_ = GetRules::Results::Create(rules); | 104 results_ = GetRules::Results::Create(rules); |
105 | 105 |
106 return error_.empty(); | 106 return error_.empty(); |
107 } | 107 } |
108 | 108 |
109 } // namespace extensions | 109 } // namespace extensions |
OLD | NEW |