| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BLIMP_COMMON_MANDATORY_CALLBACK_H_ | 5 #ifndef BLIMP_COMMON_MANDATORY_CALLBACK_H_ |
| 6 #define BLIMP_COMMON_MANDATORY_CALLBACK_H_ | 6 #define BLIMP_COMMON_MANDATORY_CALLBACK_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 other.was_run_ = false; | 61 other.was_run_ = false; |
| 62 #endif | 62 #endif |
| 63 } | 63 } |
| 64 | 64 |
| 65 ~MandatoryCallback() { | 65 ~MandatoryCallback() { |
| 66 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
| 67 DCHECK(cb_.is_null() || was_run_); | 67 DCHECK(cb_.is_null() || was_run_); |
| 68 #endif | 68 #endif |
| 69 } | 69 } |
| 70 | 70 |
| 71 // This a overload that handles the case where there are no arguments provided |
| 72 template <typename...> |
| 73 ReturnType Run() { |
| 74 DCHECK(cb_); // Can't be run following std::move. |
| 75 |
| 76 #if DCHECK_IS_ON() |
| 77 DCHECK(!was_run_); |
| 78 was_run_ = true; |
| 79 #endif |
| 80 |
| 81 cb_.Run(); |
| 82 } |
| 83 |
| 71 template <typename... RunArgs> | 84 template <typename... RunArgs> |
| 72 ReturnType Run(RunArgs... args) { | 85 ReturnType Run(RunArgs... args) { |
| 73 DCHECK(cb_); // Can't be run following std::move. | 86 DCHECK(cb_); // Can't be run following std::move. |
| 74 | 87 |
| 75 #if DCHECK_IS_ON() | 88 #if DCHECK_IS_ON() |
| 76 DCHECK(!was_run_); | 89 DCHECK(!was_run_); |
| 77 was_run_ = true; | 90 was_run_ = true; |
| 78 #endif | 91 #endif |
| 79 | 92 |
| 80 cb_.Run(std::forward<RunArgs...>(args...)); | 93 cb_.Run(std::forward<RunArgs...>(args...)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 DISALLOW_COPY_AND_ASSIGN(MandatoryCallback); | 104 DISALLOW_COPY_AND_ASSIGN(MandatoryCallback); |
| 92 }; | 105 }; |
| 93 | 106 |
| 94 // Creates a leak-checking proxy callback around |callback|. | 107 // Creates a leak-checking proxy callback around |callback|. |
| 95 template <typename SignatureType> | 108 template <typename SignatureType> |
| 96 MandatoryCallback<SignatureType> CreateMandatoryCallback( | 109 MandatoryCallback<SignatureType> CreateMandatoryCallback( |
| 97 const base::Callback<SignatureType>& callback) { | 110 const base::Callback<SignatureType>& callback) { |
| 98 return MandatoryCallback<SignatureType>(callback); | 111 return MandatoryCallback<SignatureType>(callback); |
| 99 } | 112 } |
| 100 | 113 |
| 114 using MandatoryClosure = MandatoryCallback<void()>; |
| 115 |
| 101 } // namespace blimp | 116 } // namespace blimp |
| 102 | 117 |
| 103 #endif // BLIMP_COMMON_MANDATORY_CALLBACK_H_ | 118 #endif // BLIMP_COMMON_MANDATORY_CALLBACK_H_ |
| OLD | NEW |