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

Side by Side Diff: extensions/browser/api/networking_private/networking_private_api.cc

Issue 2612873004: Remove some usages of AsyncExtensionFunction::results_. (Closed)
Patch Set: sync Created 3 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/networking_private/networking_private_api.h" 5 #include "extensions/browser/api/networking_private/networking_private_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 } // namespace networking_private 58 } // namespace networking_private
59 59
60 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
61 // NetworkingPrivateGetPropertiesFunction 61 // NetworkingPrivateGetPropertiesFunction
62 62
63 NetworkingPrivateGetPropertiesFunction:: 63 NetworkingPrivateGetPropertiesFunction::
64 ~NetworkingPrivateGetPropertiesFunction() { 64 ~NetworkingPrivateGetPropertiesFunction() {
65 } 65 }
66 66
67 bool NetworkingPrivateGetPropertiesFunction::RunAsync() { 67 ExtensionFunction::ResponseAction
68 NetworkingPrivateGetPropertiesFunction::Run() {
68 std::unique_ptr<private_api::GetProperties::Params> params = 69 std::unique_ptr<private_api::GetProperties::Params> params =
69 private_api::GetProperties::Params::Create(*args_); 70 private_api::GetProperties::Params::Create(*args_);
70 EXTENSION_FUNCTION_VALIDATE(params); 71 EXTENSION_FUNCTION_VALIDATE(params);
71 72
72 GetDelegate(browser_context()) 73 GetDelegate(browser_context())
73 ->GetProperties( 74 ->GetProperties(
74 params->network_guid, 75 params->network_guid,
75 base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this), 76 base::Bind(&NetworkingPrivateGetPropertiesFunction::Success, this),
76 base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this)); 77 base::Bind(&NetworkingPrivateGetPropertiesFunction::Failure, this));
77 return true; 78 // Success() or Failure() might have been called synchronously at this point.
79 // In that case this function has already called Respond(). Return
80 // AlreadyResponded() in that case.
81 return did_respond() ? AlreadyResponded() : RespondLater();
78 } 82 }
79 83
80 void NetworkingPrivateGetPropertiesFunction::Success( 84 void NetworkingPrivateGetPropertiesFunction::Success(
81 std::unique_ptr<base::DictionaryValue> result) { 85 std::unique_ptr<base::DictionaryValue> result) {
82 SetResult(std::move(result)); 86 Respond(OneArgument(std::move(result)));
83 SendResponse(true);
84 } 87 }
85 88
86 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) { 89 void NetworkingPrivateGetPropertiesFunction::Failure(const std::string& error) {
87 error_ = error; 90 Respond(Error(error));
88 SendResponse(false);
89 } 91 }
90 92
91 //////////////////////////////////////////////////////////////////////////////// 93 ////////////////////////////////////////////////////////////////////////////////
92 // NetworkingPrivateGetManagedPropertiesFunction 94 // NetworkingPrivateGetManagedPropertiesFunction
93 95
94 NetworkingPrivateGetManagedPropertiesFunction:: 96 NetworkingPrivateGetManagedPropertiesFunction::
95 ~NetworkingPrivateGetManagedPropertiesFunction() { 97 ~NetworkingPrivateGetManagedPropertiesFunction() {
96 } 98 }
97 99
98 bool NetworkingPrivateGetManagedPropertiesFunction::RunAsync() { 100 ExtensionFunction::ResponseAction
101 NetworkingPrivateGetManagedPropertiesFunction::Run() {
99 std::unique_ptr<private_api::GetManagedProperties::Params> params = 102 std::unique_ptr<private_api::GetManagedProperties::Params> params =
100 private_api::GetManagedProperties::Params::Create(*args_); 103 private_api::GetManagedProperties::Params::Create(*args_);
101 EXTENSION_FUNCTION_VALIDATE(params); 104 EXTENSION_FUNCTION_VALIDATE(params);
102 105
103 GetDelegate(browser_context()) 106 GetDelegate(browser_context())
104 ->GetManagedProperties( 107 ->GetManagedProperties(
105 params->network_guid, 108 params->network_guid,
106 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success, 109 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Success,
107 this), 110 this),
108 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure, 111 base::Bind(&NetworkingPrivateGetManagedPropertiesFunction::Failure,
109 this)); 112 this));
110 return true; 113 // Success() or Failure() might have been called synchronously at this point.
114 // In that case this function has already called Respond(). Return
115 // AlreadyResponded() in that case.
116 return did_respond() ? AlreadyResponded() : RespondLater();
111 } 117 }
112 118
113 void NetworkingPrivateGetManagedPropertiesFunction::Success( 119 void NetworkingPrivateGetManagedPropertiesFunction::Success(
114 std::unique_ptr<base::DictionaryValue> result) { 120 std::unique_ptr<base::DictionaryValue> result) {
115 SetResult(std::move(result)); 121 Respond(OneArgument(std::move(result)));
116 SendResponse(true);
117 } 122 }
118 123
119 void NetworkingPrivateGetManagedPropertiesFunction::Failure( 124 void NetworkingPrivateGetManagedPropertiesFunction::Failure(
120 const std::string& error) { 125 const std::string& error) {
121 error_ = error; 126 Respond(Error(error));
122 SendResponse(false);
123 } 127 }
124 128
125 //////////////////////////////////////////////////////////////////////////////// 129 ////////////////////////////////////////////////////////////////////////////////
126 // NetworkingPrivateGetStateFunction 130 // NetworkingPrivateGetStateFunction
127 131
128 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() { 132 NetworkingPrivateGetStateFunction::~NetworkingPrivateGetStateFunction() {
129 } 133 }
130 134
131 bool NetworkingPrivateGetStateFunction::RunAsync() { 135 ExtensionFunction::ResponseAction NetworkingPrivateGetStateFunction::Run() {
132 std::unique_ptr<private_api::GetState::Params> params = 136 std::unique_ptr<private_api::GetState::Params> params =
133 private_api::GetState::Params::Create(*args_); 137 private_api::GetState::Params::Create(*args_);
134 EXTENSION_FUNCTION_VALIDATE(params); 138 EXTENSION_FUNCTION_VALIDATE(params);
135 139
136 GetDelegate(browser_context()) 140 GetDelegate(browser_context())
137 ->GetState(params->network_guid, 141 ->GetState(params->network_guid,
138 base::Bind(&NetworkingPrivateGetStateFunction::Success, this), 142 base::Bind(&NetworkingPrivateGetStateFunction::Success, this),
139 base::Bind(&NetworkingPrivateGetStateFunction::Failure, this)); 143 base::Bind(&NetworkingPrivateGetStateFunction::Failure, this));
140 return true; 144 // Success() or Failure() might have been called synchronously at this point.
145 // In that case this function has already called Respond(). Return
146 // AlreadyResponded() in that case.
147 return did_respond() ? AlreadyResponded() : RespondLater();
141 } 148 }
142 149
143 void NetworkingPrivateGetStateFunction::Success( 150 void NetworkingPrivateGetStateFunction::Success(
144 std::unique_ptr<base::DictionaryValue> result) { 151 std::unique_ptr<base::DictionaryValue> result) {
145 SetResult(std::move(result)); 152 Respond(OneArgument(std::move(result)));
146 SendResponse(true);
147 } 153 }
148 154
149 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) { 155 void NetworkingPrivateGetStateFunction::Failure(const std::string& error) {
150 error_ = error; 156 Respond(Error(error));
151 SendResponse(false);
152 } 157 }
153 158
154 //////////////////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////////////////
155 // NetworkingPrivateSetPropertiesFunction 160 // NetworkingPrivateSetPropertiesFunction
156 161
157 NetworkingPrivateSetPropertiesFunction:: 162 NetworkingPrivateSetPropertiesFunction::
158 ~NetworkingPrivateSetPropertiesFunction() { 163 ~NetworkingPrivateSetPropertiesFunction() {
159 } 164 }
160 165
161 bool NetworkingPrivateSetPropertiesFunction::RunAsync() { 166 ExtensionFunction::ResponseAction
167 NetworkingPrivateSetPropertiesFunction::Run() {
162 std::unique_ptr<private_api::SetProperties::Params> params = 168 std::unique_ptr<private_api::SetProperties::Params> params =
163 private_api::SetProperties::Params::Create(*args_); 169 private_api::SetProperties::Params::Create(*args_);
164 EXTENSION_FUNCTION_VALIDATE(params); 170 EXTENSION_FUNCTION_VALIDATE(params);
165 171
166 std::unique_ptr<base::DictionaryValue> properties_dict( 172 std::unique_ptr<base::DictionaryValue> properties_dict(
167 params->properties.ToValue()); 173 params->properties.ToValue());
168 174
169 GetDelegate(browser_context()) 175 GetDelegate(browser_context())
170 ->SetProperties( 176 ->SetProperties(
171 params->network_guid, std::move(properties_dict), 177 params->network_guid, std::move(properties_dict),
172 base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this), 178 base::Bind(&NetworkingPrivateSetPropertiesFunction::Success, this),
173 base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this)); 179 base::Bind(&NetworkingPrivateSetPropertiesFunction::Failure, this));
174 return true; 180 // Success() or Failure() might have been called synchronously at this point.
181 // In that case this function has already called Respond(). Return
182 // AlreadyResponded() in that case.
183 return did_respond() ? AlreadyResponded() : RespondLater();
175 } 184 }
176 185
177 void NetworkingPrivateSetPropertiesFunction::Success() { 186 void NetworkingPrivateSetPropertiesFunction::Success() {
178 SendResponse(true); 187 Respond(NoArguments());
179 } 188 }
180 189
181 void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) { 190 void NetworkingPrivateSetPropertiesFunction::Failure(const std::string& error) {
182 error_ = error; 191 Respond(Error(error));
183 SendResponse(false);
184 } 192 }
185 193
186 //////////////////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////////////////
187 // NetworkingPrivateCreateNetworkFunction 195 // NetworkingPrivateCreateNetworkFunction
188 196
189 NetworkingPrivateCreateNetworkFunction:: 197 NetworkingPrivateCreateNetworkFunction::
190 ~NetworkingPrivateCreateNetworkFunction() { 198 ~NetworkingPrivateCreateNetworkFunction() {
191 } 199 }
192 200
193 bool NetworkingPrivateCreateNetworkFunction::RunAsync() { 201 ExtensionFunction::ResponseAction
202 NetworkingPrivateCreateNetworkFunction::Run() {
194 std::unique_ptr<private_api::CreateNetwork::Params> params = 203 std::unique_ptr<private_api::CreateNetwork::Params> params =
195 private_api::CreateNetwork::Params::Create(*args_); 204 private_api::CreateNetwork::Params::Create(*args_);
196 EXTENSION_FUNCTION_VALIDATE(params); 205 EXTENSION_FUNCTION_VALIDATE(params);
197 206
198 std::unique_ptr<base::DictionaryValue> properties_dict( 207 std::unique_ptr<base::DictionaryValue> properties_dict(
199 params->properties.ToValue()); 208 params->properties.ToValue());
200 209
201 GetDelegate(browser_context()) 210 GetDelegate(browser_context())
202 ->CreateNetwork( 211 ->CreateNetwork(
203 params->shared, std::move(properties_dict), 212 params->shared, std::move(properties_dict),
204 base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this), 213 base::Bind(&NetworkingPrivateCreateNetworkFunction::Success, this),
205 base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this)); 214 base::Bind(&NetworkingPrivateCreateNetworkFunction::Failure, this));
206 return true; 215 // Success() or Failure() might have been called synchronously at this point.
216 // In that case this function has already called Respond(). Return
217 // AlreadyResponded() in that case.
218 return did_respond() ? AlreadyResponded() : RespondLater();
207 } 219 }
208 220
209 void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) { 221 void NetworkingPrivateCreateNetworkFunction::Success(const std::string& guid) {
210 results_ = private_api::CreateNetwork::Results::Create(guid); 222 Respond(ArgumentList(private_api::CreateNetwork::Results::Create(guid)));
211 SendResponse(true);
212 } 223 }
213 224
214 void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) { 225 void NetworkingPrivateCreateNetworkFunction::Failure(const std::string& error) {
215 error_ = error; 226 Respond(Error(error));
216 SendResponse(false);
217 } 227 }
218 228
219 //////////////////////////////////////////////////////////////////////////////// 229 ////////////////////////////////////////////////////////////////////////////////
220 // NetworkingPrivateForgetNetworkFunction 230 // NetworkingPrivateForgetNetworkFunction
221 231
222 NetworkingPrivateForgetNetworkFunction:: 232 NetworkingPrivateForgetNetworkFunction::
223 ~NetworkingPrivateForgetNetworkFunction() { 233 ~NetworkingPrivateForgetNetworkFunction() {
224 } 234 }
225 235
226 bool NetworkingPrivateForgetNetworkFunction::RunAsync() { 236 ExtensionFunction::ResponseAction
237 NetworkingPrivateForgetNetworkFunction::Run() {
227 std::unique_ptr<private_api::ForgetNetwork::Params> params = 238 std::unique_ptr<private_api::ForgetNetwork::Params> params =
228 private_api::ForgetNetwork::Params::Create(*args_); 239 private_api::ForgetNetwork::Params::Create(*args_);
229 EXTENSION_FUNCTION_VALIDATE(params); 240 EXTENSION_FUNCTION_VALIDATE(params);
230 241
231 GetDelegate(browser_context()) 242 GetDelegate(browser_context())
232 ->ForgetNetwork( 243 ->ForgetNetwork(
233 params->network_guid, 244 params->network_guid,
234 base::Bind(&NetworkingPrivateForgetNetworkFunction::Success, this), 245 base::Bind(&NetworkingPrivateForgetNetworkFunction::Success, this),
235 base::Bind(&NetworkingPrivateForgetNetworkFunction::Failure, this)); 246 base::Bind(&NetworkingPrivateForgetNetworkFunction::Failure, this));
236 return true; 247 // Success() or Failure() might have been called synchronously at this point.
248 // In that case this function has already called Respond(). Return
249 // AlreadyResponded() in that case.
250 return did_respond() ? AlreadyResponded() : RespondLater();
237 } 251 }
238 252
239 void NetworkingPrivateForgetNetworkFunction::Success() { 253 void NetworkingPrivateForgetNetworkFunction::Success() {
240 SendResponse(true); 254 Respond(NoArguments());
241 } 255 }
242 256
243 void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) { 257 void NetworkingPrivateForgetNetworkFunction::Failure(const std::string& error) {
244 error_ = error; 258 Respond(Error(error));
245 SendResponse(false);
246 } 259 }
247 260
248 //////////////////////////////////////////////////////////////////////////////// 261 ////////////////////////////////////////////////////////////////////////////////
249 // NetworkingPrivateGetNetworksFunction 262 // NetworkingPrivateGetNetworksFunction
250 263
251 NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() { 264 NetworkingPrivateGetNetworksFunction::~NetworkingPrivateGetNetworksFunction() {
252 } 265 }
253 266
254 bool NetworkingPrivateGetNetworksFunction::RunAsync() { 267 ExtensionFunction::ResponseAction NetworkingPrivateGetNetworksFunction::Run() {
255 std::unique_ptr<private_api::GetNetworks::Params> params = 268 std::unique_ptr<private_api::GetNetworks::Params> params =
256 private_api::GetNetworks::Params::Create(*args_); 269 private_api::GetNetworks::Params::Create(*args_);
257 EXTENSION_FUNCTION_VALIDATE(params); 270 EXTENSION_FUNCTION_VALIDATE(params);
258 271
259 std::string network_type = private_api::ToString(params->filter.network_type); 272 std::string network_type = private_api::ToString(params->filter.network_type);
260 const bool configured_only = 273 const bool configured_only =
261 params->filter.configured ? *params->filter.configured : false; 274 params->filter.configured ? *params->filter.configured : false;
262 const bool visible_only = 275 const bool visible_only =
263 params->filter.visible ? *params->filter.visible : false; 276 params->filter.visible ? *params->filter.visible : false;
264 const int limit = 277 const int limit =
265 params->filter.limit ? *params->filter.limit : kDefaultNetworkListLimit; 278 params->filter.limit ? *params->filter.limit : kDefaultNetworkListLimit;
266 279
267 GetDelegate(browser_context()) 280 GetDelegate(browser_context())
268 ->GetNetworks( 281 ->GetNetworks(
269 network_type, configured_only, visible_only, limit, 282 network_type, configured_only, visible_only, limit,
270 base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this), 283 base::Bind(&NetworkingPrivateGetNetworksFunction::Success, this),
271 base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this)); 284 base::Bind(&NetworkingPrivateGetNetworksFunction::Failure, this));
272 return true; 285 // Success() or Failure() might have been called synchronously at this point.
286 // In that case this function has already called Respond(). Return
287 // AlreadyResponded() in that case.
288 return did_respond() ? AlreadyResponded() : RespondLater();
273 } 289 }
274 290
275 void NetworkingPrivateGetNetworksFunction::Success( 291 void NetworkingPrivateGetNetworksFunction::Success(
276 std::unique_ptr<base::ListValue> network_list) { 292 std::unique_ptr<base::ListValue> network_list) {
277 SetResult(std::move(network_list)); 293 return Respond(OneArgument(std::move(network_list)));
278 SendResponse(true);
279 } 294 }
280 295
281 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) { 296 void NetworkingPrivateGetNetworksFunction::Failure(const std::string& error) {
282 error_ = error; 297 Respond(Error(error));
283 SendResponse(false);
284 } 298 }
285 299
286 //////////////////////////////////////////////////////////////////////////////// 300 ////////////////////////////////////////////////////////////////////////////////
287 // NetworkingPrivateGetVisibleNetworksFunction 301 // NetworkingPrivateGetVisibleNetworksFunction
288 302
289 NetworkingPrivateGetVisibleNetworksFunction:: 303 NetworkingPrivateGetVisibleNetworksFunction::
290 ~NetworkingPrivateGetVisibleNetworksFunction() { 304 ~NetworkingPrivateGetVisibleNetworksFunction() {
291 } 305 }
292 306
293 bool NetworkingPrivateGetVisibleNetworksFunction::RunAsync() { 307 ExtensionFunction::ResponseAction
308 NetworkingPrivateGetVisibleNetworksFunction::Run() {
294 std::unique_ptr<private_api::GetVisibleNetworks::Params> params = 309 std::unique_ptr<private_api::GetVisibleNetworks::Params> params =
295 private_api::GetVisibleNetworks::Params::Create(*args_); 310 private_api::GetVisibleNetworks::Params::Create(*args_);
296 EXTENSION_FUNCTION_VALIDATE(params); 311 EXTENSION_FUNCTION_VALIDATE(params);
297 312
298 // getVisibleNetworks is deprecated - allow it only for apps with 313 // getVisibleNetworks is deprecated - allow it only for apps with
299 // networkingPrivate permissions, i.e. apps that might have started using it 314 // networkingPrivate permissions, i.e. apps that might have started using it
300 // before its deprecation. 315 // before its deprecation.
301 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 316 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
302 source_url())) { 317 source_url())) {
303 error_ = kPrivateOnlyError; 318 return RespondNow(Error(kPrivateOnlyError));
304 return false;
305 } 319 }
306 320
307 std::string network_type = private_api::ToString(params->network_type); 321 std::string network_type = private_api::ToString(params->network_type);
308 const bool configured_only = false; 322 const bool configured_only = false;
309 const bool visible_only = true; 323 const bool visible_only = true;
310 324
311 GetDelegate(browser_context()) 325 GetDelegate(browser_context())
312 ->GetNetworks( 326 ->GetNetworks(
313 network_type, configured_only, visible_only, kDefaultNetworkListLimit, 327 network_type, configured_only, visible_only, kDefaultNetworkListLimit,
314 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success, 328 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Success,
315 this), 329 this),
316 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure, 330 base::Bind(&NetworkingPrivateGetVisibleNetworksFunction::Failure,
317 this)); 331 this));
318 return true; 332 // Success() or Failure() might have been called synchronously at this point.
333 // In that case this function has already called Respond(). Return
334 // AlreadyResponded() in that case.
335 return did_respond() ? AlreadyResponded() : RespondLater();
319 } 336 }
320 337
321 void NetworkingPrivateGetVisibleNetworksFunction::Success( 338 void NetworkingPrivateGetVisibleNetworksFunction::Success(
322 std::unique_ptr<base::ListValue> network_properties_list) { 339 std::unique_ptr<base::ListValue> network_properties_list) {
323 SetResult(std::move(network_properties_list)); 340 Respond(OneArgument(std::move(network_properties_list)));
324 SendResponse(true);
325 } 341 }
326 342
327 void NetworkingPrivateGetVisibleNetworksFunction::Failure( 343 void NetworkingPrivateGetVisibleNetworksFunction::Failure(
328 const std::string& error) { 344 const std::string& error) {
329 error_ = error; 345 Respond(Error(error));
330 SendResponse(false);
331 } 346 }
332 347
333 //////////////////////////////////////////////////////////////////////////////// 348 ////////////////////////////////////////////////////////////////////////////////
334 // NetworkingPrivateGetEnabledNetworkTypesFunction 349 // NetworkingPrivateGetEnabledNetworkTypesFunction
335 350
336 NetworkingPrivateGetEnabledNetworkTypesFunction:: 351 NetworkingPrivateGetEnabledNetworkTypesFunction::
337 ~NetworkingPrivateGetEnabledNetworkTypesFunction() { 352 ~NetworkingPrivateGetEnabledNetworkTypesFunction() {
338 } 353 }
339 354
340 ExtensionFunction::ResponseAction 355 ExtensionFunction::ResponseAction
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return RespondNow(NoArguments()); 464 return RespondNow(NoArguments());
450 } 465 }
451 466
452 //////////////////////////////////////////////////////////////////////////////// 467 ////////////////////////////////////////////////////////////////////////////////
453 // NetworkingPrivateStartConnectFunction 468 // NetworkingPrivateStartConnectFunction
454 469
455 NetworkingPrivateStartConnectFunction:: 470 NetworkingPrivateStartConnectFunction::
456 ~NetworkingPrivateStartConnectFunction() { 471 ~NetworkingPrivateStartConnectFunction() {
457 } 472 }
458 473
459 bool NetworkingPrivateStartConnectFunction::RunAsync() { 474 ExtensionFunction::ResponseAction NetworkingPrivateStartConnectFunction::Run() {
460 std::unique_ptr<private_api::StartConnect::Params> params = 475 std::unique_ptr<private_api::StartConnect::Params> params =
461 private_api::StartConnect::Params::Create(*args_); 476 private_api::StartConnect::Params::Create(*args_);
462 EXTENSION_FUNCTION_VALIDATE(params); 477 EXTENSION_FUNCTION_VALIDATE(params);
463 478
464 GetDelegate(browser_context()) 479 GetDelegate(browser_context())
465 ->StartConnect( 480 ->StartConnect(
466 params->network_guid, 481 params->network_guid,
467 base::Bind(&NetworkingPrivateStartConnectFunction::Success, this), 482 base::Bind(&NetworkingPrivateStartConnectFunction::Success, this),
468 base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this)); 483 base::Bind(&NetworkingPrivateStartConnectFunction::Failure, this));
469 return true; 484 // Success() or Failure() might have been called synchronously at this point.
485 // In that case this function has already called Respond(). Return
486 // AlreadyResponded() in that case.
487 return did_respond() ? AlreadyResponded() : RespondLater();
470 } 488 }
471 489
472 void NetworkingPrivateStartConnectFunction::Success() { 490 void NetworkingPrivateStartConnectFunction::Success() {
473 SendResponse(true); 491 Respond(NoArguments());
474 } 492 }
475 493
476 void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) { 494 void NetworkingPrivateStartConnectFunction::Failure(const std::string& error) {
477 error_ = error; 495 Respond(Error(error));
478 SendResponse(false);
479 } 496 }
480 497
481 //////////////////////////////////////////////////////////////////////////////// 498 ////////////////////////////////////////////////////////////////////////////////
482 // NetworkingPrivateStartDisconnectFunction 499 // NetworkingPrivateStartDisconnectFunction
483 500
484 NetworkingPrivateStartDisconnectFunction:: 501 NetworkingPrivateStartDisconnectFunction::
485 ~NetworkingPrivateStartDisconnectFunction() { 502 ~NetworkingPrivateStartDisconnectFunction() {
486 } 503 }
487 504
488 bool NetworkingPrivateStartDisconnectFunction::RunAsync() { 505 ExtensionFunction::ResponseAction
506 NetworkingPrivateStartDisconnectFunction::Run() {
489 std::unique_ptr<private_api::StartDisconnect::Params> params = 507 std::unique_ptr<private_api::StartDisconnect::Params> params =
490 private_api::StartDisconnect::Params::Create(*args_); 508 private_api::StartDisconnect::Params::Create(*args_);
491 EXTENSION_FUNCTION_VALIDATE(params); 509 EXTENSION_FUNCTION_VALIDATE(params);
492 510
493 GetDelegate(browser_context()) 511 GetDelegate(browser_context())
494 ->StartDisconnect( 512 ->StartDisconnect(
495 params->network_guid, 513 params->network_guid,
496 base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this), 514 base::Bind(&NetworkingPrivateStartDisconnectFunction::Success, this),
497 base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this)); 515 base::Bind(&NetworkingPrivateStartDisconnectFunction::Failure, this));
498 return true; 516 // Success() or Failure() might have been called synchronously at this point.
517 // In that case this function has already called Respond(). Return
518 // AlreadyResponded() in that case.
519 return did_respond() ? AlreadyResponded() : RespondLater();
499 } 520 }
500 521
501 void NetworkingPrivateStartDisconnectFunction::Success() { 522 void NetworkingPrivateStartDisconnectFunction::Success() {
502 SendResponse(true); 523 Respond(NoArguments());
503 } 524 }
504 525
505 void NetworkingPrivateStartDisconnectFunction::Failure( 526 void NetworkingPrivateStartDisconnectFunction::Failure(
506 const std::string& error) { 527 const std::string& error) {
507 error_ = error; 528 Respond(Error(error));
508 SendResponse(false);
509 } 529 }
510 530
511 //////////////////////////////////////////////////////////////////////////////// 531 ////////////////////////////////////////////////////////////////////////////////
512 // NetworkingPrivateStartActivateFunction 532 // NetworkingPrivateStartActivateFunction
513 533
514 NetworkingPrivateStartActivateFunction:: 534 NetworkingPrivateStartActivateFunction::
515 ~NetworkingPrivateStartActivateFunction() { 535 ~NetworkingPrivateStartActivateFunction() {
516 } 536 }
517 537
518 bool NetworkingPrivateStartActivateFunction::RunAsync() { 538 ExtensionFunction::ResponseAction
539 NetworkingPrivateStartActivateFunction::Run() {
519 std::unique_ptr<private_api::StartActivate::Params> params = 540 std::unique_ptr<private_api::StartActivate::Params> params =
520 private_api::StartActivate::Params::Create(*args_); 541 private_api::StartActivate::Params::Create(*args_);
521 EXTENSION_FUNCTION_VALIDATE(params); 542 EXTENSION_FUNCTION_VALIDATE(params);
522 543
523 GetDelegate(browser_context()) 544 GetDelegate(browser_context())
524 ->StartActivate( 545 ->StartActivate(
525 params->network_guid, params->carrier ? *params->carrier : "", 546 params->network_guid, params->carrier ? *params->carrier : "",
526 base::Bind(&NetworkingPrivateStartActivateFunction::Success, this), 547 base::Bind(&NetworkingPrivateStartActivateFunction::Success, this),
527 base::Bind(&NetworkingPrivateStartActivateFunction::Failure, this)); 548 base::Bind(&NetworkingPrivateStartActivateFunction::Failure, this));
528 return true; 549 // Success() or Failure() might have been called synchronously at this point.
550 // In that case this function has already called Respond(). Return
551 // AlreadyResponded() in that case.
552 return did_respond() ? AlreadyResponded() : RespondLater();
529 } 553 }
530 554
531 void NetworkingPrivateStartActivateFunction::Success() { 555 void NetworkingPrivateStartActivateFunction::Success() {
532 SendResponse(true); 556 Respond(NoArguments());
533 } 557 }
534 558
535 void NetworkingPrivateStartActivateFunction::Failure(const std::string& error) { 559 void NetworkingPrivateStartActivateFunction::Failure(const std::string& error) {
536 error_ = error; 560 Respond(Error(error));
537 SendResponse(false);
538 } 561 }
539 562
540 //////////////////////////////////////////////////////////////////////////////// 563 ////////////////////////////////////////////////////////////////////////////////
541 // NetworkingPrivateVerifyDestinationFunction 564 // NetworkingPrivateVerifyDestinationFunction
542 565
543 NetworkingPrivateVerifyDestinationFunction:: 566 NetworkingPrivateVerifyDestinationFunction::
544 ~NetworkingPrivateVerifyDestinationFunction() { 567 ~NetworkingPrivateVerifyDestinationFunction() {
545 } 568 }
546 569
547 bool NetworkingPrivateVerifyDestinationFunction::RunAsync() { 570 ExtensionFunction::ResponseAction
571 NetworkingPrivateVerifyDestinationFunction::Run() {
548 // This method is private - as such, it should not be exposed through public 572 // This method is private - as such, it should not be exposed through public
549 // networking.onc API. 573 // networking.onc API.
550 // TODO(tbarzic): Consider exposing this via separate API. 574 // TODO(tbarzic): Consider exposing this via separate API.
551 // http://crbug.com/678737 575 // http://crbug.com/678737
552 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 576 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
553 source_url())) { 577 source_url())) {
554 error_ = kPrivateOnlyError; 578 return RespondNow(Error(kPrivateOnlyError));
555 return false;
556 } 579 }
557 580
558 std::unique_ptr<private_api::VerifyDestination::Params> params = 581 std::unique_ptr<private_api::VerifyDestination::Params> params =
559 private_api::VerifyDestination::Params::Create(*args_); 582 private_api::VerifyDestination::Params::Create(*args_);
560 EXTENSION_FUNCTION_VALIDATE(params); 583 EXTENSION_FUNCTION_VALIDATE(params);
561 584
562 GetDelegate(browser_context()) 585 GetDelegate(browser_context())
563 ->VerifyDestination( 586 ->VerifyDestination(
564 params->properties, 587 params->properties,
565 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success, 588 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Success,
566 this), 589 this),
567 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure, 590 base::Bind(&NetworkingPrivateVerifyDestinationFunction::Failure,
568 this)); 591 this));
569 return true; 592 // Success() or Failure() might have been called synchronously at this point.
593 // In that case this function has already called Respond(). Return
594 // AlreadyResponded() in that case.
595 return did_respond() ? AlreadyResponded() : RespondLater();
570 } 596 }
571 597
572 void NetworkingPrivateVerifyDestinationFunction::Success(bool result) { 598 void NetworkingPrivateVerifyDestinationFunction::Success(bool result) {
573 results_ = private_api::VerifyDestination::Results::Create(result); 599 Respond(
574 SendResponse(true); 600 ArgumentList(private_api::VerifyDestination::Results::Create(result)));
575 } 601 }
576 602
577 void NetworkingPrivateVerifyDestinationFunction::Failure( 603 void NetworkingPrivateVerifyDestinationFunction::Failure(
578 const std::string& error) { 604 const std::string& error) {
579 error_ = error; 605 Respond(Error(error));
580 SendResponse(false);
581 } 606 }
582 607
583 //////////////////////////////////////////////////////////////////////////////// 608 ////////////////////////////////////////////////////////////////////////////////
584 // NetworkingPrivateVerifyAndEncryptCredentialsFunction 609 // NetworkingPrivateVerifyAndEncryptCredentialsFunction
585 610
586 NetworkingPrivateVerifyAndEncryptCredentialsFunction:: 611 NetworkingPrivateVerifyAndEncryptCredentialsFunction::
587 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() { 612 ~NetworkingPrivateVerifyAndEncryptCredentialsFunction() {
588 } 613 }
589 614
590 bool NetworkingPrivateVerifyAndEncryptCredentialsFunction::RunAsync() { 615 ExtensionFunction::ResponseAction
616 NetworkingPrivateVerifyAndEncryptCredentialsFunction::Run() {
591 // This method is private - as such, it should not be exposed through public 617 // This method is private - as such, it should not be exposed through public
592 // networking.onc API. 618 // networking.onc API.
593 // TODO(tbarzic): Consider exposing this via separate API. 619 // TODO(tbarzic): Consider exposing this via separate API.
594 // http://crbug.com/678737 620 // http://crbug.com/678737
595 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 621 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
596 source_url())) { 622 source_url())) {
597 error_ = kPrivateOnlyError; 623 return RespondNow(Error(kPrivateOnlyError));
598 return false;
599 } 624 }
600 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params = 625 std::unique_ptr<private_api::VerifyAndEncryptCredentials::Params> params =
601 private_api::VerifyAndEncryptCredentials::Params::Create(*args_); 626 private_api::VerifyAndEncryptCredentials::Params::Create(*args_);
602 EXTENSION_FUNCTION_VALIDATE(params); 627 EXTENSION_FUNCTION_VALIDATE(params);
603 628
604 GetDelegate(browser_context()) 629 GetDelegate(browser_context())
605 ->VerifyAndEncryptCredentials( 630 ->VerifyAndEncryptCredentials(
606 params->network_guid, params->properties, 631 params->network_guid, params->properties,
607 base::Bind( 632 base::Bind(
608 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success, 633 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success,
609 this), 634 this),
610 base::Bind( 635 base::Bind(
611 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure, 636 &NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure,
612 this)); 637 this));
613 return true; 638 // Success() or Failure() might have been called synchronously at this point.
639 // In that case this function has already called Respond(). Return
640 // AlreadyResponded() in that case.
641 return did_respond() ? AlreadyResponded() : RespondLater();
614 } 642 }
615 643
616 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success( 644 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Success(
617 const std::string& result) { 645 const std::string& result) {
618 results_ = private_api::VerifyAndEncryptCredentials::Results::Create(result); 646 Respond(ArgumentList(
619 SendResponse(true); 647 private_api::VerifyAndEncryptCredentials::Results::Create(result)));
620 } 648 }
621 649
622 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure( 650 void NetworkingPrivateVerifyAndEncryptCredentialsFunction::Failure(
623 const std::string& error) { 651 const std::string& error) {
624 error_ = error; 652 Respond(Error(error));
625 SendResponse(false);
626 } 653 }
627 654
628 //////////////////////////////////////////////////////////////////////////////// 655 ////////////////////////////////////////////////////////////////////////////////
629 // NetworkingPrivateVerifyAndEncryptDataFunction 656 // NetworkingPrivateVerifyAndEncryptDataFunction
630 657
631 NetworkingPrivateVerifyAndEncryptDataFunction:: 658 NetworkingPrivateVerifyAndEncryptDataFunction::
632 ~NetworkingPrivateVerifyAndEncryptDataFunction() { 659 ~NetworkingPrivateVerifyAndEncryptDataFunction() {
633 } 660 }
634 661
635 bool NetworkingPrivateVerifyAndEncryptDataFunction::RunAsync() { 662 ExtensionFunction::ResponseAction
663 NetworkingPrivateVerifyAndEncryptDataFunction::Run() {
636 // This method is private - as such, it should not be exposed through public 664 // This method is private - as such, it should not be exposed through public
637 // networking.onc API. 665 // networking.onc API.
638 // TODO(tbarzic): Consider exposing this via separate API. 666 // TODO(tbarzic): Consider exposing this via separate API.
639 // http://crbug.com/678737 667 // http://crbug.com/678737
640 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 668 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
641 source_url())) { 669 source_url())) {
642 error_ = kPrivateOnlyError; 670 return RespondNow(Error(kPrivateOnlyError));
643 return false;
644 } 671 }
645 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params = 672 std::unique_ptr<private_api::VerifyAndEncryptData::Params> params =
646 private_api::VerifyAndEncryptData::Params::Create(*args_); 673 private_api::VerifyAndEncryptData::Params::Create(*args_);
647 EXTENSION_FUNCTION_VALIDATE(params); 674 EXTENSION_FUNCTION_VALIDATE(params);
648 675
649 GetDelegate(browser_context()) 676 GetDelegate(browser_context())
650 ->VerifyAndEncryptData( 677 ->VerifyAndEncryptData(
651 params->properties, params->data, 678 params->properties, params->data,
652 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success, 679 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Success,
653 this), 680 this),
654 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure, 681 base::Bind(&NetworkingPrivateVerifyAndEncryptDataFunction::Failure,
655 this)); 682 this));
656 return true; 683 // Success() or Failure() might have been called synchronously at this point.
684 // In that case this function has already called Respond(). Return
685 // AlreadyResponded() in that case.
686 return did_respond() ? AlreadyResponded() : RespondLater();
657 } 687 }
658 688
659 void NetworkingPrivateVerifyAndEncryptDataFunction::Success( 689 void NetworkingPrivateVerifyAndEncryptDataFunction::Success(
660 const std::string& result) { 690 const std::string& result) {
661 results_ = private_api::VerifyAndEncryptData::Results::Create(result); 691 Respond(
662 SendResponse(true); 692 ArgumentList(private_api::VerifyAndEncryptData::Results::Create(result)));
663 } 693 }
664 694
665 void NetworkingPrivateVerifyAndEncryptDataFunction::Failure( 695 void NetworkingPrivateVerifyAndEncryptDataFunction::Failure(
666 const std::string& error) { 696 const std::string& error) {
667 error_ = error; 697 Respond(Error(error));
668 SendResponse(false);
669 } 698 }
670 699
671 //////////////////////////////////////////////////////////////////////////////// 700 ////////////////////////////////////////////////////////////////////////////////
672 // NetworkingPrivateSetWifiTDLSEnabledStateFunction 701 // NetworkingPrivateSetWifiTDLSEnabledStateFunction
673 702
674 NetworkingPrivateSetWifiTDLSEnabledStateFunction:: 703 NetworkingPrivateSetWifiTDLSEnabledStateFunction::
675 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() { 704 ~NetworkingPrivateSetWifiTDLSEnabledStateFunction() {
676 } 705 }
677 706
678 bool NetworkingPrivateSetWifiTDLSEnabledStateFunction::RunAsync() { 707 ExtensionFunction::ResponseAction
708 NetworkingPrivateSetWifiTDLSEnabledStateFunction::Run() {
679 // This method is private - as such, it should not be exposed through public 709 // This method is private - as such, it should not be exposed through public
680 // networking.onc API. 710 // networking.onc API.
681 // TODO(tbarzic): Consider exposing this via separate API. 711 // TODO(tbarzic): Consider exposing this via separate API.
682 // http://crbug.com/678737 712 // http://crbug.com/678737
683 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 713 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
684 source_url())) { 714 source_url())) {
685 error_ = kPrivateOnlyError; 715 return RespondNow(Error(kPrivateOnlyError));
686 return false;
687 } 716 }
688 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params = 717 std::unique_ptr<private_api::SetWifiTDLSEnabledState::Params> params =
689 private_api::SetWifiTDLSEnabledState::Params::Create(*args_); 718 private_api::SetWifiTDLSEnabledState::Params::Create(*args_);
690 EXTENSION_FUNCTION_VALIDATE(params); 719 EXTENSION_FUNCTION_VALIDATE(params);
691 720
692 GetDelegate(browser_context()) 721 GetDelegate(browser_context())
693 ->SetWifiTDLSEnabledState( 722 ->SetWifiTDLSEnabledState(
694 params->ip_or_mac_address, params->enabled, 723 params->ip_or_mac_address, params->enabled,
695 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success, 724 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success,
696 this), 725 this),
697 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure, 726 base::Bind(&NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure,
698 this)); 727 this));
699 728 // Success() or Failure() might have been called synchronously at this point.
700 return true; 729 // In that case this function has already called Respond(). Return
730 // AlreadyResponded() in that case.
731 return did_respond() ? AlreadyResponded() : RespondLater();
701 } 732 }
702 733
703 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success( 734 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Success(
704 const std::string& result) { 735 const std::string& result) {
705 results_ = private_api::SetWifiTDLSEnabledState::Results::Create(result); 736 Respond(ArgumentList(
706 SendResponse(true); 737 private_api::SetWifiTDLSEnabledState::Results::Create(result)));
707 } 738 }
708 739
709 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure( 740 void NetworkingPrivateSetWifiTDLSEnabledStateFunction::Failure(
710 const std::string& error) { 741 const std::string& error) {
711 error_ = error; 742 Respond(Error(error));
712 SendResponse(false);
713 } 743 }
714 744
715 //////////////////////////////////////////////////////////////////////////////// 745 ////////////////////////////////////////////////////////////////////////////////
716 // NetworkingPrivateGetWifiTDLSStatusFunction 746 // NetworkingPrivateGetWifiTDLSStatusFunction
717 747
718 NetworkingPrivateGetWifiTDLSStatusFunction:: 748 NetworkingPrivateGetWifiTDLSStatusFunction::
719 ~NetworkingPrivateGetWifiTDLSStatusFunction() { 749 ~NetworkingPrivateGetWifiTDLSStatusFunction() {
720 } 750 }
721 751
722 bool NetworkingPrivateGetWifiTDLSStatusFunction::RunAsync() { 752 ExtensionFunction::ResponseAction
753 NetworkingPrivateGetWifiTDLSStatusFunction::Run() {
723 // This method is private - as such, it should not be exposed through public 754 // This method is private - as such, it should not be exposed through public
724 // networking.onc API. 755 // networking.onc API.
725 // TODO(tbarzic): Consider exposing this via separate API. 756 // TODO(tbarzic): Consider exposing this via separate API.
726 // http://crbug.com/678737 757 // http://crbug.com/678737
727 if (!HasPrivateNetworkingAccess(extension(), source_context_type(), 758 if (!HasPrivateNetworkingAccess(extension(), source_context_type(),
728 source_url())) { 759 source_url())) {
729 error_ = kPrivateOnlyError; 760 return RespondNow(Error(kPrivateOnlyError));
730 return false;
731 } 761 }
732 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params = 762 std::unique_ptr<private_api::GetWifiTDLSStatus::Params> params =
733 private_api::GetWifiTDLSStatus::Params::Create(*args_); 763 private_api::GetWifiTDLSStatus::Params::Create(*args_);
734 EXTENSION_FUNCTION_VALIDATE(params); 764 EXTENSION_FUNCTION_VALIDATE(params);
735 765
736 GetDelegate(browser_context()) 766 GetDelegate(browser_context())
737 ->GetWifiTDLSStatus( 767 ->GetWifiTDLSStatus(
738 params->ip_or_mac_address, 768 params->ip_or_mac_address,
739 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success, 769 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Success,
740 this), 770 this),
741 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure, 771 base::Bind(&NetworkingPrivateGetWifiTDLSStatusFunction::Failure,
742 this)); 772 this));
743 773 // Success() or Failure() might have been called synchronously at this point.
744 return true; 774 // In that case this function has already called Respond(). Return
775 // AlreadyResponded() in that case.
776 return did_respond() ? AlreadyResponded() : RespondLater();
745 } 777 }
746 778
747 void NetworkingPrivateGetWifiTDLSStatusFunction::Success( 779 void NetworkingPrivateGetWifiTDLSStatusFunction::Success(
748 const std::string& result) { 780 const std::string& result) {
749 results_ = private_api::GetWifiTDLSStatus::Results::Create(result); 781 Respond(
750 SendResponse(true); 782 ArgumentList(private_api::GetWifiTDLSStatus::Results::Create(result)));
751 } 783 }
752 784
753 void NetworkingPrivateGetWifiTDLSStatusFunction::Failure( 785 void NetworkingPrivateGetWifiTDLSStatusFunction::Failure(
754 const std::string& error) { 786 const std::string& error) {
755 error_ = error; 787 Respond(Error(error));
756 SendResponse(false);
757 } 788 }
758 789
759 //////////////////////////////////////////////////////////////////////////////// 790 ////////////////////////////////////////////////////////////////////////////////
760 // NetworkingPrivateGetCaptivePortalStatusFunction 791 // NetworkingPrivateGetCaptivePortalStatusFunction
761 792
762 NetworkingPrivateGetCaptivePortalStatusFunction:: 793 NetworkingPrivateGetCaptivePortalStatusFunction::
763 ~NetworkingPrivateGetCaptivePortalStatusFunction() { 794 ~NetworkingPrivateGetCaptivePortalStatusFunction() {
764 } 795 }
765 796
766 bool NetworkingPrivateGetCaptivePortalStatusFunction::RunAsync() { 797 ExtensionFunction::ResponseAction
798 NetworkingPrivateGetCaptivePortalStatusFunction::Run() {
767 std::unique_ptr<private_api::GetCaptivePortalStatus::Params> params = 799 std::unique_ptr<private_api::GetCaptivePortalStatus::Params> params =
768 private_api::GetCaptivePortalStatus::Params::Create(*args_); 800 private_api::GetCaptivePortalStatus::Params::Create(*args_);
769 EXTENSION_FUNCTION_VALIDATE(params); 801 EXTENSION_FUNCTION_VALIDATE(params);
770 802
771 GetDelegate(browser_context()) 803 GetDelegate(browser_context())
772 ->GetCaptivePortalStatus( 804 ->GetCaptivePortalStatus(
773 params->network_guid, 805 params->network_guid,
774 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Success, 806 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Success,
775 this), 807 this),
776 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure, 808 base::Bind(&NetworkingPrivateGetCaptivePortalStatusFunction::Failure,
777 this)); 809 this));
778 return true; 810 // Success() or Failure() might have been called synchronously at this point.
811 // In that case this function has already called Respond(). Return
812 // AlreadyResponded() in that case.
813 return did_respond() ? AlreadyResponded() : RespondLater();
779 } 814 }
780 815
781 void NetworkingPrivateGetCaptivePortalStatusFunction::Success( 816 void NetworkingPrivateGetCaptivePortalStatusFunction::Success(
782 const std::string& result) { 817 const std::string& result) {
783 results_ = private_api::GetCaptivePortalStatus::Results::Create( 818 Respond(ArgumentList(private_api::GetCaptivePortalStatus::Results::Create(
784 private_api::ParseCaptivePortalStatus(result)); 819 private_api::ParseCaptivePortalStatus(result))));
785 SendResponse(true);
786 } 820 }
787 821
788 void NetworkingPrivateGetCaptivePortalStatusFunction::Failure( 822 void NetworkingPrivateGetCaptivePortalStatusFunction::Failure(
789 const std::string& error) { 823 const std::string& error) {
790 error_ = error; 824 Respond(Error(error));
791 SendResponse(false);
792 } 825 }
793 826
794 //////////////////////////////////////////////////////////////////////////////// 827 ////////////////////////////////////////////////////////////////////////////////
795 // NetworkingPrivateUnlockCellularSimFunction 828 // NetworkingPrivateUnlockCellularSimFunction
796 829
797 NetworkingPrivateUnlockCellularSimFunction:: 830 NetworkingPrivateUnlockCellularSimFunction::
798 ~NetworkingPrivateUnlockCellularSimFunction() {} 831 ~NetworkingPrivateUnlockCellularSimFunction() {}
799 832
800 bool NetworkingPrivateUnlockCellularSimFunction::RunAsync() { 833 ExtensionFunction::ResponseAction
834 NetworkingPrivateUnlockCellularSimFunction::Run() {
801 std::unique_ptr<private_api::UnlockCellularSim::Params> params = 835 std::unique_ptr<private_api::UnlockCellularSim::Params> params =
802 private_api::UnlockCellularSim::Params::Create(*args_); 836 private_api::UnlockCellularSim::Params::Create(*args_);
803 EXTENSION_FUNCTION_VALIDATE(params); 837 EXTENSION_FUNCTION_VALIDATE(params);
804 838
805 GetDelegate(browser_context()) 839 GetDelegate(browser_context())
806 ->UnlockCellularSim( 840 ->UnlockCellularSim(
807 params->network_guid, params->pin, params->puk ? *params->puk : "", 841 params->network_guid, params->pin, params->puk ? *params->puk : "",
808 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Success, 842 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Success,
809 this), 843 this),
810 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Failure, 844 base::Bind(&NetworkingPrivateUnlockCellularSimFunction::Failure,
811 this)); 845 this));
812 return true; 846 // Success() or Failure() might have been called synchronously at this point.
847 // In that case this function has already called Respond(). Return
848 // AlreadyResponded() in that case.
849 return did_respond() ? AlreadyResponded() : RespondLater();
813 } 850 }
814 851
815 void NetworkingPrivateUnlockCellularSimFunction::Success() { 852 void NetworkingPrivateUnlockCellularSimFunction::Success() {
816 SendResponse(true); 853 Respond(NoArguments());
817 } 854 }
818 855
819 void NetworkingPrivateUnlockCellularSimFunction::Failure( 856 void NetworkingPrivateUnlockCellularSimFunction::Failure(
820 const std::string& error) { 857 const std::string& error) {
821 error_ = error; 858 Respond(Error(error));
822 SendResponse(false);
823 } 859 }
824 860
825 //////////////////////////////////////////////////////////////////////////////// 861 ////////////////////////////////////////////////////////////////////////////////
826 // NetworkingPrivateSetCellularSimStateFunction 862 // NetworkingPrivateSetCellularSimStateFunction
827 863
828 NetworkingPrivateSetCellularSimStateFunction:: 864 NetworkingPrivateSetCellularSimStateFunction::
829 ~NetworkingPrivateSetCellularSimStateFunction() {} 865 ~NetworkingPrivateSetCellularSimStateFunction() {}
830 866
831 bool NetworkingPrivateSetCellularSimStateFunction::RunAsync() { 867 ExtensionFunction::ResponseAction
868 NetworkingPrivateSetCellularSimStateFunction::Run() {
832 std::unique_ptr<private_api::SetCellularSimState::Params> params = 869 std::unique_ptr<private_api::SetCellularSimState::Params> params =
833 private_api::SetCellularSimState::Params::Create(*args_); 870 private_api::SetCellularSimState::Params::Create(*args_);
834 EXTENSION_FUNCTION_VALIDATE(params); 871 EXTENSION_FUNCTION_VALIDATE(params);
835 872
836 GetDelegate(browser_context()) 873 GetDelegate(browser_context())
837 ->SetCellularSimState( 874 ->SetCellularSimState(
838 params->network_guid, params->sim_state.require_pin, 875 params->network_guid, params->sim_state.require_pin,
839 params->sim_state.current_pin, 876 params->sim_state.current_pin,
840 params->sim_state.new_pin ? *params->sim_state.new_pin : "", 877 params->sim_state.new_pin ? *params->sim_state.new_pin : "",
841 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Success, 878 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Success,
842 this), 879 this),
843 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Failure, 880 base::Bind(&NetworkingPrivateSetCellularSimStateFunction::Failure,
844 this)); 881 this));
845 return true; 882 // Success() or Failure() might have been called synchronously at this point.
883 // In that case this function has already called Respond(). Return
884 // AlreadyResponded() in that case.
885 return did_respond() ? AlreadyResponded() : RespondLater();
846 } 886 }
847 887
848 void NetworkingPrivateSetCellularSimStateFunction::Success() { 888 void NetworkingPrivateSetCellularSimStateFunction::Success() {
849 SendResponse(true); 889 Respond(NoArguments());
850 } 890 }
851 891
852 void NetworkingPrivateSetCellularSimStateFunction::Failure( 892 void NetworkingPrivateSetCellularSimStateFunction::Failure(
853 const std::string& error) { 893 const std::string& error) {
854 error_ = error; 894 Respond(Error(error));
855 SendResponse(false);
856 } 895 }
857 896
858 //////////////////////////////////////////////////////////////////////////////// 897 ////////////////////////////////////////////////////////////////////////////////
859 // NetworkingPrivateGetGlobalPolicyFunction 898 // NetworkingPrivateGetGlobalPolicyFunction
860 899
861 NetworkingPrivateGetGlobalPolicyFunction:: 900 NetworkingPrivateGetGlobalPolicyFunction::
862 ~NetworkingPrivateGetGlobalPolicyFunction() {} 901 ~NetworkingPrivateGetGlobalPolicyFunction() {}
863 902
864 ExtensionFunction::ResponseAction 903 ExtensionFunction::ResponseAction
865 NetworkingPrivateGetGlobalPolicyFunction::Run() { 904 NetworkingPrivateGetGlobalPolicyFunction::Run() {
866 std::unique_ptr<base::DictionaryValue> policy_dict( 905 std::unique_ptr<base::DictionaryValue> policy_dict(
867 GetDelegate(browser_context())->GetGlobalPolicy()); 906 GetDelegate(browser_context())->GetGlobalPolicy());
868 DCHECK(policy_dict); 907 DCHECK(policy_dict);
869 // private_api::GlobalPolicy is a subset of the global policy dictionary 908 // private_api::GlobalPolicy is a subset of the global policy dictionary
870 // (by definition), so use the api setter/getter to generate the subset. 909 // (by definition), so use the api setter/getter to generate the subset.
871 std::unique_ptr<private_api::GlobalPolicy> policy( 910 std::unique_ptr<private_api::GlobalPolicy> policy(
872 private_api::GlobalPolicy::FromValue(*policy_dict)); 911 private_api::GlobalPolicy::FromValue(*policy_dict));
873 DCHECK(policy); 912 DCHECK(policy);
874 return RespondNow( 913 return RespondNow(
875 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy))); 914 ArgumentList(private_api::GetGlobalPolicy::Results::Create(*policy)));
876 } 915 }
877 916
878 } // namespace extensions 917 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698