Chromium Code Reviews| Index: media/mojo/services/mojo_cdm_promise.cc |
| diff --git a/media/mojo/services/mojo_cdm_promise.cc b/media/mojo/services/mojo_cdm_promise.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e2e5dead5421685c6c6ebcc36b5eecdf1e6fb97b |
| --- /dev/null |
| +++ b/media/mojo/services/mojo_cdm_promise.cc |
| @@ -0,0 +1,59 @@ |
| +// 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/mojo/services/mojo_cdm_promise.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "media/base/decryptor.h" |
| + |
| +namespace media { |
| + |
| +static mojo::CdmPromiseResultPtr GetRejectResult( |
| + MediaKeys::Exception exception, |
| + uint32 system_code, |
| + const std::string& error_message) { |
| + mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New()); |
| + cdm_promise_result->success = false; |
| + cdm_promise_result->exception = static_cast<mojo::CdmException>(exception); |
| + cdm_promise_result->system_code = system_code; |
| + cdm_promise_result->error_message = error_message; |
| + return cdm_promise_result.Pass(); |
| +} |
| + |
| +template <typename... T> |
| +MojoCdmPromise<T...>::MojoCdmPromise(const CallbackType& callback) |
| + : callback_(callback) { |
| + DCHECK(!callback_.is_null()); |
| +} |
| + |
| +template <typename... T> |
| +MojoCdmPromise<T...>::~MojoCdmPromise() { |
| + if (!callback_.is_null()) |
| + DVLOG(1) << "Promise not resolved before destruction."; |
| +} |
| + |
| +template <typename... T> |
| +void MojoCdmPromise<T...>::resolve(const T&... result) { |
| + mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New()); |
| + cdm_promise_result->success = true; |
| + callback_.Run(cdm_promise_result.Pass(), |
| + MojoTypeTrait<T>::MojoType::From(result)...); |
| + callback_.reset(); |
| +} |
| + |
| +template <typename... T> |
| +void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception, |
| + uint32 system_code, |
| + const std::string& error_message) { |
| + callback_.Run(GetRejectResult(exception, system_code, error_message), |
| + MojoTypeTrait<T>::DefaultValue()...); |
| + callback_.reset(); |
| +} |
| + |
| +template class MojoCdmPromise<>; |
| +template class MojoCdmPromise<std::string>; |
|
ddorwin
2014/12/12 19:25:13
Need std includes: string and vector.
xhwang
2014/12/12 23:15:44
Done.
|
| +template class MojoCdmPromise<std::vector<std::vector<uint8_t>>>; |
| + |
| +} // namespace media |