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

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

Issue 651113002: Move CdmResultPromise to media/blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix template export issue. 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/media/cdm_result_promise.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "third_party/WebKit/public/platform/WebString.h"
10
11 namespace content {
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
30 static blink::WebContentDecryptionModuleException ConvertException(
31 media::MediaKeys::Exception exception_code) {
32 switch (exception_code) {
33 case media::MediaKeys::NOT_SUPPORTED_ERROR:
34 return blink::WebContentDecryptionModuleExceptionNotSupportedError;
35 case media::MediaKeys::INVALID_STATE_ERROR:
36 return blink::WebContentDecryptionModuleExceptionInvalidStateError;
37 case media::MediaKeys::INVALID_ACCESS_ERROR:
38 return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
39 case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
40 return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
41 case media::MediaKeys::UNKNOWN_ERROR:
42 return blink::WebContentDecryptionModuleExceptionUnknownError;
43 case media::MediaKeys::CLIENT_ERROR:
44 return blink::WebContentDecryptionModuleExceptionClientError;
45 case media::MediaKeys::OUTPUT_ERROR:
46 return blink::WebContentDecryptionModuleExceptionOutputError;
47 }
48 NOTREACHED();
49 return blink::WebContentDecryptionModuleExceptionUnknownError;
50 }
51
52 static ResultCodeForUMA ConvertExceptionToUMAResult(
53 media::MediaKeys::Exception exception_code) {
54 switch (exception_code) {
55 case media::MediaKeys::NOT_SUPPORTED_ERROR:
56 return NOT_SUPPORTED_ERROR;
57 case media::MediaKeys::INVALID_STATE_ERROR:
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;
72 }
73
74 static void ReportUMA(std::string uma_name, ResultCodeForUMA result) {
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(
90 const blink::WebContentDecryptionModuleResult& result,
91 const std::string& uma_name)
92 : web_cdm_result_(result), uma_name_(uma_name) {
93 }
94
95 template <typename... T>
96 CdmResultPromise<T...>::~CdmResultPromise() {
97 }
98
99 template <>
100 void CdmResultPromise<>::resolve() {
101 MarkPromiseSettled();
102 ReportUMA(uma_name_, SUCCESS);
103 web_cdm_result_.complete();
104 }
105
106 template <>
107 void CdmResultPromise<media::KeyIdsVector>::resolve(
108 const media::KeyIdsVector& result) {
109 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
110 // handle the set of keys.
111 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
112 }
113
114 template <typename... T>
115 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
116 uint32 system_code,
117 const std::string& error_message) {
118 MarkPromiseSettled();
119 ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
120 web_cdm_result_.completeWithError(ConvertException(exception_code),
121 system_code,
122 blink::WebString::fromUTF8(error_message));
123 }
124
125 NewSessionCdmResultPromise::NewSessionCdmResultPromise(
126 const blink::WebContentDecryptionModuleResult& result,
127 const std::string& uma_name,
128 const SessionInitializedCB& new_session_created_cb)
129 : web_cdm_result_(result),
130 uma_name_(uma_name),
131 new_session_created_cb_(new_session_created_cb) {
132 }
133
134 NewSessionCdmResultPromise::~NewSessionCdmResultPromise() {
135 }
136
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);
143 }
144
145 void NewSessionCdmResultPromise::reject(
146 media::MediaKeys::Exception exception_code,
147 uint32 system_code,
148 const std::string& error_message) {
149 MarkPromiseSettled();
150 ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
151 web_cdm_result_.completeWithError(ConvertException(exception_code),
152 system_code,
153 blink::WebString::fromUTF8(error_message));
154 }
155
156 // Explicit template instantiation for the templates needed.
157 template class CdmResultPromise<>;
158 template class CdmResultPromise<media::KeyIdsVector>;
jrummell 2014/10/16 00:20:16 Would doing this in cdm_result_promise_helper.cc h
xhwang 2014/10/16 04:25:43 I tried many ways of explicit instantiation but no
159
160 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698