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

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

Issue 555223004: Update MediaKeys interface for EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename 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/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 CdmResultPromise<T>::CdmResultPromise(
38 blink::WebContentDecryptionModuleResult result)
39 : media::CdmPromiseTemplate<T>(
40 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
41 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
xhwang 2014/09/25 05:11:46 This patten is a bit tricky. Might worth some docu
jrummell 2014/09/25 20:33:24 Discussed offline. Will be cleaned up in a future
42 webCDMResult_(result) {
43 }
44
45 template <typename T>
46 CdmResultPromise<T>::CdmResultPromise(
47 blink::WebContentDecryptionModuleResult result,
48 const std::string& uma_name)
49 : media::CdmPromiseTemplate<T>(
50 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
51 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
52 uma_name),
53 webCDMResult_(result) {
54 }
xhwang 2014/09/25 05:11:46 Is it possible to only keep the version with uma_n
jrummell 2014/09/25 20:33:24 CdmPromise() does a DCHECK on uma_name if specifie
55
56 template <>
57 void CdmResultPromise<std::string>::OnResolve(const std::string& result) {
58 // This must be overridden in a subclass.
59 NOTIMPLEMENTED();
xhwang 2014/09/25 05:11:46 NOTREACHED
jrummell 2014/09/25 20:33:24 Done.
60 }
61
62 template <>
63 void CdmResultPromise<media::KeyIdsVector>::OnResolve(
64 const media::KeyIdsVector& result) {
65 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
66 // handle the set of keys.
67 OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
68 }
69
70 template <typename T>
71 void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code,
72 uint32 system_code,
73 const std::string& error_message) {
74 webCDMResult_.completeWithError(ConvertException(exception_code),
75 system_code,
76 blink::WebString::fromUTF8(error_message));
77 }
78
79 CdmResultPromise<void>::CdmResultPromise(
80 blink::WebContentDecryptionModuleResult result)
81 : media::CdmPromiseTemplate<void>(
82 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
83 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
84 webCDMResult_(result) {
85 }
86
87 CdmResultPromise<void>::CdmResultPromise(
88 blink::WebContentDecryptionModuleResult result,
89 const std::string& uma_name)
90 : media::CdmPromiseTemplate<void>(
91 base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
92 base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
93 uma_name),
94 webCDMResult_(result) {
95 }
96
97 void CdmResultPromise<void>::OnResolve() {
98 webCDMResult_.complete();
99 }
100
101 void CdmResultPromise<void>::OnReject(
102 media::MediaKeys::Exception exception_code,
103 uint32 system_code,
104 const std::string& error_message) {
105 webCDMResult_.completeWithError(ConvertException(exception_code),
106 system_code,
107 blink::WebString::fromUTF8(error_message));
108 }
109
110 // Explicit template instantiation for the templates needed.
111 template class CdmResultPromise<std::string>;
ddorwin 2014/09/25 00:07:15 ditto - and this might allow us to avoid anyone ac
ddorwin 2014/09/25 00:16:38 Nevermind, that doesn't work with the implementati
112 template class CdmResultPromise<media::KeyIdsVector>;
ddorwin 2014/09/25 00:07:15 ditto
ddorwin 2014/09/25 00:16:38 Nevermind.
113
114 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698