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

Side by Side Diff: media/blink/cdm_result_promise.h

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 #ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_H_
6 #define MEDIA_BLINK_CDM_RESULT_PROMISE_H_
7
8 #include "base/basictypes.h"
9 #include "media/base/cdm_promise.h"
10 #include "media/base/media_keys.h"
11 #include "media/blink/cdm_result_promise_helper.h"
12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
13
14 namespace media {
15
16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate
17 // so that it can be passed through Chromium. When resolve(T) is called, the
18 // appropriate complete...() method on WebContentDecryptionModuleResult will be
19 // invoked. If reject() is called instead,
20 // WebContentDecryptionModuleResult::completeWithError() is called.
21 // If constructed with a |uma_name|, CdmResultPromise will report the promise
22 // result (success or rejection code) to UMA.
23 template <typename... T>
24 class CdmResultPromise : public media::CdmPromiseTemplate<T...> {
25 public:
26 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
27 const std::string& uma_name);
28 virtual ~CdmResultPromise();
29
30 // CdmPromiseTemplate<T> implementation.
31 virtual void resolve(const T&... result) override;
32 virtual void reject(media::MediaKeys::Exception exception_code,
33 uint32 system_code,
34 const std::string& error_message) override;
35
36 private:
37 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled;
38
39 blink::WebContentDecryptionModuleResult web_cdm_result_;
40
41 // UMA name to report result to.
42 std::string uma_name_;
43
44 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
45 };
46
47 template <typename... T>
48 CdmResultPromise<T...>::CdmResultPromise(
49 const blink::WebContentDecryptionModuleResult& result,
50 const std::string& uma_name)
51 : web_cdm_result_(result), uma_name_(uma_name) {
52 }
53
54 template <typename... T>
55 CdmResultPromise<T...>::~CdmResultPromise() {
56 }
57
58 // "inline" is needed to prevent multiple definition error.
59
60 template <>
61 inline void CdmResultPromise<>::resolve() {
62 MarkPromiseSettled();
63 ReportCdmResultUMA(uma_name_, SUCCESS);
64 web_cdm_result_.complete();
65 }
66
67 template <>
68 inline void CdmResultPromise<media::KeyIdsVector>::resolve(
69 const media::KeyIdsVector& result) {
70 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
71 // handle the set of keys.
72 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
73 }
74
75 template <typename... T>
76 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
77 uint32 system_code,
78 const std::string& error_message) {
79 MarkPromiseSettled();
80 ReportCdmResultUMA(uma_name_,
81 ConvertCdmExceptionToResultForUMA(exception_code));
82 web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
83 system_code,
84 blink::WebString::fromUTF8(error_message));
85 }
86
87 } // namespace media
88
89 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698