Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / media / blink / cdm_result_promise.h
blobed4105c7365366a53d47fab02ab60e5f819394c1
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 virtual ~CdmResultPromise();
31 // CdmPromiseTemplate<T> implementation.
32 virtual void resolve(const T&... result) override;
33 virtual 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 <>
69 inline void CdmResultPromise<media::KeyIdsVector>::resolve(
70 const media::KeyIdsVector& result) {
71 // TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
72 // handle the set of keys.
73 reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
76 template <typename... T>
77 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
78 uint32 system_code,
79 const std::string& error_message) {
80 MarkPromiseSettled();
81 ReportCdmResultUMA(uma_name_,
82 ConvertCdmExceptionToResultForUMA(exception_code));
83 web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
84 system_code,
85 blink::WebString::fromUTF8(error_message));
88 } // namespace media
90 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_