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

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

Issue 555223004: Update MediaKeys interface for EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: BlinkCdmPromiseTemplate 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/webcontentdecryptionmoduleresult_helper.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "third_party/WebKit/public/platform/WebString.h"
10
11 namespace content {
12
13 static blink::WebContentDecryptionModuleException ConvertException(
14 media::MediaKeys::Exception exception_code) {
15 switch (exception_code) {
16 case media::MediaKeys::NOT_SUPPORTED_ERROR:
17 return blink::WebContentDecryptionModuleExceptionNotSupportedError;
18 case media::MediaKeys::INVALID_STATE_ERROR:
19 return blink::WebContentDecryptionModuleExceptionInvalidStateError;
20 case media::MediaKeys::INVALID_ACCESS_ERROR:
21 return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
22 case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
23 return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
24 case media::MediaKeys::UNKNOWN_ERROR:
25 return blink::WebContentDecryptionModuleExceptionUnknownError;
26 case media::MediaKeys::CLIENT_ERROR:
27 return blink::WebContentDecryptionModuleExceptionClientError;
28 case media::MediaKeys::OUTPUT_ERROR:
29 return blink::WebContentDecryptionModuleExceptionOutputError;
30 default:
31 NOTREACHED();
32 return blink::WebContentDecryptionModuleExceptionUnknownError;
33 }
34 }
35
36 template <typename T>
37 BlinkCdmPromiseTemplate<T>::BlinkCdmPromiseTemplate(
38 blink::WebContentDecryptionModuleResult result)
39 : media::CdmPromiseTemplate<T>(
40 base::Bind(&BlinkCdmPromiseTemplate::OnResolve,
41 base::Unretained(this)),
42 base::Bind(&BlinkCdmPromiseTemplate::OnReject,
43 base::Unretained(this))),
44 webCDMResult_(result) {
45 }
46
47 template <typename T>
48 BlinkCdmPromiseTemplate<T>::BlinkCdmPromiseTemplate(
49 blink::WebContentDecryptionModuleResult result,
50 const std::string& uma_name)
51 : media::CdmPromiseTemplate<T>(
52 base::Bind(&BlinkCdmPromiseTemplate::OnResolve,
53 base::Unretained(this)),
54 base::Bind(&BlinkCdmPromiseTemplate::OnReject,
55 base::Unretained(this)),
56 uma_name),
57 webCDMResult_(result) {
58 }
59
60 template <>
61 void BlinkCdmPromiseTemplate<std::string>::OnResolve(
62 const std::string& result) {
63 // This must be overridden in a subclass.
ddorwin 2014/09/23 23:14:21 Will it link if you leave this out? Actually, how
jrummell 2014/09/24 00:49:32 Linking fails if I leave it out. Testing with the
64 NOTIMPLEMENTED();
65 }
66
67 template <>
68 void BlinkCdmPromiseTemplate<media::KeyIdsVector>::OnResolve(
69 const media::KeyIdsVector& result) {
70 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
71 // handle the set of keys.
72 webCDMResult_.completeWithError(
ddorwin 2014/09/23 23:14:21 nit: This is a bit simpler if you just call OnReje
jrummell 2014/09/24 00:49:32 Fits on one line now.
73 blink::WebContentDecryptionModuleExceptionNotSupportedError,
74 0,
75 "Not implemented.");
76 }
77
78 template <typename T>
79 void BlinkCdmPromiseTemplate<T>::OnReject(
80 media::MediaKeys::Exception exception_code,
81 uint32 system_code,
82 const std::string& error_message) {
83 webCDMResult_.completeWithError(ConvertException(exception_code),
84 system_code,
85 blink::WebString::fromUTF8(error_message));
86 }
87
88 BlinkCdmPromiseTemplate<void>::BlinkCdmPromiseTemplate(
89 blink::WebContentDecryptionModuleResult result)
90 : media::CdmPromiseTemplate<void>(
91 base::Bind(&BlinkCdmPromiseTemplate::OnResolve,
92 base::Unretained(this)),
93 base::Bind(&BlinkCdmPromiseTemplate::OnReject,
94 base::Unretained(this))),
95 webCDMResult_(result) {
96 }
97
98 BlinkCdmPromiseTemplate<void>::BlinkCdmPromiseTemplate(
99 blink::WebContentDecryptionModuleResult result,
100 const std::string& uma_name)
101 : media::CdmPromiseTemplate<void>(
102 base::Bind(&BlinkCdmPromiseTemplate::OnResolve,
103 base::Unretained(this)),
104 base::Bind(&BlinkCdmPromiseTemplate::OnReject,
105 base::Unretained(this)),
106 uma_name),
107 webCDMResult_(result) {
108 }
109
110 void BlinkCdmPromiseTemplate<void>::OnResolve() {
111 webCDMResult_.complete();
112 }
113
114 void BlinkCdmPromiseTemplate<void>::OnReject(
115 media::MediaKeys::Exception exception_code,
116 uint32 system_code,
117 const std::string& error_message) {
118 webCDMResult_.completeWithError(ConvertException(exception_code),
119 system_code,
120 blink::WebString::fromUTF8(error_message));
121 }
122
123 // Explicit template instantiation for the templates needed.
124 template class BlinkCdmPromiseTemplate<std::string>;
125 template class BlinkCdmPromiseTemplate<media::KeyIdsVector>;
126
127 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698