This sets up API to release OutputSurface from LTHClient.
[chromium-blink-merge.git] / media / mojo / services / mojo_cdm_promise.cc
blob7b0dc6cf5a95e5b47be1bbc92c14acb751a3898f
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"
7 #include <string>
8 #include <vector>
10 #include "base/bind.h"
11 #include "base/logging.h"
12 #include "media/base/decryptor.h"
13 #include "media/base/media_keys.h"
15 namespace media {
17 static interfaces::CdmPromiseResultPtr GetRejectResult(
18 MediaKeys::Exception exception,
19 uint32_t system_code,
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) {
45 MarkPromiseSettled();
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)...);
51 callback_.reset();
54 template <typename... T>
55 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception,
56 uint32_t system_code,
57 const std::string& error_message) {
58 MarkPromiseSettled();
59 callback_.Run(GetRejectResult(exception, system_code, error_message),
60 MojoTypeTrait<T>::DefaultValue()...);
61 callback_.reset();
64 template class MojoCdmPromise<>;
65 template class MojoCdmPromise<std::string>;
67 } // namespace media