Chromium Code Reviews| 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 #include "media/base/cdm_callback_promise.h" | 5 #include "media/base/cdm_callback_promise.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 | 9 |
| 9 namespace media { | 10 namespace media { |
| 10 | 11 |
| 11 template <typename... T> | 12 template <typename... T> |
| 12 CdmCallbackPromise<T...>::CdmCallbackPromise( | 13 CdmCallbackPromise<T...>::CdmCallbackPromise( |
| 13 const base::Callback<void(const T&...)>& resolve_cb, | 14 const base::Callback<void(const T&...)>& resolve_cb, |
| 14 const PromiseRejectedCB& reject_cb) | 15 const PromiseRejectedCB& reject_cb) |
| 15 : resolve_cb_(resolve_cb), reject_cb_(reject_cb) { | 16 : resolve_cb_(resolve_cb), reject_cb_(reject_cb) { |
| 16 DCHECK(!resolve_cb_.is_null()); | 17 DCHECK(!resolve_cb_.is_null()); |
| 17 DCHECK(!reject_cb_.is_null()); | 18 DCHECK(!reject_cb_.is_null()); |
| 18 } | 19 } |
| 19 | 20 |
| 20 template <typename... T> | 21 template <typename... T> |
| 21 CdmCallbackPromise<T...>::~CdmCallbackPromise() { | 22 CdmCallbackPromise<T...>::~CdmCallbackPromise() { |
| 23 if (resolve_cb_.is_null() || reject_cb_.is_null()) | |
| 24 return; | |
|
ddorwin
2016/02/25 19:14:12
// Promise has already been settled.
?
Or just ad
| |
| 25 | |
| 26 std::string message = | |
| 27 "Unfulfilled promise rejected automatically during destruction."; | |
| 28 DVLOG(1) << message; | |
| 29 reject(MediaKeys::INVALID_STATE_ERROR, 0, message); | |
| 22 } | 30 } |
| 23 | 31 |
| 24 template <typename... T> | 32 template <typename... T> |
| 25 void CdmCallbackPromise<T...>::resolve(const T&... result) { | 33 void CdmCallbackPromise<T...>::resolve(const T&... result) { |
| 26 MarkPromiseSettled(); | 34 MarkPromiseSettled(); |
|
jrummell
2016/02/25 02:30:03
This call sets a flag to indicate that the promise
xhwang
2016/02/25 07:49:21
In CdmPromiseTemplate's destructor, I can't call r
ddorwin
2016/02/25 19:14:12
Is there still a possibility that specifications/c
| |
| 27 resolve_cb_.Run(result...); | 35 base::ResetAndReturn(&resolve_cb_).Run(result...); |
| 28 } | 36 } |
| 29 | 37 |
| 30 template <typename... T> | 38 template <typename... T> |
| 31 void CdmCallbackPromise<T...>::reject(MediaKeys::Exception exception_code, | 39 void CdmCallbackPromise<T...>::reject(MediaKeys::Exception exception_code, |
| 32 uint32_t system_code, | 40 uint32_t system_code, |
| 33 const std::string& error_message) { | 41 const std::string& error_message) { |
| 34 MarkPromiseSettled(); | 42 MarkPromiseSettled(); |
| 35 reject_cb_.Run(exception_code, system_code, error_message); | 43 base::ResetAndReturn(&reject_cb_) |
| 44 .Run(exception_code, system_code, error_message); | |
| 36 } | 45 } |
| 37 | 46 |
| 38 // Explicit template instantiation for the Promises needed. | 47 // Explicit template instantiation for the Promises needed. |
| 39 template class MEDIA_EXPORT CdmCallbackPromise<>; | 48 template class MEDIA_EXPORT CdmCallbackPromise<>; |
| 40 template class MEDIA_EXPORT CdmCallbackPromise<std::string>; | 49 template class MEDIA_EXPORT CdmCallbackPromise<std::string>; |
| 41 | 50 |
| 42 } // namespace media | 51 } // namespace media |
| OLD | NEW |