| OLD | NEW |
| 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 #ifndef MEDIA_BASE_CDM_PROMISE_H_ | 5 #ifndef MEDIA_BASE_CDM_PROMISE_H_ |
| 6 #define MEDIA_BASE_CDM_PROMISE_H_ | 6 #define MEDIA_BASE_CDM_PROMISE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // CdmPromise implementation. | 92 // CdmPromise implementation. |
| 93 virtual void reject(MediaKeys::Exception exception_code, | 93 virtual void reject(MediaKeys::Exception exception_code, |
| 94 uint32_t system_code, | 94 uint32_t system_code, |
| 95 const std::string& error_message) = 0; | 95 const std::string& error_message) = 0; |
| 96 | 96 |
| 97 ResolveParameterType GetResolveParameterType() const override { | 97 ResolveParameterType GetResolveParameterType() const override { |
| 98 return CdmPromiseTraits<T...>::kType; | 98 return CdmPromiseTraits<T...>::kType; |
| 99 } | 99 } |
| 100 | 100 |
| 101 protected: | 101 protected: |
| 102 bool IsPromiseSettled() const { return is_settled_; } |
| 103 |
| 102 // All implementations must call this method in resolve() and reject() methods | 104 // All implementations must call this method in resolve() and reject() methods |
| 103 // to indicate that the promise has been settled. | 105 // to indicate that the promise has been settled. |
| 104 void MarkPromiseSettled() { | 106 void MarkPromiseSettled() { |
| 105 // Promise can only be settled once. | 107 // Promise can only be settled once. |
| 106 DCHECK(!is_settled_); | 108 DCHECK(!is_settled_); |
| 107 is_settled_ = true; | 109 is_settled_ = true; |
| 108 } | 110 } |
| 109 | 111 |
| 112 // Must be called by the concrete destructor if !IsPromiseSettled(). |
| 113 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual. |
| 114 void RejectPromiseOnDestruction() { |
| 115 DCHECK(!is_settled_); |
| 116 std::string message = |
| 117 "Unfulfilled promise rejected automatically during destruction."; |
| 118 DVLOG(1) << message; |
| 119 reject(MediaKeys::INVALID_STATE_ERROR, 0, message); |
| 120 DCHECK(is_settled_); |
| 121 } |
| 122 |
| 110 private: | 123 private: |
| 111 // Keep track of whether the promise has been resolved or rejected yet. | 124 // Keep track of whether the promise has been resolved or rejected yet. |
| 112 bool is_settled_; | 125 bool is_settled_; |
| 113 | 126 |
| 114 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 127 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
| 115 }; | 128 }; |
| 116 | 129 |
| 117 } // namespace media | 130 } // namespace media |
| 118 | 131 |
| 119 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 132 #endif // MEDIA_BASE_CDM_PROMISE_H_ |
| OLD | NEW |