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

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

Issue 265993002: Add Promises for EME (Chromium side) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments + fewer error codes 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
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 #ifndef MEDIA_BASE_CDM_PROMISE_H_
6 #define MEDIA_BASE_CDM_PROMISE_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "media/base/media_export.h"
13 #include "media/base/media_keys.h"
14
15 namespace media {
16
17 // Interface for promises being resolved/rejected in response to various
18 // session actions. These may be called synchronously or asynchronously.
19 // The promise must be resolved or rejected exactly once. It is expected that
20 // the caller free the promise once it is resolved/rejected.
21 //
22 // This is only the base class, as parameter to resolve() varies.
23 class MEDIA_EXPORT CdmPromise {
24 public:
25 typedef base::Callback<void(MediaKeys::Exception exception_code,
26 uint32 system_code,
27 const std::string& error_message)>
28 PromiseRejectedCB;
29
30 virtual ~CdmPromise();
31
32 // Used to indicate that the operation failed. |exception_code| must be
33 // specified. |system_code| is a Key System-specific value for the error
34 // that occurred, or 0 if there is no associated status code or such status
35 // codes are not supported by the Key System. |error_message| is optional.
36 virtual void reject(MediaKeys::Exception exception_code,
37 uint32 system_code,
38 const std::string& error_message);
39
40 protected:
41 CdmPromise(PromiseRejectedCB reject_cb);
42
43 PromiseRejectedCB reject_cb_;
44
45 // Keep track of whether the promise hasn't been resolved or rejected yet.
46 bool is_pending_;
47
48 DISALLOW_COPY_AND_ASSIGN(CdmPromise);
49 };
50
51 template <typename T>
52 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise {
53 public:
54 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb,
55 PromiseRejectedCB rejected_cb);
56 virtual ~CdmPromiseTemplate();
57 virtual void resolve(const T& result);
58
59 private:
60 base::Callback<void(const T&)> resolve_cb_;
61
62 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
63 };
64
65 // Specialization for no parameter to resolve().
66 template <>
67 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise {
68 public:
69 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb,
70 PromiseRejectedCB rejected_cb);
71 virtual ~CdmPromiseTemplate();
72 virtual void resolve();
73
74 private:
75 base::Callback<void(void)> resolve_cb_;
76
77 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
78 };
79
80 } // namespace media
81
82 #endif // MEDIA_BASE_CDM_PROMISE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698