Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: media/mojo/services/mojo_cdm_promise.cc

Issue 763883006: Add Mojo CDM Service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more comments. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/bind.h"
8 #include "base/logging.h"
9 #include "media/base/decryptor.h"
10
11 namespace media {
12
13 static mojo::CdmPromiseResultPtr GetRejectResult(
14 MediaKeys::Exception exception_code,
15 uint32 system_code,
16 const std::string& error_message) {
17 mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New());
18 cdm_promise_result->success = false;
19 cdm_promise_result->exception_code =
20 static_cast<mojo::CdmException>(exception_code);
21 cdm_promise_result->system_code = system_code;
22 cdm_promise_result->error_message = error_message;
23 return cdm_promise_result.Pass();
24 }
25
26 SimpleMojoCdmPromise::SimpleMojoCdmPromise(
27 const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback)
28 : callback_(callback) {
29 DCHECK(!callback_.is_null());
30 }
31
32 SimpleMojoCdmPromise::~SimpleMojoCdmPromise() {
33 if (!callback_.is_null())
34 DVLOG(1) << "Promise not resolved before destruction.";
35 }
36
37 void SimpleMojoCdmPromise::resolve() {
38 mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New());
39 cdm_promise_result->success = true;
40 callback_.Run(cdm_promise_result.Pass());
41 callback_.reset();
42 }
43
44 void SimpleMojoCdmPromise::reject(MediaKeys::Exception exception_code,
45 uint32 system_code,
46 const std::string& error_message) {
47 callback_.Run(GetRejectResult(exception_code, system_code, error_message));
48 callback_.reset();
49 }
50
51 template <typename Type, typename MojoType>
52 MojoCdmPromise<Type, MojoType>::MojoCdmPromise(
53 const mojo::Callback<void(mojo::CdmPromiseResultPtr, MojoType)>& callback)
54 : callback_(callback) {
55 DCHECK(!callback_.is_null());
56 }
57
58 template <typename Type, typename MojoType>
59 MojoCdmPromise<Type, MojoType>::~MojoCdmPromise() {
60 if (!callback_.is_null())
61 DVLOG(1) << "Promise not resolved before destruction.";
62 }
63
64 template <typename Type, typename MojoType>
65 void MojoCdmPromise<Type, MojoType>::resolve(const Type& arg) {
66 mojo::CdmPromiseResultPtr cdm_promise_result(mojo::CdmPromiseResult::New());
67 cdm_promise_result->success = true;
68 callback_.Run(cdm_promise_result.Pass(), MojoType::From(arg));
69 callback_.reset();
70 }
71
72 template <typename Type, typename MojoType>
73 void MojoCdmPromise<Type, MojoType>::reject(MediaKeys::Exception exception_code,
74 uint32 system_code,
75 const std::string& error_message) {
76 callback_.Run(GetRejectResult(exception_code, system_code, error_message),
77 MojoType());
78 callback_.reset();
79 }
80
81 template class MojoCdmPromise<std::string, mojo::String>;
82 template class MojoCdmPromise<std::vector<std::vector<uint8_t>>,
83 mojo::Array<mojo::Array<uint8_t>>>;
84
85 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698