| 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 ~AlreadyRespondedAction() override {} |
| 159 |
| 160 void Execute() override {} |
| 161 }; |
| 162 |
| 156 // Used in implementation of ScopedUserGestureForTests. | 163 // Used in implementation of ScopedUserGestureForTests. |
| 157 class UserGestureForTests { | 164 class UserGestureForTests { |
| 158 public: | 165 public: |
| 159 static UserGestureForTests* GetInstance(); | 166 static UserGestureForTests* GetInstance(); |
| 160 | 167 |
| 161 // Returns true if there is at least one ScopedUserGestureForTests object | 168 // Returns true if there is at least one ScopedUserGestureForTests object |
| 162 // alive. | 169 // alive. |
| 163 bool HaveGesture(); | 170 bool HaveGesture(); |
| 164 | 171 |
| 165 // These should be called when a ScopedUserGestureForTests object is | 172 // 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) { | 393 ResponseValue result) { |
| 387 return ResponseAction(new RespondNowAction( | 394 return ResponseAction(new RespondNowAction( |
| 388 std::move(result), | 395 std::move(result), |
| 389 base::Bind(&ExtensionFunction::SendResponseImpl, this))); | 396 base::Bind(&ExtensionFunction::SendResponseImpl, this))); |
| 390 } | 397 } |
| 391 | 398 |
| 392 ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { | 399 ExtensionFunction::ResponseAction ExtensionFunction::RespondLater() { |
| 393 return ResponseAction(new RespondLaterAction()); | 400 return ResponseAction(new RespondLaterAction()); |
| 394 } | 401 } |
| 395 | 402 |
| 403 ExtensionFunction::ResponseAction ExtensionFunction::AlreadyResponded() { |
| 404 DCHECK(did_respond()) << "ExtensionFunction did not call Respond()," |
| 405 " but Run() returned AlreadyResponded()"; |
| 406 return ResponseAction(new AlreadyRespondedAction()); |
| 407 } |
| 408 |
| 396 // static | 409 // static |
| 397 ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( | 410 ExtensionFunction::ResponseAction ExtensionFunction::ValidationFailure( |
| 398 ExtensionFunction* function) { | 411 ExtensionFunction* function) { |
| 399 return function->RespondNow(function->BadMessage()); | 412 return function->RespondNow(function->BadMessage()); |
| 400 } | 413 } |
| 401 | 414 |
| 402 void ExtensionFunction::Respond(ResponseValue result) { | 415 void ExtensionFunction::Respond(ResponseValue result) { |
| 403 SendResponseImpl(result->Apply()); | 416 SendResponseImpl(result->Apply()); |
| 404 } | 417 } |
| 405 | 418 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 void AsyncExtensionFunction::SendResponse(bool success) { | 629 void AsyncExtensionFunction::SendResponse(bool success) { |
| 617 ResponseValue response; | 630 ResponseValue response; |
| 618 if (success) { | 631 if (success) { |
| 619 response = ArgumentList(std::move(results_)); | 632 response = ArgumentList(std::move(results_)); |
| 620 } else { | 633 } else { |
| 621 response = results_ ? ErrorWithArguments(std::move(results_), error_) | 634 response = results_ ? ErrorWithArguments(std::move(results_), error_) |
| 622 : Error(error_); | 635 : Error(error_); |
| 623 } | 636 } |
| 624 Respond(std::move(response)); | 637 Respond(std::move(response)); |
| 625 } | 638 } |
| OLD | NEW |