Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: content/renderer/media/cdm_result_promise.cc

Issue 604283003: Refactor CdmPromise and related classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + override Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 namespace {
14
15 // A superset of media::MediaKeys::Exception for UMA reporting. These values
16 // should never be changed as it will affect existing reporting, and must match
17 // the values for CdmPromiseResult in tools/metrics/histograms/histograms.xml.
18 enum ResultCodeForUMA {
19 SUCCESS = 0,
20 NOT_SUPPORTED_ERROR = 1,
21 INVALID_STATE_ERROR = 2,
22 INVALID_ACCESS_ERROR = 3,
23 QUOTA_EXCEEDED_ERROR = 4,
24 UNKNOWN_ERROR = 5,
25 CLIENT_ERROR = 6,
26 OUTPUT_ERROR = 7,
27 NUM_RESULT_CODES
28 };
29
13 static blink::WebContentDecryptionModuleException ConvertException( 30 static blink::WebContentDecryptionModuleException ConvertException(
14 media::MediaKeys::Exception exception_code) { 31 media::MediaKeys::Exception exception_code) {
15 switch (exception_code) { 32 switch (exception_code) {
16 case media::MediaKeys::NOT_SUPPORTED_ERROR: 33 case media::MediaKeys::NOT_SUPPORTED_ERROR:
17 return blink::WebContentDecryptionModuleExceptionNotSupportedError; 34 return blink::WebContentDecryptionModuleExceptionNotSupportedError;
18 case media::MediaKeys::INVALID_STATE_ERROR: 35 case media::MediaKeys::INVALID_STATE_ERROR:
19 return blink::WebContentDecryptionModuleExceptionInvalidStateError; 36 return blink::WebContentDecryptionModuleExceptionInvalidStateError;
20 case media::MediaKeys::INVALID_ACCESS_ERROR: 37 case media::MediaKeys::INVALID_ACCESS_ERROR:
21 return blink::WebContentDecryptionModuleExceptionInvalidAccessError; 38 return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
22 case media::MediaKeys::QUOTA_EXCEEDED_ERROR: 39 case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
23 return blink::WebContentDecryptionModuleExceptionQuotaExceededError; 40 return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
24 case media::MediaKeys::UNKNOWN_ERROR: 41 case media::MediaKeys::UNKNOWN_ERROR:
25 return blink::WebContentDecryptionModuleExceptionUnknownError; 42 return blink::WebContentDecryptionModuleExceptionUnknownError;
26 case media::MediaKeys::CLIENT_ERROR: 43 case media::MediaKeys::CLIENT_ERROR:
27 return blink::WebContentDecryptionModuleExceptionClientError; 44 return blink::WebContentDecryptionModuleExceptionClientError;
28 case media::MediaKeys::OUTPUT_ERROR: 45 case media::MediaKeys::OUTPUT_ERROR:
29 return blink::WebContentDecryptionModuleExceptionOutputError; 46 return blink::WebContentDecryptionModuleExceptionOutputError;
30 default:
31 NOTREACHED();
32 return blink::WebContentDecryptionModuleExceptionUnknownError;
33 } 47 }
48 NOTREACHED();
49 return blink::WebContentDecryptionModuleExceptionUnknownError;
34 } 50 }
35 51
36 template <typename T> 52 static ResultCodeForUMA ConvertExceptionToUMAResult(
37 CdmResultPromise<T>::CdmResultPromise( 53 media::MediaKeys::Exception exception_code) {
38 const blink::WebContentDecryptionModuleResult& result) 54 switch (exception_code) {
39 : media::CdmPromiseTemplate<T>( 55 case media::MediaKeys::NOT_SUPPORTED_ERROR:
40 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), 56 return NOT_SUPPORTED_ERROR;
41 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))), 57 case media::MediaKeys::INVALID_STATE_ERROR:
42 web_cdm_result_(result) { 58 return INVALID_STATE_ERROR;
59 case media::MediaKeys::INVALID_ACCESS_ERROR:
60 return INVALID_ACCESS_ERROR;
61 case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
62 return QUOTA_EXCEEDED_ERROR;
63 case media::MediaKeys::UNKNOWN_ERROR:
64 return UNKNOWN_ERROR;
65 case media::MediaKeys::CLIENT_ERROR:
66 return CLIENT_ERROR;
67 case media::MediaKeys::OUTPUT_ERROR:
68 return OUTPUT_ERROR;
69 }
70 NOTREACHED();
71 return UNKNOWN_ERROR;
43 } 72 }
44 73
45 template <typename T> 74 static void ReportUMA(std::string uma_name, ResultCodeForUMA result) {
46 CdmResultPromise<T>::CdmResultPromise( 75 if (uma_name.empty())
76 return;
77
78 base::LinearHistogram::FactoryGet(
79 uma_name,
80 1,
81 NUM_RESULT_CODES,
82 NUM_RESULT_CODES + 1,
83 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result);
84 }
85
86 } // namespace
87
88 template <typename... T>
89 CdmResultPromise<T...>::CdmResultPromise(
47 const blink::WebContentDecryptionModuleResult& result, 90 const blink::WebContentDecryptionModuleResult& result,
48 const std::string& uma_name) 91 const std::string& uma_name)
49 : media::CdmPromiseTemplate<T>( 92 : web_cdm_result_(result), uma_name_(uma_name) {
50 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
51 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
52 uma_name),
53 web_cdm_result_(result) {
54 } 93 }
55 94
56 template <typename T> 95 template <typename... T>
57 CdmResultPromise<T>::~CdmResultPromise() { 96 CdmResultPromise<T...>::~CdmResultPromise() {
58 } 97 }
59 98
60 template <> 99 template <>
61 void CdmResultPromise<std::string>::OnResolve(const std::string& result) { 100 void CdmResultPromise<>::resolve() {
62 // This must be overridden in a subclass. 101 MarkPromiseSettled();
63 NOTREACHED(); 102 ReportUMA(uma_name_, SUCCESS);
103 web_cdm_result_.complete();
64 } 104 }
65 105
66 template <> 106 template <>
67 void CdmResultPromise<media::KeyIdsVector>::OnResolve( 107 void CdmResultPromise<media::KeyIdsVector>::resolve(
68 const media::KeyIdsVector& result) { 108 const media::KeyIdsVector& result) {
69 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to 109 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
70 // handle the set of keys. 110 // handle the set of keys.
71 OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented."); 111 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
72 } 112 }
73 113
74 template <typename T> 114 template <typename... T>
75 void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code, 115 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
76 uint32 system_code, 116 uint32 system_code,
77 const std::string& error_message) { 117 const std::string& error_message) {
118 MarkPromiseSettled();
119 ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
78 web_cdm_result_.completeWithError(ConvertException(exception_code), 120 web_cdm_result_.completeWithError(ConvertException(exception_code),
79 system_code, 121 system_code,
80 blink::WebString::fromUTF8(error_message)); 122 blink::WebString::fromUTF8(error_message));
81 } 123 }
82 124
83 CdmResultPromise<void>::CdmResultPromise( 125 NewSessionCdmResultPromise::NewSessionCdmResultPromise(
84 const blink::WebContentDecryptionModuleResult& result) 126 const blink::WebContentDecryptionModuleResult& result,
85 : media::CdmPromiseTemplate<void>( 127 const std::string& uma_name,
86 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)), 128 const SessionInitializedCB& new_session_created_cb)
87 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))), 129 : web_cdm_result_(result),
88 web_cdm_result_(result) { 130 uma_name_(uma_name),
131 new_session_created_cb_(new_session_created_cb) {
89 } 132 }
90 133
91 CdmResultPromise<void>::CdmResultPromise( 134 NewSessionCdmResultPromise::~NewSessionCdmResultPromise() {
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 } 135 }
100 136
101 CdmResultPromise<void>::~CdmResultPromise() { 137 void NewSessionCdmResultPromise::resolve(const std::string& web_session_id) {
138 MarkPromiseSettled();
139 ReportUMA(uma_name_, SUCCESS);
140 blink::WebContentDecryptionModuleResult::SessionStatus status =
141 new_session_created_cb_.Run(web_session_id);
142 web_cdm_result_.completeWithSession(status);
102 } 143 }
103 144
104 void CdmResultPromise<void>::OnResolve() { 145 void NewSessionCdmResultPromise::reject(
105 web_cdm_result_.complete();
106 }
107
108 void CdmResultPromise<void>::OnReject(
109 media::MediaKeys::Exception exception_code, 146 media::MediaKeys::Exception exception_code,
110 uint32 system_code, 147 uint32 system_code,
111 const std::string& error_message) { 148 const std::string& error_message) {
149 MarkPromiseSettled();
150 ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
112 web_cdm_result_.completeWithError(ConvertException(exception_code), 151 web_cdm_result_.completeWithError(ConvertException(exception_code),
113 system_code, 152 system_code,
114 blink::WebString::fromUTF8(error_message)); 153 blink::WebString::fromUTF8(error_message));
115 } 154 }
116 155
117 // Explicit template instantiation for the templates needed. 156 // Explicit template instantiation for the templates needed.
118 template class CdmResultPromise<std::string>; 157 template class CdmResultPromise<>;
119 template class CdmResultPromise<media::KeyIdsVector>; 158 template class CdmResultPromise<media::KeyIdsVector>;
120 159
121 } // namespace content 160 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/cdm_result_promise.h ('k') | content/renderer/media/crypto/ppapi_decryptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698