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 mojo::CdmPromiseResultPtr
GetRejectResult(
18 MediaKeys::Exception exception
,
20 const std::string
& error_message
) {
21 mojo::CdmPromiseResultPtr
cdm_promise_result(mojo::CdmPromiseResult::New());
22 cdm_promise_result
->success
= false;
23 cdm_promise_result
->exception
= static_cast<mojo::CdmException
>(exception
);
24 cdm_promise_result
->system_code
= system_code
;
25 cdm_promise_result
->error_message
= error_message
;
26 return cdm_promise_result
.Pass();
29 template <typename
... T
>
30 MojoCdmPromise
<T
...>::MojoCdmPromise(const CallbackType
& callback
)
31 : callback_(callback
) {
32 DCHECK(!callback_
.is_null());
35 template <typename
... T
>
36 MojoCdmPromise
<T
...>::~MojoCdmPromise() {
37 if (!callback_
.is_null())
38 DVLOG(1) << "Promise not resolved before destruction.";
41 template <typename
... T
>
42 void MojoCdmPromise
<T
...>::resolve(const T
&... result
) {
44 mojo::CdmPromiseResultPtr
cdm_promise_result(mojo::CdmPromiseResult::New());
45 cdm_promise_result
->success
= true;
46 callback_
.Run(cdm_promise_result
.Pass(),
47 MojoTypeTrait
<T
>::MojoType::From(result
)...);
51 template <typename
... T
>
52 void MojoCdmPromise
<T
...>::reject(MediaKeys::Exception exception
,
54 const std::string
& error_message
) {
56 callback_
.Run(GetRejectResult(exception
, system_code
, error_message
),
57 MojoTypeTrait
<T
>::DefaultValue()...);
61 template class MojoCdmPromise
<>;
62 template class MojoCdmPromise
<std::string
>;