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 #include "content/renderer/media/cdm_result_promise.h" | 5 #include "content/renderer/media/cdm_result_promise.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "third_party/WebKit/public/platform/WebString.h" | 9 #include "third_party/WebKit/public/platform/WebString.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 static blink::WebContentDecryptionModuleException ConvertException( | 13 static blink::WebContentDecryptionModuleException ConvertException( |
| 14 media::MediaKeys::Exception exception_code) { | 14 media::MediaKeys::Exception exception_code) { |
| 15 switch (exception_code) { | 15 switch (exception_code) { |
| 16 case media::MediaKeys::NOT_SUPPORTED_ERROR: | 16 case media::MediaKeys::NOT_SUPPORTED_ERROR: |
| 17 return blink::WebContentDecryptionModuleExceptionNotSupportedError; | 17 return blink::WebContentDecryptionModuleExceptionNotSupportedError; |
| 18 case media::MediaKeys::INVALID_STATE_ERROR: | 18 case media::MediaKeys::INVALID_STATE_ERROR: |
| 19 return blink::WebContentDecryptionModuleExceptionInvalidStateError; | 19 return blink::WebContentDecryptionModuleExceptionInvalidStateError; |
| 20 case media::MediaKeys::INVALID_ACCESS_ERROR: | 20 case media::MediaKeys::INVALID_ACCESS_ERROR: |
| 21 return blink::WebContentDecryptionModuleExceptionInvalidAccessError; | 21 return blink::WebContentDecryptionModuleExceptionInvalidAccessError; |
| 22 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: | 22 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: |
| 23 return blink::WebContentDecryptionModuleExceptionQuotaExceededError; | 23 return blink::WebContentDecryptionModuleExceptionQuotaExceededError; |
| 24 case media::MediaKeys::UNKNOWN_ERROR: | 24 case media::MediaKeys::UNKNOWN_ERROR: |
| 25 return blink::WebContentDecryptionModuleExceptionUnknownError; | 25 return blink::WebContentDecryptionModuleExceptionUnknownError; |
| 26 case media::MediaKeys::CLIENT_ERROR: | 26 case media::MediaKeys::CLIENT_ERROR: |
| 27 return blink::WebContentDecryptionModuleExceptionClientError; | 27 return blink::WebContentDecryptionModuleExceptionClientError; |
| 28 case media::MediaKeys::OUTPUT_ERROR: | 28 case media::MediaKeys::OUTPUT_ERROR: |
| 29 return blink::WebContentDecryptionModuleExceptionOutputError; | 29 return blink::WebContentDecryptionModuleExceptionOutputError; |
| 30 default: | |
| 31 NOTREACHED(); | |
| 32 return blink::WebContentDecryptionModuleExceptionUnknownError; | |
| 33 } | 30 } |
| 31 NOTREACHED(); | |
| 32 return blink::WebContentDecryptionModuleExceptionUnknownError; | |
| 34 } | 33 } |
| 35 | 34 |
| 36 template <typename T> | 35 static ResultCodeForUMA ConvertExceptionToUMAResult( |
| 37 CdmResultPromise<T>::CdmResultPromise( | 36 media::MediaKeys::Exception exception_code) { |
| 38 const blink::WebContentDecryptionModuleResult& result) | 37 switch (exception_code) { |
| 39 : media::CdmPromiseTemplate<T>( | 38 case media::MediaKeys::NOT_SUPPORTED_ERROR: |
| 40 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | 39 return NOT_SUPPORTED_ERROR; |
| 41 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))), | 40 case media::MediaKeys::INVALID_STATE_ERROR: |
| 42 web_cdm_result_(result) { | 41 return INVALID_STATE_ERROR; |
| 42 case media::MediaKeys::INVALID_ACCESS_ERROR: | |
| 43 return INVALID_ACCESS_ERROR; | |
| 44 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: | |
| 45 return QUOTA_EXCEEDED_ERROR; | |
| 46 case media::MediaKeys::UNKNOWN_ERROR: | |
| 47 return UNKNOWN_ERROR; | |
| 48 case media::MediaKeys::CLIENT_ERROR: | |
| 49 return CLIENT_ERROR; | |
| 50 case media::MediaKeys::OUTPUT_ERROR: | |
| 51 return OUTPUT_ERROR; | |
| 52 } | |
| 53 NOTREACHED(); | |
| 54 return UNKNOWN_ERROR; | |
| 43 } | 55 } |
| 44 | 56 |
| 45 template <typename T> | 57 template <typename T> |
| 46 CdmResultPromise<T>::CdmResultPromise( | 58 CdmResultPromise<T>::CdmResultPromise( |
| 47 const blink::WebContentDecryptionModuleResult& result, | 59 const blink::WebContentDecryptionModuleResult& result, |
| 48 const std::string& uma_name) | 60 const std::string& uma_name) |
| 49 : media::CdmPromiseTemplate<T>( | 61 : media::CdmPromiseTemplate<T>(), |
| 50 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | 62 web_cdm_result_(result), |
| 51 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)), | 63 uma_name_(uma_name), |
| 52 uma_name), | 64 is_pending_(true) { |
| 53 web_cdm_result_(result) { | |
| 54 } | 65 } |
| 55 | 66 |
| 56 template <typename T> | 67 template <typename T> |
| 57 CdmResultPromise<T>::~CdmResultPromise() { | 68 CdmResultPromise<T>::~CdmResultPromise() { |
| 69 DCHECK(!is_pending_); | |
| 58 } | 70 } |
| 59 | 71 |
| 60 template <> | 72 template <> |
| 61 void CdmResultPromise<std::string>::OnResolve(const std::string& result) { | 73 void CdmResultPromise<std::string>::resolve(const std::string& result) { |
| 62 // This must be overridden in a subclass. | 74 // This must be overridden in a subclass. |
| 63 NOTREACHED(); | 75 NOTREACHED(); |
| 64 } | 76 } |
| 65 | 77 |
| 66 template <> | 78 template <> |
| 67 void CdmResultPromise<media::KeyIdsVector>::OnResolve( | 79 void CdmResultPromise<media::KeyIdsVector>::resolve( |
| 68 const media::KeyIdsVector& result) { | 80 const media::KeyIdsVector& result) { |
| 69 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to | 81 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to |
| 70 // handle the set of keys. | 82 // handle the set of keys. |
| 71 OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented."); | 83 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented."); |
| 72 } | 84 } |
| 73 | 85 |
| 74 template <typename T> | 86 template <typename T> |
| 75 void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code, | 87 void CdmResultPromise<T>::reject(media::MediaKeys::Exception exception_code, |
| 76 uint32 system_code, | 88 uint32 system_code, |
| 77 const std::string& error_message) { | 89 const std::string& error_message) { |
| 90 ReportResultToUMA(ConvertExceptionToUMAResult(exception_code)); | |
| 78 web_cdm_result_.completeWithError(ConvertException(exception_code), | 91 web_cdm_result_.completeWithError(ConvertException(exception_code), |
| 79 system_code, | 92 system_code, |
| 80 blink::WebString::fromUTF8(error_message)); | 93 blink::WebString::fromUTF8(error_message)); |
| 81 } | 94 } |
| 82 | 95 |
| 83 CdmResultPromise<void>::CdmResultPromise( | 96 template <typename T> |
| 84 const blink::WebContentDecryptionModuleResult& result) | 97 void CdmResultPromise<T>::ReportResultToUMA(ResultCodeForUMA result) { |
| 85 : media::CdmPromiseTemplate<void>( | 98 DCHECK(is_pending_); |
| 86 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | 99 is_pending_ = false; |
| 87 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))), | 100 if (!uma_name_.empty()) { |
|
xhwang
2014/09/29 18:32:58
Return early:
if (uma_name_.empty())
return;
/
jrummell
2014/09/29 22:08:38
Done.
| |
| 88 web_cdm_result_(result) { | 101 base::LinearHistogram::FactoryGet( |
|
ddorwin
2014/09/26 22:40:00
Can we make this a local function that takes a nam
jrummell
2014/09/29 22:08:38
Done.
| |
| 102 uma_name_, | |
| 103 1, | |
| 104 NUM_RESULT_CODES, | |
| 105 NUM_RESULT_CODES + 1, | |
| 106 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result); | |
| 107 } | |
| 89 } | 108 } |
| 90 | 109 |
| 91 CdmResultPromise<void>::CdmResultPromise( | 110 CdmResultPromise<void>::CdmResultPromise( |
| 92 const blink::WebContentDecryptionModuleResult& result, | 111 const blink::WebContentDecryptionModuleResult& result, |
| 93 const std::string& uma_name) | 112 const std::string& uma_name) |
| 94 : media::CdmPromiseTemplate<void>( | 113 : media::CdmPromiseTemplate<void>(), |
| 95 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | 114 web_cdm_result_(result), |
| 96 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)), | 115 uma_name_(uma_name), |
| 97 uma_name), | 116 is_pending_(true) { |
| 98 web_cdm_result_(result) { | |
| 99 } | 117 } |
| 100 | 118 |
| 101 CdmResultPromise<void>::~CdmResultPromise() { | 119 CdmResultPromise<void>::~CdmResultPromise() { |
| 120 DCHECK(!is_pending_); | |
| 102 } | 121 } |
| 103 | 122 |
| 104 void CdmResultPromise<void>::OnResolve() { | 123 void CdmResultPromise<void>::resolve() { |
| 124 ReportResultToUMA(SUCCESS); | |
| 105 web_cdm_result_.complete(); | 125 web_cdm_result_.complete(); |
| 106 } | 126 } |
| 107 | 127 |
| 108 void CdmResultPromise<void>::OnReject( | 128 void CdmResultPromise<void>::reject(media::MediaKeys::Exception exception_code, |
| 109 media::MediaKeys::Exception exception_code, | 129 uint32 system_code, |
| 110 uint32 system_code, | 130 const std::string& error_message) { |
| 111 const std::string& error_message) { | 131 ReportResultToUMA(ConvertExceptionToUMAResult(exception_code)); |
| 112 web_cdm_result_.completeWithError(ConvertException(exception_code), | 132 web_cdm_result_.completeWithError(ConvertException(exception_code), |
| 113 system_code, | 133 system_code, |
| 114 blink::WebString::fromUTF8(error_message)); | 134 blink::WebString::fromUTF8(error_message)); |
| 115 } | 135 } |
| 116 | 136 |
| 137 void CdmResultPromise<void>::ReportResultToUMA(ResultCodeForUMA result) { | |
| 138 DCHECK(is_pending_); | |
| 139 is_pending_ = false; | |
| 140 if (!uma_name_.empty()) { | |
|
xhwang
2014/09/29 18:32:58
ditto
jrummell
2014/09/29 22:08:38
Gone.
| |
| 141 base::LinearHistogram::FactoryGet( | |
| 142 uma_name_, | |
| 143 1, | |
| 144 NUM_RESULT_CODES, | |
| 145 NUM_RESULT_CODES + 1, | |
| 146 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result); | |
| 147 } | |
| 148 } | |
| 149 | |
| 117 // Explicit template instantiation for the templates needed. | 150 // Explicit template instantiation for the templates needed. |
| 118 template class CdmResultPromise<std::string>; | 151 template class CdmResultPromise<std::string>; |
| 119 template class CdmResultPromise<media::KeyIdsVector>; | 152 template class CdmResultPromise<media::KeyIdsVector>; |
| 120 | 153 |
| 121 } // namespace content | 154 } // namespace content |
| OLD | NEW |