OLD | NEW |
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 // TODO(xhwang): Remove this include after http://crbug.com/656706 is fixed. | 14 #include "media/base/cdm_key_information.h" |
15 #include "media/base/content_decryption_module.h" | |
16 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
17 | 16 |
18 namespace media { | 17 namespace media { |
19 | 18 |
20 // Interface for promises being resolved/rejected in response to various | 19 // Interface for promises being resolved/rejected in response to various |
21 // session actions. These may be called synchronously or asynchronously. | 20 // session actions. These may be called synchronously or asynchronously. |
22 // The promise must be resolved or rejected exactly once. It is expected that | 21 // The promise must be resolved or rejected exactly once. It is expected that |
23 // the caller free the promise once it is resolved/rejected. | 22 // the caller free the promise once it is resolved/rejected. |
24 | 23 |
25 // These classes are almost generic, except for the parameters to reject(). If | 24 // These classes are almost generic, except for the parameters to reject(). If |
(...skipping 20 matching lines...) Expand all Loading... |
46 EXCEPTION_MAX = OUTPUT_ERROR | 45 EXCEPTION_MAX = OUTPUT_ERROR |
47 }; | 46 }; |
48 | 47 |
49 enum ResolveParameterType { | 48 enum ResolveParameterType { |
50 VOID_TYPE, | 49 VOID_TYPE, |
51 INT_TYPE, | 50 INT_TYPE, |
52 STRING_TYPE, | 51 STRING_TYPE, |
53 KEY_STATUS_TYPE | 52 KEY_STATUS_TYPE |
54 }; | 53 }; |
55 | 54 |
56 CdmPromise(); | 55 CdmPromise() = default; |
57 virtual ~CdmPromise(); | 56 virtual ~CdmPromise() = default; |
58 | 57 |
59 // Used to indicate that the operation failed. |exception_code| must be | 58 // Used to indicate that the operation failed. |exception_code| must be |
60 // specified. |system_code| is a Key System-specific value for the error | 59 // specified. |system_code| is a Key System-specific value for the error |
61 // that occurred, or 0 if there is no associated status code or such status | 60 // that occurred, or 0 if there is no associated status code or such status |
62 // codes are not supported by the Key System. |error_message| is optional. | 61 // codes are not supported by the Key System. |error_message| is optional. |
63 virtual void reject(Exception exception_code, | 62 virtual void reject(Exception exception_code, |
64 uint32_t system_code, | 63 uint32_t system_code, |
65 const std::string& error_message) = 0; | 64 const std::string& error_message) = 0; |
66 | 65 |
67 // Used to determine the template type of CdmPromiseTemplate<T> so that | 66 // Used to determine the template type of CdmPromiseTemplate<T> so that |
68 // saved CdmPromise objects can be cast to the correct templated version. | 67 // saved CdmPromise objects can be cast to the correct templated version. |
69 virtual ResolveParameterType GetResolveParameterType() const = 0; | 68 virtual ResolveParameterType GetResolveParameterType() const = 0; |
70 | 69 |
71 private: | 70 private: |
72 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 71 DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
73 }; | 72 }; |
74 | 73 |
75 // For some reason the Windows compiler is not happy with the implementation | |
76 // of CdmPromiseTemplate being in the .cc file, so moving it here. | |
77 template <typename... T> | 74 template <typename... T> |
78 struct CdmPromiseTraits {}; | 75 struct CdmPromiseTraits {}; |
79 | 76 |
80 template <> | 77 template <> |
81 struct CdmPromiseTraits<> { | 78 struct MEDIA_EXPORT CdmPromiseTraits<> { |
82 static const CdmPromise::ResolveParameterType kType = CdmPromise::VOID_TYPE; | 79 static const CdmPromise::ResolveParameterType kType; |
83 }; | 80 }; |
84 | 81 |
85 template <> | 82 template <> |
86 struct CdmPromiseTraits<int> { | 83 struct MEDIA_EXPORT CdmPromiseTraits<int> { |
87 static const CdmPromise::ResolveParameterType kType = CdmPromise::INT_TYPE; | 84 static const CdmPromise::ResolveParameterType kType; |
88 }; | 85 }; |
89 | 86 |
90 template <> | 87 template <> |
91 struct CdmPromiseTraits<std::string> { | 88 struct MEDIA_EXPORT CdmPromiseTraits<std::string> { |
92 static const CdmPromise::ResolveParameterType kType = CdmPromise::STRING_TYPE; | 89 static const CdmPromise::ResolveParameterType kType; |
93 }; | 90 }; |
94 | 91 |
95 template <> | 92 template <> |
96 struct CdmPromiseTraits<CdmKeyInformation::KeyStatus> { | 93 struct MEDIA_EXPORT CdmPromiseTraits<CdmKeyInformation::KeyStatus> { |
97 static const CdmPromise::ResolveParameterType kType = | 94 static const CdmPromise::ResolveParameterType kType; |
98 CdmPromise::KEY_STATUS_TYPE; | |
99 }; | 95 }; |
100 | 96 |
101 // This class adds the resolve(T) method. This class is still an interface, and | 97 // This class adds the resolve(T) method. This class is still an interface, and |
102 // is used as the type of promise that gets passed around. | 98 // is used as the type of promise that gets passed around. |
103 template <typename... T> | 99 template <typename... T> |
104 class CdmPromiseTemplate : public CdmPromise { | 100 class CdmPromiseTemplate : public CdmPromise { |
105 public: | 101 public: |
106 CdmPromiseTemplate() : is_settled_(false) {} | 102 CdmPromiseTemplate() : is_settled_(false) {} |
107 | 103 |
108 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); } | 104 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); } |
109 | 105 |
110 virtual void resolve(const T&... result) = 0; | 106 virtual void resolve(const T&... result) = 0; |
111 | 107 |
112 // CdmPromise implementation. | 108 // CdmPromise implementation. |
113 virtual void reject(Exception exception_code, | 109 virtual void reject(Exception exception_code, |
114 uint32_t system_code, | 110 uint32_t system_code, |
115 const std::string& error_message) = 0; | 111 const std::string& error_message) = 0; |
116 | 112 |
117 ResolveParameterType GetResolveParameterType() const override { | 113 ResolveParameterType GetResolveParameterType() const final; |
118 return CdmPromiseTraits<T...>::kType; | |
119 } | |
120 | 114 |
121 protected: | 115 protected: |
122 bool IsPromiseSettled() const { return is_settled_; } | 116 bool IsPromiseSettled() const { return is_settled_; } |
123 | 117 |
124 // All implementations must call this method in resolve() and reject() methods | 118 // All implementations must call this method in resolve() and reject() methods |
125 // to indicate that the promise has been settled. | 119 // to indicate that the promise has been settled. |
126 void MarkPromiseSettled() { | 120 void MarkPromiseSettled() { |
127 // Promise can only be settled once. | 121 // Promise can only be settled once. |
128 DCHECK(!is_settled_); | 122 DCHECK(!is_settled_); |
129 is_settled_ = true; | 123 is_settled_ = true; |
(...skipping 10 matching lines...) Expand all Loading... |
140 DCHECK(is_settled_); | 134 DCHECK(is_settled_); |
141 } | 135 } |
142 | 136 |
143 private: | 137 private: |
144 // Keep track of whether the promise has been resolved or rejected yet. | 138 // Keep track of whether the promise has been resolved or rejected yet. |
145 bool is_settled_; | 139 bool is_settled_; |
146 | 140 |
147 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 141 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
148 }; | 142 }; |
149 | 143 |
| 144 // Explicitly defining all variants of GetResolveParameterType(). |
| 145 // Without this component builds on Windows fail due to versions of the same |
| 146 // method being generated in multiple DLLs. |
| 147 template <> |
| 148 MEDIA_EXPORT CdmPromise::ResolveParameterType |
| 149 CdmPromiseTemplate<>::GetResolveParameterType() const; |
| 150 |
| 151 template <> |
| 152 MEDIA_EXPORT CdmPromise::ResolveParameterType |
| 153 CdmPromiseTemplate<int>::GetResolveParameterType() const; |
| 154 |
| 155 template <> |
| 156 MEDIA_EXPORT CdmPromise::ResolveParameterType |
| 157 CdmPromiseTemplate<std::string>::GetResolveParameterType() const; |
| 158 |
| 159 template <> |
| 160 MEDIA_EXPORT CdmPromise::ResolveParameterType CdmPromiseTemplate< |
| 161 CdmKeyInformation::KeyStatus>::GetResolveParameterType() const; |
| 162 |
150 } // namespace media | 163 } // namespace media |
151 | 164 |
152 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 165 #endif // MEDIA_BASE_CDM_PROMISE_H_ |
OLD | NEW |