diff options
author | jrummell <jrummell@chromium.org> | 2014-10-07 13:09:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-07 20:10:07 +0000 |
commit | 60b669f6768594714aca8b72d1530ed2672c126b (patch) | |
tree | 27d581c827d321564cde3c32cbd1b96f895b3329 /media/base/cdm_callback_promise.cc | |
parent | 39fd2c99a478bc28f6468a9c3c4be22d283fbf3e (diff) | |
download | chromium_src-60b669f6768594714aca8b72d1530ed2672c126b.zip chromium_src-60b669f6768594714aca8b72d1530ed2672c126b.tar.gz chromium_src-60b669f6768594714aca8b72d1530ed2672c126b.tar.bz2 |
Refactor CdmPromise and related classes
Move the implementation from CdmPromiseTemplate into a new templated
class CdmCallbackPromise class. CdmResultPromise can now override
resolve() and reject() without having to be concerned with the
callbacks.
Also convert the templates into variadic templates to avoid the
specialization for <void> (now just <>).
BUG=358271
TEST=existing EME tests still pass
Review URL: https://codereview.chromium.org/604283003
Cr-Commit-Position: refs/heads/master@{#298554}
Diffstat (limited to 'media/base/cdm_callback_promise.cc')
-rw-r--r-- | media/base/cdm_callback_promise.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/media/base/cdm_callback_promise.cc b/media/base/cdm_callback_promise.cc new file mode 100644 index 0000000..7b952ab --- /dev/null +++ b/media/base/cdm_callback_promise.cc @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/cdm_callback_promise.h" + +#include "base/logging.h" + +namespace media { + +template <typename... T> +CdmCallbackPromise<T...>::CdmCallbackPromise( + const base::Callback<void(const T&...)>& resolve_cb, + const PromiseRejectedCB& reject_cb) + : resolve_cb_(resolve_cb), reject_cb_(reject_cb) { + DCHECK(!resolve_cb_.is_null()); + DCHECK(!reject_cb_.is_null()); +} + +template <typename... T> +CdmCallbackPromise<T...>::~CdmCallbackPromise() { +} + +template <typename... T> +void CdmCallbackPromise<T...>::resolve(const T&... result) { + MarkPromiseSettled(); + resolve_cb_.Run(result...); +} + +template <typename... T> +void CdmCallbackPromise<T...>::reject(MediaKeys::Exception exception_code, + uint32 system_code, + const std::string& error_message) { + MarkPromiseSettled(); + reject_cb_.Run(exception_code, system_code, error_message); +} + +// Explicit template instantiation for the Promises needed. +template class MEDIA_EXPORT CdmCallbackPromise<>; +template class MEDIA_EXPORT CdmCallbackPromise<std::string>; +template class MEDIA_EXPORT CdmCallbackPromise<KeyIdsVector>; + +} // namespace media |