Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extension_function.h" | 5 #include "extensions/browser/extension_function.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 SendResponseCallback send_response_; | 146 SendResponseCallback send_response_; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 class RespondLaterAction : public ExtensionFunction::ResponseActionObject { | 149 class RespondLaterAction : public ExtensionFunction::ResponseActionObject { |
| 150 public: | 150 public: |
| 151 ~RespondLaterAction() override {} | 151 ~RespondLaterAction() override {} |
| 152 | 152 |
| 153 void Execute() override {} | 153 void Execute() override {} |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 class AlreadyRespondedAction : public ExtensionFunction::ResponseActionObject { | |
| 157 public: | |
| 158 using DidRespondCallback = base::Callback<bool(void)>; | |
| 159 AlreadyRespondedAction(const DidRespondCallback& did_respond) | |
| 160 : did_respond_(did_respond) {} | |
| 161 ~AlreadyRespondedAction() override {} | |
| 162 | |
| 163 void Execute() override { | |
| 164 DCHECK(did_respond_.Run()) << "ExtensionFunction did not call Respond()," | |
| 165 " but Run() returned AlreadyResponded()"; | |
| 166 } | |
| 167 | |
| 168 private: | |
| 169 DidRespondCallback did_respond_; | |
| 170 }; | |
| 171 | |
| 156 // Used in implementation of ScopedUserGestureForTests. | 172 // Used in implementation of ScopedUserGestureForTests. |
| 157 class UserGestureForTests { | 173 class UserGestureForTests { |
| 158 public: | 174 public: |
| 159 static UserGestureForTests* GetInstance(); | 175 static UserGestureForTests* GetInstance(); |
| 160 | 176 |
| 161 // Returns true if there is at least one ScopedUserGestureForTests object | 177 // Returns true if there is at least one ScopedUserGestureForTests object |
| 162 // alive. | 178 // alive. |
| 163 bool HaveGesture(); | 179 bool HaveGesture(); |
| 164 | 180 |
| 165 // These should be called when a ScopedUserGestureForTests object is | 181 // These should be called when a ScopedUserGestureForTests object is |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 ResponseValue result) { | 402 ResponseValue result) { |
| 387 return ResponseAction(new RespondNowAction( | 403 return ResponseAction(new RespondNowAction( |
| 388 std::move(result), | 404 std::move(result), |
| 389 base::Bind(&ExtensionFunction::SendResponseImpl, this))); | 405 base::Bind(&ExtensionFunction::SendResponseImpl, this))); |
| 390 } | 406 } |
| 391 | 407 |
| 392 ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { | 408 ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { |
| 393 return ResponseAction(new RespondLaterAction()); | 409 return ResponseAction(new RespondLaterAction()); |
| 394 } | 410 } |
| 395 | 411 |
| 412 ExtensionFunction::ResponseAction ExtensionFunction::AlreadyResponded() { | |
| 413 return ResponseAction(new AlreadyRespondedAction( | |
| 414 base::Bind(&ExtensionFunction::did_respond, this))); | |
|
Devlin
2017/01/20 00:16:02
Why not just DCHECK() here instead, and have Execu
lazyboy
2017/01/20 00:54:47
Right, thanks.
Done.
| |
| 415 } | |
| 416 | |
| 396 // static | 417 // static |
| 397 ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( | 418 ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( |
| 398 ExtensionFunction* function) { | 419 ExtensionFunction* function) { |
| 399 return function->RespondNow(function->BadMessage()); | 420 return function->RespondNow(function->BadMessage()); |
| 400 } | 421 } |
| 401 | 422 |
| 402 void ExtensionFunction::Respond(ResponseValue result) { | 423 void ExtensionFunction::Respond(ResponseValue result) { |
| 403 SendResponseImpl(result->Apply()); | 424 SendResponseImpl(result->Apply()); |
| 404 } | 425 } |
| 405 | 426 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 616 void AsyncExtensionFunction::SendResponse(bool success) { | 637 void AsyncExtensionFunction::SendResponse(bool success) { |
| 617 ResponseValue response; | 638 ResponseValue response; |
| 618 if (success) { | 639 if (success) { |
| 619 response = ArgumentList(std::move(results_)); | 640 response = ArgumentList(std::move(results_)); |
| 620 } else { | 641 } else { |
| 621 response = results_ ? ErrorWithArguments(std::move(results_), error_) | 642 response = results_ ? ErrorWithArguments(std::move(results_), error_) |
| 622 : Error(error_); | 643 : Error(error_); |
| 623 } | 644 } |
| 624 Respond(std::move(response)); | 645 Respond(std::move(response)); |
| 625 } | 646 } |
| OLD | NEW |