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 CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_
6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_
10 #include "base/basictypes.h"
11 #include "media/base/cdm_promise.h"
12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h"
16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromise so that
17 // it can be passed through Chromium. When CdmPromise::resolve(T) is called,
18 // OnResolve(T) will be called and will call the appropriate complete...()
19 // method on WebContentDecryptionModuleResult. If CdmPromise::reject() is called
20 // instead, WebContentDecryptionModuleResult::completeWithError() is called.
21 // If constructed with a |uma_name| (which must be the name of a
22 // CdmPromiseResult UMA), CdmResultPromise will report the promise result
23 // (success or rejection code).
25 class CdmResultPromise : public media::CdmPromiseTemplate<T> {
27 explicit CdmResultPromise(
28 const blink::WebContentDecryptionModuleResult& result);
29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
30 const std::string& uma_name);
31 virtual ~CdmResultPromise();
34 // OnResolve() is virtual as it may need special handling in derived classes.
35 virtual void OnResolve(const T& result);
36 void OnReject(media::MediaKeys::Exception exception_code,
38 const std::string& error_message);
40 blink::WebContentDecryptionModuleResult web_cdm_result_;
43 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
46 // Specialization for no parameter to resolve().
48 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> {
50 explicit CdmResultPromise(
51 const blink::WebContentDecryptionModuleResult& result);
52 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result,
53 const std::string& uma_name);
54 virtual ~CdmResultPromise();
57 virtual void OnResolve();
58 void OnReject(media::MediaKeys::Exception exception_code,
60 const std::string& error_message);
62 blink::WebContentDecryptionModuleResult web_cdm_result_;
65 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
68 typedef CdmResultPromise<void> SimpleCdmResultPromise;
70 } // namespace content
72 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_