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
3 // found in the LICENSE file.
5 #include "media/mojo/services/mojo_cdm_promise.h"
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "media/base/decryptor.h"
13 #include "media/base/media_keys.h"
17 static interfaces::CdmPromiseResultPtr
GetRejectResult(
18 MediaKeys::Exception exception
,
20 const std::string
& error_message
) {
21 interfaces::CdmPromiseResultPtr
cdm_promise_result(
22 interfaces::CdmPromiseResult::New());
23 cdm_promise_result
->success
= false;
24 cdm_promise_result
->exception
=
25 static_cast<interfaces::CdmException
>(exception
);
26 cdm_promise_result
->system_code
= system_code
;
27 cdm_promise_result
->error_message
= error_message
;
28 return cdm_promise_result
.Pass();
31 template <typename
... T
>
32 MojoCdmPromise
<T
...>::MojoCdmPromise(const CallbackType
& callback
)
33 : callback_(callback
) {
34 DCHECK(!callback_
.is_null());
37 template <typename
... T
>
38 MojoCdmPromise
<T
...>::~MojoCdmPromise() {
39 if (!callback_
.is_null())
40 DVLOG(1) << "Promise not resolved before destruction.";
43 template <typename
... T
>
44 void MojoCdmPromise
<T
...>::resolve(const T
&... result
) {
46 interfaces::CdmPromiseResultPtr
cdm_promise_result(
47 interfaces::CdmPromiseResult::New());
48 cdm_promise_result
->success
= true;
49 callback_
.Run(cdm_promise_result
.Pass(),
50 MojoTypeTrait
<T
>::MojoType::From(result
)...);
54 template <typename
... T
>
55 void MojoCdmPromise
<T
...>::reject(MediaKeys::Exception exception
,
57 const std::string
& error_message
) {
59 callback_
.Run(GetRejectResult(exception
, system_code
, error_message
),
60 MojoTypeTrait
<T
>::DefaultValue()...);
64 template class MojoCdmPromise
<>;
65 template class MojoCdmPromise
<std::string
>;