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

Side by Side Diff: media/base/cdm_promise.cc

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more trybot issue Created 6 years, 6 months 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
« no previous file with comments | « media/base/cdm_promise.h ('k') | media/base/media_keys.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/base/cdm_promise.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9
10 namespace media {
11
12 CdmPromise::CdmPromise() : is_pending_(true) {
13 }
14
15 CdmPromise::CdmPromise(PromiseRejectedCB reject_cb)
16 : reject_cb_(reject_cb), is_pending_(true) {
17 DCHECK(!reject_cb_.is_null());
18 }
19
20 CdmPromise::~CdmPromise() {
21 DCHECK(!is_pending_);
22 }
23
24 void CdmPromise::reject(MediaKeys::Exception exception_code,
25 uint32 system_code,
26 const std::string& error_message) {
27 DCHECK(is_pending_);
28 is_pending_ = false;
29 reject_cb_.Run(exception_code, system_code, error_message);
30 }
31
32 template <typename T>
33 CdmPromiseTemplate<T>::CdmPromiseTemplate(
34 base::Callback<void(const T&)> resolve_cb,
35 PromiseRejectedCB reject_cb)
36 : CdmPromise(reject_cb), resolve_cb_(resolve_cb) {
37 DCHECK(!resolve_cb_.is_null());
38 }
39
40 template <typename T>
41 CdmPromiseTemplate<T>::~CdmPromiseTemplate() {
42 DCHECK(!is_pending_);
43 }
44
45 template <typename T>
46 void CdmPromiseTemplate<T>::resolve(const T& result) {
47 DCHECK(is_pending_);
48 is_pending_ = false;
49 resolve_cb_.Run(result);
50 }
51
52 CdmPromiseTemplate<void>::CdmPromiseTemplate(base::Callback<void()> resolve_cb,
53 PromiseRejectedCB reject_cb)
54 : CdmPromise(reject_cb), resolve_cb_(resolve_cb) {
55 DCHECK(!resolve_cb_.is_null());
56 }
57
58 CdmPromiseTemplate<void>::CdmPromiseTemplate() {
59 }
60
61 CdmPromiseTemplate<void>::~CdmPromiseTemplate() {
62 DCHECK(!is_pending_);
63 }
64
65 void CdmPromiseTemplate<void>::resolve() {
66 DCHECK(is_pending_);
67 is_pending_ = false;
68 resolve_cb_.Run();
69 }
70
71 // Explicit template instantiation for the Promises needed.
72 template class MEDIA_EXPORT CdmPromiseTemplate<std::string>;
73
74 } // namespace media
OLDNEW
« no previous file with comments | « media/base/cdm_promise.h ('k') | media/base/media_keys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698