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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 CdmPromise(); | 62 CdmPromise(); |
| 63 CdmPromise(PromiseRejectedCB reject_cb); | 63 CdmPromise(PromiseRejectedCB reject_cb); |
| 64 | 64 |
| 65 // If constructed with a |uma_name| (which must be the name of a | 65 // If constructed with a |uma_name| (which must be the name of a |
| 66 // CdmPromiseResult UMA), CdmPromise will report the promise result (success | 66 // CdmPromiseResult UMA), CdmPromise will report the promise result (success |
| 67 // or rejection code). | 67 // or rejection code). |
| 68 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name); | 68 CdmPromise(PromiseRejectedCB reject_cb, const std::string& uma_name); |
| 69 | 69 |
| 70 // Called by all resolve() methods to do the check on |is_pending_| | |
|
ddorwin
2014/09/19 20:56:46
... to report UMA, if applicable, and update |is_p
jrummell
2014/09/22 19:21:10
Done.
| |
| 71 // and call the UMA success if required. | |
| 72 void ReportResolution(); | |
|
ddorwin
2014/09/19 20:56:46
nit: "Resolution" has many meanings. How about Rep
xhwang
2014/09/20 00:34:50
ReportXxxToUMA() to be explicit?
jrummell
2014/09/22 19:21:10
Done.
jrummell
2014/09/22 19:21:10
Done.
| |
| 73 | |
| 70 PromiseRejectedCB reject_cb_; | 74 PromiseRejectedCB reject_cb_; |
| 71 | 75 |
| 72 // Keep track of whether the promise hasn't been resolved or rejected yet. | 76 // Keep track of whether the promise hasn't been resolved or rejected yet. |
| 73 bool is_pending_; | 77 bool is_pending_; |
| 74 | 78 |
| 75 // UMA to report result to. | 79 // UMA to report result to. |
|
xhwang
2014/09/20 00:34:50
s/UMA/UMA name/
Can you give an example here? Som
jrummell
2014/09/22 19:21:10
Comment changed. As for an example, the names are
| |
| 76 std::string uma_name_; | 80 std::string uma_name_; |
| 77 | 81 |
| 78 DISALLOW_COPY_AND_ASSIGN(CdmPromise); | 82 DISALLOW_COPY_AND_ASSIGN(CdmPromise); |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 // Specialization for no parameter to resolve(). | 85 template <typename T> |
| 82 template <> | 86 class MEDIA_EXPORT CdmPromiseTemplate : public CdmPromise { |
| 83 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { | |
| 84 public: | 87 public: |
| 85 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | 88 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, |
| 86 PromiseRejectedCB rejected_cb); | 89 PromiseRejectedCB rejected_cb); |
| 87 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | 90 CdmPromiseTemplate(base::Callback<void(const T&)> resolve_cb, |
| 88 PromiseRejectedCB rejected_cb, | 91 PromiseRejectedCB rejected_cb, |
| 89 const std::string& uma_name); | 92 const std::string& uma_name); |
| 90 virtual ~CdmPromiseTemplate(); | 93 virtual ~CdmPromiseTemplate(); |
| 91 virtual void resolve(); | 94 virtual void resolve(const T& result); |
| 92 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; | 95 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; |
|
ddorwin
2014/09/19 20:56:46
Rather than overriding this, can we make the base
jrummell
2014/09/22 19:21:10
Done.
| |
| 93 | 96 |
| 94 protected: | 97 protected: |
| 95 // Allow subclasses to completely override the implementation. | 98 // Allow subclasses to completely override the implementation. |
|
ddorwin
2014/09/19 20:56:46
Is this still appropriate? I don't think it was us
jrummell
2014/09/22 19:21:10
It is used by SessionUpdatedPromise and SessionLoa
ddorwin
2014/09/22 20:46:30
Maybe a TODO to consider removing these in October
jrummell
2014/09/22 23:57:32
I'll wait until the new overrides are implemented.
| |
| 96 CdmPromiseTemplate(); | 99 CdmPromiseTemplate(); |
| 97 | 100 |
| 98 private: | 101 private: |
| 102 base::Callback<void(const T&)> resolve_cb_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | |
| 105 }; | |
| 106 | |
| 107 // Specialization for no parameter to resolve(). | |
| 108 template <> | |
| 109 class MEDIA_EXPORT CdmPromiseTemplate<void> : public CdmPromise { | |
| 110 public: | |
| 111 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | |
| 112 PromiseRejectedCB rejected_cb); | |
| 113 CdmPromiseTemplate(base::Callback<void(void)> resolve_cb, | |
| 114 PromiseRejectedCB rejected_cb, | |
| 115 const std::string& uma_name); | |
| 116 virtual ~CdmPromiseTemplate(); | |
| 117 virtual void resolve(); | |
| 118 virtual ResolveParameterType GetResolveParameterType() const OVERRIDE; | |
| 119 | |
| 120 protected: | |
| 121 // Allow subclasses to completely override the implementation. | |
| 122 CdmPromiseTemplate(); | |
| 123 | |
| 124 private: | |
| 99 base::Callback<void(void)> resolve_cb_; | 125 base::Callback<void(void)> resolve_cb_; |
| 100 | 126 |
| 101 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); | 127 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); |
| 102 }; | 128 }; |
| 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 | 129 |
| 146 } // namespace media | 130 } // namespace media |
| 147 | 131 |
| 148 #endif // MEDIA_BASE_CDM_PROMISE_H_ | 132 #endif // MEDIA_BASE_CDM_PROMISE_H_ |
| OLD | NEW |