| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "media/mojo/services/mojo_cdm_promise.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/logging.h" |
| 12 #include "media/base/decryptor.h" |
| 13 #include "media/base/media_keys.h" |
| 14 |
| 15 namespace media { |
| 16 |
| 17 static mojo::CdmPromiseResultPtr GetRejectResult( |
| 18 MediaKeys::Exception exception, |
| 19 uint32_t system_code, |
| 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(); |
| 27 } |
| 28 |
| 29 template <typename... T> |
| 30 MojoCdmPromise<T...>::MojoCdmPromise(const CallbackType& callback) |
| 31 : callback_(callback) { |
| 32 DCHECK(!callback_.is_null()); |
| 33 } |
| 34 |
| 35 template <typename... T> |
| 36 MojoCdmPromise<T...>::~MojoCdmPromise() { |
| 37 if (!callback_.is_null()) |
| 38 DVLOG(1) << "Promise not resolved before destruction."; |
| 39 } |
| 40 |
| 41 template <typename... T> |
| 42 void MojoCdmPromise<T...>::resolve(const T&... result) { |
| 43 mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New()); |
| 44 cdm_promise_result->success = true; |
| 45 callback_.Run(cdm_promise_result.Pass(), |
| 46 MojoTypeTrait<T>::MojoType::From(result)...); |
| 47 callback_.reset(); |
| 48 } |
| 49 |
| 50 template <typename... T> |
| 51 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception, |
| 52 uint32_t system_code, |
| 53 const std::string& error_message) { |
| 54 callback_.Run(GetRejectResult(exception, system_code, error_message), |
| 55 MojoTypeTrait<T>::DefaultValue()...); |
| 56 callback_.reset(); |
| 57 } |
| 58 |
| 59 template class MojoCdmPromise<>; |
| 60 template class MojoCdmPromise<std::string>; |
| 61 template class MojoCdmPromise<std::vector<std::vector<uint8_t>>>; |
| 62 |
| 63 } // namespace media |
| OLD | NEW |