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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 virtual ~CdmPromise(); | 49 virtual ~CdmPromise(); |
| 50 | 50 |
| 51 // Used to indicate that the operation failed. |exception_code| must be | 51 // Used to indicate that the operation failed. |exception_code| must be |
| 52 // specified. |system_code| is a Key System-specific value for the error | 52 // specified. |system_code| is a Key System-specific value for the error |
| 53 // that occurred, or 0 if there is no associated status code or such status | 53 // that occurred, or 0 if there is no associated status code or such status |
| 54 // codes are not supported by the Key System. |error_message| is optional. | 54 // codes are not supported by the Key System. |error_message| is optional. |
| 55 virtual void reject(MediaKeys::Exception exception_code, | 55 virtual void reject(MediaKeys::Exception exception_code, |
| 56 uint32 system_code, | 56 uint32 system_code, |
| 57 const std::string& error_message); | 57 const std::string& error_message); |
| 58 | 58 |
| 59 virtual ResolveParameterType GetResolveParameterType() const = 0; | 59 ResolveParameterType GetResolveParameterType() const { |
| 60 return parameter_type_; | |
| 61 } | |
| 60 | 62 |
| 61 protected: | 63 protected: |
| 62 CdmPromise(); | 64 explicit CdmPromise(ResolveParameterType parameter_type); |
| 63 CdmPromise(PromiseRejectedCB reject_cb); | 65 CdmPromise(ResolveParameterType parameter_type, PromiseRejectedCB reject_cb); |
|
xhwang
2014/09/22 20:55:31
In another CL, pass callbacks by const-ref?
jrummell
2014/09/22 23:57:32
Acknowledged.
| |
| 64 | 66 |
| 65 // If constructed with a |uma_name| (which must be the name of a | 67 // If constructed with a |uma_name| (which must be the name of a |
| 66 // CdmPromiseResult UMA), CdmPromise will report the promise result (success | 68 // CdmPromiseResult UMA), CdmPromise will report the promise result (success |
| 67 // or rejection code). | 69 // or rejection code). |
| 68 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name); | 70 CdmPromise(ResolveParameterType parameter_type, |
| 71 PromiseRejectedCB reject_cb, | |
| 72 const std::string& uma_name); | |
| 69 | 73 |
| 74 // Called by all resolve()/reject() methods to report the UMA result if | |
| 75 // applicable, and update |is_pending_|. | |
| 76 void ReportResultToUMA(ResultCodeForUMA result); | |
| 77 | |
| 78 const ResolveParameterType parameter_type_; | |
| 70 PromiseRejectedCB reject_cb_; | 79 PromiseRejectedCB reject_cb_; |
| 71 | 80 |
| 72 // Keep track of whether the promise hasn't been resolved or rejected yet. | 81 // Keep track of whether the promise hasn't been resolved or rejected yet. |
| 73 bool is_pending_; | 82 bool is_pending_; |
| 74 | 83 |
| 75 // UMA to report result to. | 84 // UMA name to report result to. |
| 76 std::string uma_name_; | 85 std::string uma_name_; |
| 77 | 86 |
| 78 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 87 DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
| 79 }; | 88 }; |
| 80 | 89 |
| 90 template <typename T> | |
| 91 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { | |
| 92 public: | |
| 93 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, | |
| 94 PromiseRejectedCB rejected_cb); | |
|
xhwang
2014/09/22 20:55:31
ditto: pass both callbacks in const-ref?
jrummell
2014/09/22 23:57:32
Acknowledged.
| |
| 95 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, | |
| 96 PromiseRejectedCB rejected_cb, | |
| 97 const std::string& uma_name); | |
| 98 virtual void resolve(const T& result); | |
| 99 | |
| 100 protected: | |
| 101 // Allow subclasses to completely override the implementation. | |
| 102 CdmPromiseTemplate(); | |
| 103 | |
| 104 private: | |
| 105 base::Callback<void(const T&)> resolve_cb_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | |
| 108 }; | |
| 109 | |
| 81 // Specialization for no parameter to resolve(). | 110 // Specialization for no parameter to resolve(). |
| 82 template <> | 111 template <> |
| 83 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { | 112 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { |
| 84 public: | 113 public: |
| 85 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | 114 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, |
| 86 PromiseRejectedCB rejected_cb); | 115 PromiseRejectedCB rejected_cb); |
| 87 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | 116 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, |
| 88 PromiseRejectedCB rejected_cb, | 117 PromiseRejectedCB rejected_cb, |
| 89 const std::string& uma_name); | 118 const std::string& uma_name); |
| 90 virtual ~CdmPromiseTemplate(); | |
| 91 virtual void resolve(); | 119 virtual void resolve(); |
| 92 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; | |
| 93 | 120 |
| 94 protected: | 121 protected: |
| 95 // Allow subclasses to completely override the implementation. | 122 // Allow subclasses to completely override the implementation. |
| 96 CdmPromiseTemplate(); | 123 CdmPromiseTemplate(); |
| 97 | 124 |
| 98 private: | 125 private: |
| 99 base::Callback<void(void)> resolve_cb_; | 126 base::Callback<void(void)> resolve_cb_; |
| 100 | 127 |
| 101 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 128 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
| 102 }; | 129 }; |
| 103 | |
| 104 template <> | |
| 105 class MEDIA_EXPORT CdmPromiseTemplate<std::string> : public CdmPromise { | |
| 106 public: | |
| 107 CdmPromiseTemplate(base::Callback<void(const std::string&)> resolve_cb, | |
| 108 PromiseRejectedCB rejected_cb); | |
| 109 CdmPromiseTemplate(base::Callback<void(const std::string&)> resolve_cb, | |
| 110 PromiseRejectedCB rejected_cb, | |
| 111 const std::string& uma_name); | |
| 112 virtual ~CdmPromiseTemplate(); | |
| 113 virtual void resolve(const std::string& result); | |
| 114 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; | |
| 115 | |
| 116 protected: | |
| 117 // Allow subclasses to completely override the implementation. | |
| 118 // TODO(jrummell): Remove when derived class SessionLoadedPromise | |
| 119 // (in ppapi_decryptor.cc) is no longer needed. | |
| 120 CdmPromiseTemplate(); | |
| 121 | |
| 122 private: | |
| 123 base::Callback<void(const std::string&)> resolve_cb_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | |
| 126 }; | |
| 127 | |
| 128 template <> | |
| 129 class MEDIA_EXPORT CdmPromiseTemplate<KeyIdsVector> : public CdmPromise { | |
| 130 public: | |
| 131 CdmPromiseTemplate(base::Callback<void(const KeyIdsVector&)> resolve_cb, | |
| 132 PromiseRejectedCB rejected_cb); | |
| 133 CdmPromiseTemplate(base::Callback<void(const KeyIdsVector&)> resolve_cb, | |
| 134 PromiseRejectedCB rejected_cb, | |
| 135 const std::string& uma_name); | |
| 136 virtual ~CdmPromiseTemplate(); | |
| 137 virtual void resolve(const KeyIdsVector& result); | |
| 138 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; | |
| 139 | |
| 140 private: | |
| 141 base::Callback<void(const KeyIdsVector&)> resolve_cb_; | |
| 142 | |
| 143 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | |
| 144 }; | |
| 145 | 130 |
| 146 } // namespace media | 131 } // namespace media |
| 147 | 132 |
| 148 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 133 #endif // MEDIA_BASE_CDM_PROMISE_H_ |
| OLD | NEW |