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 static void GenerateUMA(std::string uma_name, ResultCodeForUMA result) { |
xhwang
2014/10/03 07:34:21
s/Generate/Report
jrummell
2014/10/03 18:58:29
Done.
| |
46 CdmResultPromise<T>::CdmResultPromise( | 58 if (uma_name.empty()) |
59 return; | |
60 | |
61 base::LinearHistogram::FactoryGet( | |
62 uma_name, | |
63 1, | |
64 NUM_RESULT_CODES, | |
65 NUM_RESULT_CODES + 1, | |
66 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result); | |
67 } | |
68 | |
69 template <typename... T> | |
70 CdmResultPromise<T...>::CdmResultPromise( | |
47 const blink::WebContentDecryptionModuleResult& result, | 71 const blink::WebContentDecryptionModuleResult& result, |
48 const std::string& uma_name) | 72 const std::string& uma_name) |
49 : media::CdmPromiseTemplate<T>( | 73 : media::CdmPromiseTemplate<T...>(), |
xhwang
2014/10/03 07:34:21
Is this necessary?
jrummell
2014/10/03 18:58:29
Doesn't look like it. Removed.
| |
50 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | 74 web_cdm_result_(result), |
51 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)), | 75 uma_name_(uma_name) { |
52 uma_name), | |
53 web_cdm_result_(result) { | |
54 } | 76 } |
55 | 77 |
56 template <typename T> | 78 template <typename... T> |
57 CdmResultPromise<T>::~CdmResultPromise() { | 79 CdmResultPromise<T...>::~CdmResultPromise() { |
80 } | |
81 | |
82 template <typename... T> | |
83 void CdmResultPromise<T...>::resolve(const T&... result) { | |
84 // As there are specializations for std::string and media::KeyIdsVector below, | |
85 // this should only be used for the 0 argument version. | |
xhwang
2014/10/03 07:34:21
In this case, change this to
template<>
void CdmR
jrummell
2014/10/03 18:58:29
Done.
| |
86 DCHECK(sizeof...(T) == 0); | |
xhwang
2014/10/03 07:34:21
DCHECK_EQ
jrummell
2014/10/03 18:58:29
Removed now that this is specific for CdmResultPro
| |
87 this->PromiseSettled(); | |
88 GenerateUMA(uma_name_, SUCCESS); | |
89 web_cdm_result_.complete(); | |
58 } | 90 } |
59 | 91 |
60 template <> | 92 template <> |
61 void CdmResultPromise<std::string>::OnResolve(const std::string& result) { | 93 void CdmResultPromise<std::string>::resolve(const std::string& result) { |
62 // This must be overridden in a subclass. | 94 // This must be overridden in a subclass. However, this method must be called |
63 NOTREACHED(); | 95 // from any overrides to mark the promise as settled and report to UMA. |
96 this->PromiseSettled(); | |
97 GenerateUMA(uma_name_, SUCCESS); | |
xhwang
2014/10/03 07:34:21
Comment why we don't call resolve here. It's hard
jrummell
2014/10/03 18:58:30
Done.
| |
64 } | 98 } |
65 | 99 |
66 template <> | 100 template <> |
67 void CdmResultPromise<media::KeyIdsVector>::OnResolve( | 101 void CdmResultPromise<media::KeyIdsVector>::resolve( |
68 const media::KeyIdsVector& result) { | 102 const media::KeyIdsVector& result) { |
69 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to | 103 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to |
70 // handle the set of keys. | 104 // handle the set of keys. |
71 OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented."); | 105 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented."); |
72 } | 106 } |
73 | 107 |
74 template <typename T> | 108 template <typename... T> |
75 void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code, | 109 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code, |
76 uint32 system_code, | 110 uint32 system_code, |
77 const std::string& error_message) { | 111 const std::string& error_message) { |
78 web_cdm_result_.completeWithError(ConvertException(exception_code), | 112 this->PromiseSettled(); |
79 system_code, | 113 GenerateUMA(uma_name_, ConvertExceptionToUMAResult(exception_code)); |
80 blink::WebString::fromUTF8(error_message)); | |
81 } | |
82 | |
83 CdmResultPromise<void>::CdmResultPromise( | |
84 const blink::WebContentDecryptionModuleResult& result) | |
85 : media::CdmPromiseTemplate<void>( | |
86 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | |
87 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))), | |
88 web_cdm_result_(result) { | |
89 } | |
90 | |
91 CdmResultPromise<void>::CdmResultPromise( | |
92 const blink::WebContentDecryptionModuleResult& result, | |
93 const std::string& uma_name) | |
94 : media::CdmPromiseTemplate<void>( | |
95 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), | |
96 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)), | |
97 uma_name), | |
98 web_cdm_result_(result) { | |
99 } | |
100 | |
101 CdmResultPromise<void>::~CdmResultPromise() { | |
102 } | |
103 | |
104 void CdmResultPromise<void>::OnResolve() { | |
105 web_cdm_result_.complete(); | |
106 } | |
107 | |
108 void CdmResultPromise<void>::OnReject( | |
109 media::MediaKeys::Exception exception_code, | |
110 uint32 system_code, | |
111 const std::string& error_message) { | |
112 web_cdm_result_.completeWithError(ConvertException(exception_code), | 114 web_cdm_result_.completeWithError(ConvertException(exception_code), |
113 system_code, | 115 system_code, |
114 blink::WebString::fromUTF8(error_message)); | 116 blink::WebString::fromUTF8(error_message)); |
115 } | 117 } |
116 | 118 |
117 // Explicit template instantiation for the templates needed. | 119 // Explicit template instantiation for the templates needed. |
120 template class CdmResultPromise<>; | |
118 template class CdmResultPromise<std::string>; | 121 template class CdmResultPromise<std::string>; |
119 template class CdmResultPromise<media::KeyIdsVector>; | 122 template class CdmResultPromise<media::KeyIdsVector>; |
120 | 123 |
121 } // namespace content | 124 } // namespace content |
OLD | NEW |