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

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

Issue 2444683002: Move MediaKeys::Exception to CdmPromise::Exception (Closed)
Patch Set: remove third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h Created 4 years, 1 month 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_BASE_CDM_PROMISE_H_ 5 #ifndef MEDIA_BASE_CDM_PROMISE_H_
6 #define MEDIA_BASE_CDM_PROMISE_H_ 6 #define MEDIA_BASE_CDM_PROMISE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
15 #include "media/base/media_keys.h"
16 15
17 namespace media { 16 namespace media {
18 17
19 // Interface for promises being resolved/rejected in response to various 18 // Interface for promises being resolved/rejected in response to various
20 // session actions. These may be called synchronously or asynchronously. 19 // session actions. These may be called synchronously or asynchronously.
21 // The promise must be resolved or rejected exactly once. It is expected that 20 // The promise must be resolved or rejected exactly once. It is expected that
22 // the caller free the promise once it is resolved/rejected. 21 // the caller free the promise once it is resolved/rejected.
23 22
24 // These classes are almost generic, except for the parameters to reject(). If 23 // These classes are almost generic, except for the parameters to reject(). If
25 // a generic class for promises is available, this could be changed to use the 24 // a generic class for promises is available, this could be changed to use the
26 // generic class as long as the parameters to reject() can be set appropriately. 25 // generic class as long as the parameters to reject() can be set appropriately.
27 26
28 // The base class only has a reject() method and GetResolveParameterType() that 27 // The base class only has a reject() method and GetResolveParameterType() that
29 // indicates the type of CdmPromiseTemplate. CdmPromiseTemplate<T> adds the 28 // indicates the type of CdmPromiseTemplate. CdmPromiseTemplate<T> adds the
30 // resolve(T) method that is dependent on the type of promise. This base class 29 // resolve(T) method that is dependent on the type of promise. This base class
31 // is specified so that the promises can be easily saved before passing across 30 // is specified so that the promises can be easily saved before passing across
32 // the pepper interface. 31 // the pepper interface.
33 class MEDIA_EXPORT CdmPromise { 32 class MEDIA_EXPORT CdmPromise {
34 public: 33 public:
34 // TODO(jrummell): Remove deprecated errors. See
35 // http://crbug.com/570216
36 enum Exception {
37 NOT_SUPPORTED_ERROR,
38 INVALID_STATE_ERROR,
39 INVALID_ACCESS_ERROR,
40 QUOTA_EXCEEDED_ERROR,
41 UNKNOWN_ERROR,
42 CLIENT_ERROR,
43 OUTPUT_ERROR,
44 EXCEPTION_MAX = OUTPUT_ERROR
45 };
46
35 enum ResolveParameterType { 47 enum ResolveParameterType {
36 VOID_TYPE, 48 VOID_TYPE,
37 INT_TYPE, 49 INT_TYPE,
38 STRING_TYPE, 50 STRING_TYPE,
39 KEY_IDS_VECTOR_TYPE 51 KEY_IDS_VECTOR_TYPE
40 }; 52 };
41 53
42 CdmPromise(); 54 CdmPromise();
43 virtual ~CdmPromise(); 55 virtual ~CdmPromise();
44 56
45 // Used to indicate that the operation failed. |exception_code| must be 57 // Used to indicate that the operation failed. |exception_code| must be
46 // specified. |system_code| is a Key System-specific value for the error 58 // specified. |system_code| is a Key System-specific value for the error
47 // that occurred, or 0 if there is no associated status code or such status 59 // that occurred, or 0 if there is no associated status code or such status
48 // codes are not supported by the Key System. |error_message| is optional. 60 // codes are not supported by the Key System. |error_message| is optional.
49 virtual void reject(MediaKeys::Exception exception_code, 61 virtual void reject(CdmPromise::Exception exception_code,
xhwang 2016/10/26 00:13:04 nit: No need for "CdmPromise::" here.
50 uint32_t system_code, 62 uint32_t system_code,
51 const std::string& error_message) = 0; 63 const std::string& error_message) = 0;
52 64
53 // Used to determine the template type of CdmPromiseTemplate<T> so that 65 // Used to determine the template type of CdmPromiseTemplate<T> so that
54 // saved CdmPromise objects can be cast to the correct templated version. 66 // saved CdmPromise objects can be cast to the correct templated version.
55 virtual ResolveParameterType GetResolveParameterType() const = 0; 67 virtual ResolveParameterType GetResolveParameterType() const = 0;
56 68
57 private: 69 private:
58 DISALLOW_COPY_AND_ASSIGN(CdmPromise); 70 DISALLOW_COPY_AND_ASSIGN(CdmPromise);
59 }; 71 };
(...skipping 23 matching lines...) Expand all
83 template <typename... T> 95 template <typename... T>
84 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { 96 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise {
85 public: 97 public:
86 CdmPromiseTemplate() : is_settled_(false) {} 98 CdmPromiseTemplate() : is_settled_(false) {}
87 99
88 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); } 100 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); }
89 101
90 virtual void resolve(const T&... result) = 0; 102 virtual void resolve(const T&... result) = 0;
91 103
92 // CdmPromise implementation. 104 // CdmPromise implementation.
93 virtual void reject(MediaKeys::Exception exception_code, 105 virtual void reject(CdmPromise::Exception exception_code,
xhwang 2016/10/26 00:13:05 ditto
94 uint32_t system_code, 106 uint32_t system_code,
95 const std::string& error_message) = 0; 107 const std::string& error_message) = 0;
96 108
97 ResolveParameterType GetResolveParameterType() const override { 109 ResolveParameterType GetResolveParameterType() const override {
98 return CdmPromiseTraits<T...>::kType; 110 return CdmPromiseTraits<T...>::kType;
99 } 111 }
100 112
101 protected: 113 protected:
102 bool IsPromiseSettled() const { return is_settled_; } 114 bool IsPromiseSettled() const { return is_settled_; }
103 115
104 // All implementations must call this method in resolve() and reject() methods 116 // All implementations must call this method in resolve() and reject() methods
105 // to indicate that the promise has been settled. 117 // to indicate that the promise has been settled.
106 void MarkPromiseSettled() { 118 void MarkPromiseSettled() {
107 // Promise can only be settled once. 119 // Promise can only be settled once.
108 DCHECK(!is_settled_); 120 DCHECK(!is_settled_);
109 is_settled_ = true; 121 is_settled_ = true;
110 } 122 }
111 123
112 // Must be called by the concrete destructor if !IsPromiseSettled(). 124 // Must be called by the concrete destructor if !IsPromiseSettled().
113 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual. 125 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual.
114 void RejectPromiseOnDestruction() { 126 void RejectPromiseOnDestruction() {
115 DCHECK(!is_settled_); 127 DCHECK(!is_settled_);
116 std::string message = 128 std::string message =
117 "Unfulfilled promise rejected automatically during destruction."; 129 "Unfulfilled promise rejected automatically during destruction.";
118 DVLOG(1) << message; 130 DVLOG(1) << message;
119 reject(MediaKeys::INVALID_STATE_ERROR, 0, message); 131 reject(CdmPromise::INVALID_STATE_ERROR, 0, message);
xhwang 2016/10/26 00:13:04 ditto
120 DCHECK(is_settled_); 132 DCHECK(is_settled_);
121 } 133 }
122 134
123 private: 135 private:
124 // Keep track of whether the promise has been resolved or rejected yet. 136 // Keep track of whether the promise has been resolved or rejected yet.
125 bool is_settled_; 137 bool is_settled_;
126 138
127 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); 139 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
128 }; 140 };
129 141
130 } // namespace media 142 } // namespace media
131 143
132 #endif // MEDIA_BASE_CDM_PROMISE_H_ 144 #endif // MEDIA_BASE_CDM_PROMISE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698