Hook the WebThreadImplForMessageLoop up to post taks through the blink
[chromium-blink-merge.git] / media / blink / cdm_result_promise.h
blob6ae5778be2fb72f7a8c28e71fc094144e1f828ea
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"
14 namespace media {
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();
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;
36 private:
37 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled;
39 blink::WebContentDecryptionModuleResult web_cdm_result_;
41 // UMA name to report result to.
42 std::string uma_name_;
44 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
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) {
54 template <typename... T>
55 CdmResultPromise<T...>::~CdmResultPromise() {
58 // "inline" is needed to prevent multiple definition error.
60 template <>
61 inline void CdmResultPromise<>::resolve() {
62 MarkPromiseSettled();
63 ReportCdmResultUMA(uma_name_, SUCCESS);
64 web_cdm_result_.complete();
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.");
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));
87 } // namespace media
89 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_