Fix the Android Mandoline ui build.
[chromium-blink-merge.git] / media / blink / cdm_result_promise.h
blob57313df3ebe62f3fa1dc1e9317f9229c8644baad
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.
5 #ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_H_
6 #define MEDIA_BLINK_CDM_RESULT_PROMISE_H_
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 #include "third_party/WebKit/public/platform/WebString.h"
15 namespace media {
17 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate
18 // so that it can be passed through Chromium. When resolve(T) is called, the
19 // appropriate complete...() method on WebContentDecryptionModuleResult will be
20 // invoked. If reject() is called instead,
21 // WebContentDecryptionModuleResult::completeWithError() is called.
22 // If constructed with a |uma_name|, CdmResultPromise will report the promise
23 // result (success or rejection code) to UMA.
24 template <typename... T>
25 class CdmResultPromise : public media::CdmPromiseTemplate<T...> {
26 public:
27 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
28 const std::string& uma_name);
29 ~CdmResultPromise() override;
31 // CdmPromiseTemplate<T> implementation.
32 void resolve(const T&... result) override;
33 void reject(media::MediaKeys::Exception exception_code,
34 uint32 system_code,
35 const std::string& error_message) override;
37 private:
38 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled;
40 blink::WebContentDecryptionModuleResult web_cdm_result_;
42 // UMA name to report result to.
43 std::string uma_name_;
45 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
48 template <typename... T>
49 CdmResultPromise<T...>::CdmResultPromise(
50 const blink::WebContentDecryptionModuleResult& result,
51 const std::string& uma_name)
52 : web_cdm_result_(result), uma_name_(uma_name) {
55 template <typename... T>
56 CdmResultPromise<T...>::~CdmResultPromise() {
59 // "inline" is needed to prevent multiple definition error.
61 template <>
62 inline void CdmResultPromise<>::resolve() {
63 MarkPromiseSettled();
64 ReportCdmResultUMA(uma_name_, SUCCESS);
65 web_cdm_result_.complete();
68 template <typename... T>
69 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
70 uint32 system_code,
71 const std::string& error_message) {
72 MarkPromiseSettled();
73 ReportCdmResultUMA(uma_name_,
74 ConvertCdmExceptionToResultForUMA(exception_code));
75 web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
76 system_code,
77 blink::WebString::fromUTF8(error_message));
80 } // namespace media
82 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_