Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / media / mojo / services / mojo_cdm_promise.cc
blob4f17f117ead6a1de2f7dd510d5f334972ee8d0f5
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 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();
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) {
43 MarkPromiseSettled();
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)...);
48 callback_.reset();
51 template <typename... T>
52 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception,
53 uint32_t system_code,
54 const std::string& error_message) {
55 MarkPromiseSettled();
56 callback_.Run(GetRejectResult(exception, system_code, error_message),
57 MojoTypeTrait<T>::DefaultValue()...);
58 callback_.reset();
61 template class MojoCdmPromise<>;
62 template class MojoCdmPromise<std::string>;
64 } // namespace media