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 CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 6 #define CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 7 8 #include <map> 9 10 #include "base/basictypes.h" 11 #include "media/base/cdm_promise.h" 12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" 13 14 namespace content { 15 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). 24 template <typename T> 25 class CdmResultPromise : public media::CdmPromiseTemplate<T> { 26 public: 27 explicit CdmResultPromise( 28 const blink::WebContentDecryptionModuleResult& result); 29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 30 const std::string& uma_name); 31 virtual ~CdmResultPromise(); 32 33 protected: 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, 37 uint32 system_code, 38 const std::string& error_message); 39 40 blink::WebContentDecryptionModuleResult web_cdm_result_; 41 42 private: 43 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 44 }; 45 46 // Specialization for no parameter to resolve(). 47 template <> 48 class CdmResultPromise<void> : public media::CdmPromiseTemplate<void> { 49 public: 50 explicit CdmResultPromise( 51 const blink::WebContentDecryptionModuleResult& result); 52 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, 53 const std::string& uma_name); 54 virtual ~CdmResultPromise(); 55 56 protected: 57 virtual void OnResolve(); 58 void OnReject(media::MediaKeys::Exception exception_code, 59 uint32 system_code, 60 const std::string& error_message); 61 62 blink::WebContentDecryptionModuleResult web_cdm_result_; 63 64 private: 65 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 66 }; 67 68 typedef CdmResultPromise<void> SimpleCdmResultPromise; 69 70 } // namespace content 71 72 #endif // CONTENT_RENDERER_MEDIA_CDM_RESULT_PROMISE_H_ 73