Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_H_ | 5 #ifndef MEDIA_BLINK_CDM_RESULT_PROMISE_H_ |
| 6 #define MEDIA_BLINK_CDM_RESULT_PROMISE_H_ | 6 #define MEDIA_BLINK_CDM_RESULT_PROMISE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "media/base/cdm_promise.h" | 11 #include "media/base/cdm_promise.h" |
| 12 #include "media/base/media_keys.h" | 12 #include "media/base/media_keys.h" |
|
xhwang
2016/10/24 17:06:13
ditto
| |
| 13 #include "media/blink/cdm_result_promise_helper.h" | 13 #include "media/blink/cdm_result_promise_helper.h" |
| 14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate | 19 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate |
| 20 // so that it can be passed through Chromium. When resolve(T) is called, the | 20 // so that it can be passed through Chromium. When resolve(T) is called, the |
| 21 // appropriate complete...() method on WebContentDecryptionModuleResult will be | 21 // appropriate complete...() method on WebContentDecryptionModuleResult will be |
| 22 // invoked. If reject() is called instead, | 22 // invoked. If reject() is called instead, |
| 23 // WebContentDecryptionModuleResult::completeWithError() is called. | 23 // WebContentDecryptionModuleResult::completeWithError() is called. |
| 24 // If constructed with a |uma_name|, CdmResultPromise will report the promise | 24 // If constructed with a |uma_name|, CdmResultPromise will report the promise |
| 25 // result (success or rejection code) to UMA. | 25 // result (success or rejection code) to UMA. |
| 26 template <typename... T> | 26 template <typename... T> |
| 27 class CdmResultPromise : public CdmPromiseTemplate<T...> { | 27 class CdmResultPromise : public CdmPromiseTemplate<T...> { |
| 28 public: | 28 public: |
| 29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, | 29 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, |
| 30 const std::string& uma_name); | 30 const std::string& uma_name); |
| 31 ~CdmResultPromise() override; | 31 ~CdmResultPromise() override; |
| 32 | 32 |
| 33 // CdmPromiseTemplate<T> implementation. | 33 // CdmPromiseTemplate<T> implementation. |
| 34 void resolve(const T&... result) override; | 34 void resolve(const T&... result) override; |
| 35 void reject(MediaKeys::Exception exception_code, | 35 void reject(CdmPromise::Exception exception_code, |
| 36 uint32_t system_code, | 36 uint32_t system_code, |
| 37 const std::string& error_message) override; | 37 const std::string& error_message) override; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 using CdmPromiseTemplate<T...>::IsPromiseSettled; | 40 using CdmPromiseTemplate<T...>::IsPromiseSettled; |
| 41 using CdmPromiseTemplate<T...>::MarkPromiseSettled; | 41 using CdmPromiseTemplate<T...>::MarkPromiseSettled; |
| 42 using CdmPromiseTemplate<T...>::RejectPromiseOnDestruction; | 42 using CdmPromiseTemplate<T...>::RejectPromiseOnDestruction; |
| 43 | 43 |
| 44 blink::WebContentDecryptionModuleResult web_cdm_result_; | 44 blink::WebContentDecryptionModuleResult web_cdm_result_; |
| 45 | 45 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 65 // "inline" is needed to prevent multiple definition error. | 65 // "inline" is needed to prevent multiple definition error. |
| 66 | 66 |
| 67 template <> | 67 template <> |
| 68 inline void CdmResultPromise<>::resolve() { | 68 inline void CdmResultPromise<>::resolve() { |
| 69 MarkPromiseSettled(); | 69 MarkPromiseSettled(); |
| 70 ReportCdmResultUMA(uma_name_, SUCCESS); | 70 ReportCdmResultUMA(uma_name_, SUCCESS); |
| 71 web_cdm_result_.complete(); | 71 web_cdm_result_.complete(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 template <typename... T> | 74 template <typename... T> |
| 75 void CdmResultPromise<T...>::reject(MediaKeys::Exception exception_code, | 75 void CdmResultPromise<T...>::reject(CdmPromise::Exception exception_code, |
| 76 uint32_t system_code, | 76 uint32_t system_code, |
| 77 const std::string& error_message) { | 77 const std::string& error_message) { |
| 78 MarkPromiseSettled(); | 78 MarkPromiseSettled(); |
| 79 ReportCdmResultUMA(uma_name_, | 79 ReportCdmResultUMA(uma_name_, |
| 80 ConvertCdmExceptionToResultForUMA(exception_code)); | 80 ConvertCdmExceptionToResultForUMA(exception_code)); |
| 81 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), | 81 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), |
| 82 system_code, | 82 system_code, |
| 83 blink::WebString::fromUTF8(error_message)); | 83 blink::WebString::fromUTF8(error_message)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace media | 86 } // namespace media |
| 87 | 87 |
| 88 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_ | 88 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_ |
| OLD | NEW |