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

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: latest CDM_5 Created 6 years, 7 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
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/logging.h"
8
9 namespace media {
10
11 template <typename T>
12 CdmPromise<T>::CdmPromise(base::Callback<void(const T&)> resolve_cb,
13 PromiseRejectedCB rejected_cb)
14 : resolve_cb_(resolve_cb), rejected_cb_(rejected_cb), is_pending_(true) {
15 DCHECK(!resolve_cb_.is_null());
16 DCHECK(!rejected_cb_.is_null());
17 }
18
19 template <typename T>
20 CdmPromise<T>::~CdmPromise() {
21 DCHECK(!is_pending_);
22 }
23
24 template <typename T>
25 void CdmPromise<T>::resolve(const T& result) {
26 DCHECK(is_pending_);
27 is_pending_ = false;
28 resolve_cb_.Run(result);
29 }
30
31 template <typename T>
32 void CdmPromise<T>::reject(MediaKeys::MediaKeysException exception_code,
33 uint32 system_code,
34 const std::string& error_message) {
35 DCHECK(is_pending_);
36 is_pending_ = false;
37 rejected_cb_.Run(exception_code, system_code, error_message);
38 }
39
40 CdmPromise<void>::CdmPromise(base::Callback<void()> resolve_cb,
41 PromiseRejectedCB rejected_cb)
42 : resolve_cb_(resolve_cb), rejected_cb_(rejected_cb), is_pending_(true) {
43 }
44
45 CdmPromise<void>::~CdmPromise() {
46 DCHECK(!is_pending_);
47 }
48
49 void CdmPromise<void>::resolve() {
50 DCHECK(is_pending_);
51 is_pending_ = false;
52 resolve_cb_.Run();
53 }
54
55 void CdmPromise<void>::reject(MediaKeys::MediaKeysException exception_code,
56 uint32 system_code,
57 const std::string& error_message) {
58 DCHECK(is_pending_);
59 is_pending_ = false;
60 rejected_cb_.Run(exception_code, system_code, error_message);
61 }
62
63 // Explicit template instantiation for the Promises needed.
64 template class MEDIA_EXPORT CdmPromise<std::string>;
65 template class MEDIA_EXPORT CdmPromise<void>;
66
67 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698