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

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

Issue 1841483002: [Extensions] Convert APIs to use movable types [11] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 "extensions/browser/api/declarative/declarative_api.h" 5 #include "extensions/browser/api/declarative/declarative_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 164 }
165 165
166 return true; 166 return true;
167 } 167 }
168 168
169 bool EventsEventAddRulesFunction::RunAsyncOnCorrectThread() { 169 bool EventsEventAddRulesFunction::RunAsyncOnCorrectThread() {
170 ConvertBinaryListElementsToBase64(args_.get()); 170 ConvertBinaryListElementsToBase64(args_.get());
171 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_)); 171 scoped_ptr<AddRules::Params> params(AddRules::Params::Create(*args_));
172 EXTENSION_FUNCTION_VALIDATE(params.get()); 172 EXTENSION_FUNCTION_VALIDATE(params.get());
173 173
174 error_ = rules_registry_->AddRules(extension_id(), params->rules); 174 // TODO(devlin): Remove the dependency on linked_ptr here.
175 std::vector<linked_ptr<api::events::Rule>> linked_rules;
176 for (api::events::Rule& rule : params->rules) {
177 linked_rules.push_back(
178 make_linked_ptr(new api::events::Rule(std::move(rule))));
179 }
180 error_ = rules_registry_->AddRules(extension_id(), linked_rules);
175 181
176 if (error_.empty()) 182 if (error_.empty()) {
177 results_ = AddRules::Results::Create(params->rules); 183 scoped_ptr<base::ListValue> rules_value(new base::ListValue());
184 for (const auto& rule : linked_rules)
185 rules_value->Append(rule->ToValue());
186 SetResult(std::move(rules_value));
187 }
178 188
179 return error_.empty(); 189 return error_.empty();
180 } 190 }
181 191
182 bool EventsEventRemoveRulesFunction::RunAsyncOnCorrectThread() { 192 bool EventsEventRemoveRulesFunction::RunAsyncOnCorrectThread() {
183 scoped_ptr<RemoveRules::Params> params(RemoveRules::Params::Create(*args_)); 193 scoped_ptr<RemoveRules::Params> params(RemoveRules::Params::Create(*args_));
184 EXTENSION_FUNCTION_VALIDATE(params.get()); 194 EXTENSION_FUNCTION_VALIDATE(params.get());
185 195
186 if (params->rule_identifiers.get()) { 196 if (params->rule_identifiers.get()) {
187 error_ = rules_registry_->RemoveRules(extension_id(), 197 error_ = rules_registry_->RemoveRules(extension_id(),
(...skipping 10 matching lines...) Expand all
198 EXTENSION_FUNCTION_VALIDATE(params.get()); 208 EXTENSION_FUNCTION_VALIDATE(params.get());
199 209
200 std::vector<linked_ptr<Rule> > rules; 210 std::vector<linked_ptr<Rule> > rules;
201 if (params->rule_identifiers.get()) { 211 if (params->rule_identifiers.get()) {
202 rules_registry_->GetRules( 212 rules_registry_->GetRules(
203 extension_id(), *params->rule_identifiers, &rules); 213 extension_id(), *params->rule_identifiers, &rules);
204 } else { 214 } else {
205 rules_registry_->GetAllRules(extension_id(), &rules); 215 rules_registry_->GetAllRules(extension_id(), &rules);
206 } 216 }
207 217
208 results_ = GetRules::Results::Create(rules); 218 scoped_ptr<base::ListValue> rules_value(new base::ListValue());
219 for (const auto& rule : rules)
220 rules_value->Append(rule->ToValue());
221 SetResult(std::move(rules_value));
209 222
210 return true; 223 return true;
211 } 224 }
212 225
213 } // namespace extensions 226 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698