Chromium Code Reviews| 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 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" | 
| 15 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" | 
| 
 
xhwang
2016/10/24 17:06:13
ditto about removing this include
 
 | |
| 16 | 16 | 
| 17 namespace media { | 17 namespace media { | 
| 18 | 18 | 
| 19 // Interface for promises being resolved/rejected in response to various | 19 // Interface for promises being resolved/rejected in response to various | 
| 20 // session actions. These may be called synchronously or asynchronously. | 20 // session actions. These may be called synchronously or asynchronously. | 
| 21 // 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 | 
| 22 // the caller free the promise once it is resolved/rejected. | 22 // the caller free the promise once it is resolved/rejected. | 
| 23 | 23 | 
| 24 // 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 | 
| 25 // a generic class for promises is available, this could be changed to use the | 25 // 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. | 26 // generic class as long as the parameters to reject() can be set appropriately. | 
| 27 | 27 | 
| 28 // The base class only has a reject() method and GetResolveParameterType() that | 28 // The base class only has a reject() method and GetResolveParameterType() that | 
| 29 // indicates the type of CdmPromiseTemplate. CdmPromiseTemplate<T> adds the | 29 // indicates the type of CdmPromiseTemplate. CdmPromiseTemplate<T> adds the | 
| 30 // resolve(T) method that is dependent on the type of promise. This base class | 30 // 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 | 31 // is specified so that the promises can be easily saved before passing across | 
| 32 // the pepper interface. | 32 // the pepper interface. | 
| 33 class MEDIA_EXPORT CdmPromise { | 33 class MEDIA_EXPORT CdmPromise { | 
| 34 public: | 34 public: | 
| 35 // TODO(xhwang): Remove after prefixed EME support is removed. See | |
| 36 // http://crbug.com/249976 | |
| 
 
xhwang
2016/10/24 17:34:23
Also, this comment is not accurate now. Could you
 
 | |
| 37 enum Exception { | |
| 38 NOT_SUPPORTED_ERROR, | |
| 39 INVALID_STATE_ERROR, | |
| 40 INVALID_ACCESS_ERROR, | |
| 41 QUOTA_EXCEEDED_ERROR, | |
| 42 UNKNOWN_ERROR, | |
| 43 CLIENT_ERROR, | |
| 44 OUTPUT_ERROR, | |
| 45 EXCEPTION_MAX = OUTPUT_ERROR | |
| 46 }; | |
| 47 | |
| 35 enum ResolveParameterType { | 48 enum ResolveParameterType { | 
| 36 VOID_TYPE, | 49 VOID_TYPE, | 
| 37 INT_TYPE, | 50 INT_TYPE, | 
| 38 STRING_TYPE, | 51 STRING_TYPE, | 
| 39 KEY_IDS_VECTOR_TYPE | 52 KEY_IDS_VECTOR_TYPE | 
| 40 }; | 53 }; | 
| 41 | 54 | 
| 42 CdmPromise(); | 55 CdmPromise(); | 
| 43 virtual ~CdmPromise(); | 56 virtual ~CdmPromise(); | 
| 44 | 57 | 
| 45 // Used to indicate that the operation failed. |exception_code| must be | 58 // Used to indicate that the operation failed. |exception_code| must be | 
| 46 // 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 | 
| 47 // 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 | 
| 48 // 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. | 
| 49 virtual void reject(MediaKeys::Exception exception_code, | 62 virtual void reject(CdmPromise::Exception exception_code, | 
| 50 uint32_t system_code, | 63 uint32_t system_code, | 
| 51 const std::string& error_message) = 0; | 64 const std::string& error_message) = 0; | 
| 52 | 65 | 
| 53 // Used to determine the template type of CdmPromiseTemplate<T> so that | 66 // Used to determine the template type of CdmPromiseTemplate<T> so that | 
| 54 // saved CdmPromise objects can be cast to the correct templated version. | 67 // saved CdmPromise objects can be cast to the correct templated version. | 
| 55 virtual ResolveParameterType GetResolveParameterType() const = 0; | 68 virtual ResolveParameterType GetResolveParameterType() const = 0; | 
| 56 | 69 | 
| 57 private: | 70 private: | 
| 58 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 71 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 
| 59 }; | 72 }; | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 83 template <typename... T> | 96 template <typename... T> | 
| 84 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { | 97 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { | 
| 85 public: | 98 public: | 
| 86 CdmPromiseTemplate() : is_settled_(false) {} | 99 CdmPromiseTemplate() : is_settled_(false) {} | 
| 87 | 100 | 
| 88 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); } | 101 virtual ~CdmPromiseTemplate() { DCHECK(is_settled_); } | 
| 89 | 102 | 
| 90 virtual void resolve(const T&... result) = 0; | 103 virtual void resolve(const T&... result) = 0; | 
| 91 | 104 | 
| 92 // CdmPromise implementation. | 105 // CdmPromise implementation. | 
| 93 virtual void reject(MediaKeys::Exception exception_code, | 106 virtual void reject(CdmPromise::Exception exception_code, | 
| 94 uint32_t system_code, | 107 uint32_t system_code, | 
| 95 const std::string& error_message) = 0; | 108 const std::string& error_message) = 0; | 
| 96 | 109 | 
| 97 ResolveParameterType GetResolveParameterType() const override { | 110 ResolveParameterType GetResolveParameterType() const override { | 
| 98 return CdmPromiseTraits<T...>::kType; | 111 return CdmPromiseTraits<T...>::kType; | 
| 99 } | 112 } | 
| 100 | 113 | 
| 101 protected: | 114 protected: | 
| 102 bool IsPromiseSettled() const { return is_settled_; } | 115 bool IsPromiseSettled() const { return is_settled_; } | 
| 103 | 116 | 
| 104 // All implementations must call this method in resolve() and reject() methods | 117 // All implementations must call this method in resolve() and reject() methods | 
| 105 // to indicate that the promise has been settled. | 118 // to indicate that the promise has been settled. | 
| 106 void MarkPromiseSettled() { | 119 void MarkPromiseSettled() { | 
| 107 // Promise can only be settled once. | 120 // Promise can only be settled once. | 
| 108 DCHECK(!is_settled_); | 121 DCHECK(!is_settled_); | 
| 109 is_settled_ = true; | 122 is_settled_ = true; | 
| 110 } | 123 } | 
| 111 | 124 | 
| 112 // Must be called by the concrete destructor if !IsPromiseSettled(). | 125 // Must be called by the concrete destructor if !IsPromiseSettled(). | 
| 113 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual. | 126 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual. | 
| 114 void RejectPromiseOnDestruction() { | 127 void RejectPromiseOnDestruction() { | 
| 115 DCHECK(!is_settled_); | 128 DCHECK(!is_settled_); | 
| 116 std::string message = | 129 std::string message = | 
| 117 "Unfulfilled promise rejected automatically during destruction."; | 130 "Unfulfilled promise rejected automatically during destruction."; | 
| 118 DVLOG(1) << message; | 131 DVLOG(1) << message; | 
| 119 reject(MediaKeys::INVALID_STATE_ERROR, 0, message); | 132 reject(CdmPromise::INVALID_STATE_ERROR, 0, message); | 
| 120 DCHECK(is_settled_); | 133 DCHECK(is_settled_); | 
| 121 } | 134 } | 
| 122 | 135 | 
| 123 private: | 136 private: | 
| 124 // Keep track of whether the promise has been resolved or rejected yet. | 137 // Keep track of whether the promise has been resolved or rejected yet. | 
| 125 bool is_settled_; | 138 bool is_settled_; | 
| 126 | 139 | 
| 127 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 140 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 
| 128 }; | 141 }; | 
| 129 | 142 | 
| 130 } // namespace media | 143 } // namespace media | 
| 131 | 144 | 
| 132 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 145 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 
| OLD | NEW |