OLD | NEW |
---|---|
(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 typedef base::Callback<void(MediaKeys::MediaKeysException exception_code, | |
18 uint32 system_code, | |
19 const std::string& error_message)> | |
20 PromiseRejectedCB; | |
21 | |
22 // Interface for promises being resolved/rejected in response to various | |
23 // session actions. These may be called synchronously or asynchronously. | |
24 // Only one method may be called on any promise. It is expected that the | |
25 // caller free the promise once it is resolved/rejected. | |
26 template <typename T> | |
27 class MEDIA_EXPORT CdmPromise { | |
28 public: | |
29 CdmPromise(base::Callback<void(const T&)> resolve_cb, | |
30 PromiseRejectedCB rejected_cb); | |
31 virtual ~CdmPromise(); | |
32 | |
33 // Used to indicate that promise has successfully resolved. | |
ddorwin
2014/05/13 22:44:02
Be consistent with reject comment: i.e. operation
jrummell
2014/05/15 22:38:09
Done.
| |
34 virtual void resolve(const T& result); | |
35 | |
36 // Used to indicate that the operation failed. |exception_code| must be | |
37 // specified. |system_code| is a Key System-specific value for the error | |
38 // that occurred, or 0 if there is no associated status code or such status | |
39 // codes are not supported by the Key System. |error_message| is optional. | |
40 virtual void reject(MediaKeys::MediaKeysException exception_code, | |
41 uint32 system_code, | |
42 const std::string& error_message); | |
43 | |
44 private: | |
45 base::Callback<void(const T&)> resolve_cb_; | |
46 PromiseRejectedCB rejected_cb_; | |
47 bool is_pending_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | |
50 }; | |
51 | |
52 // Specialization for no parameter to resolve(). | |
53 template <> | |
54 class MEDIA_EXPORT CdmPromise<void> { | |
55 public: | |
56 CdmPromise(base::Callback<void()> resolve_cb, PromiseRejectedCB rejected_cb); | |
ddorwin
2014/05/13 22:44:02
Use base::Closure? Or maybe that's more confusing
jrummell
2014/05/15 22:38:09
Changed it to be more like the above call.
| |
57 virtual ~CdmPromise(); | |
58 virtual void resolve(); | |
59 virtual void reject(MediaKeys::MediaKeysException exception_code, | |
60 uint32 system_code, | |
61 const std::string& error_message); | |
62 | |
63 private: | |
64 base::Callback<void()> resolve_cb_; | |
65 PromiseRejectedCB rejected_cb_; | |
66 bool is_pending_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | |
69 }; | |
70 | |
71 } // namespace media | |
72 | |
73 #endif // MEDIA_BASE_CDM_PROMISE_H_ | |
OLD | NEW |