| 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 "base/basictypes.h" | |
| 9 #include "media/base/cdm_promise.h" | 8 #include "media/base/cdm_promise.h" |
| 10 #include "media/base/media_keys.h" | 9 #include "media/base/media_keys.h" |
| 11 #include "media/blink/cdm_result_promise_helper.h" | 10 #include "media/blink/cdm_result_promise_helper.h" |
| 12 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 11 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 12 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate | 16 // Used to convert a WebContentDecryptionModuleResult into a CdmPromiseTemplate |
| 18 // so that it can be passed through Chromium. When resolve(T) is called, the | 17 // so that it can be passed through Chromium. When resolve(T) is called, the |
| 19 // appropriate complete...() method on WebContentDecryptionModuleResult will be | 18 // appropriate complete...() method on WebContentDecryptionModuleResult will be |
| 20 // invoked. If reject() is called instead, | 19 // invoked. If reject() is called instead, |
| 21 // WebContentDecryptionModuleResult::completeWithError() is called. | 20 // WebContentDecryptionModuleResult::completeWithError() is called. |
| 22 // If constructed with a |uma_name|, CdmResultPromise will report the promise | 21 // If constructed with a |uma_name|, CdmResultPromise will report the promise |
| 23 // result (success or rejection code) to UMA. | 22 // result (success or rejection code) to UMA. |
| 24 template <typename... T> | 23 template <typename... T> |
| 25 class CdmResultPromise : public media::CdmPromiseTemplate<T...> { | 24 class CdmResultPromise : public media::CdmPromiseTemplate<T...> { |
| 26 public: | 25 public: |
| 27 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, | 26 CdmResultPromise(const blink::WebContentDecryptionModuleResult& result, |
| 28 const std::string& uma_name); | 27 const std::string& uma_name); |
| 29 ~CdmResultPromise() override; | 28 ~CdmResultPromise() override; |
| 30 | 29 |
| 31 // CdmPromiseTemplate<T> implementation. | 30 // CdmPromiseTemplate<T> implementation. |
| 32 void resolve(const T&... result) override; | 31 void resolve(const T&... result) override; |
| 33 void reject(media::MediaKeys::Exception exception_code, | 32 void reject(media::MediaKeys::Exception exception_code, |
| 34 uint32 system_code, | 33 uint32_t system_code, |
| 35 const std::string& error_message) override; | 34 const std::string& error_message) override; |
| 36 | 35 |
| 37 private: | 36 private: |
| 38 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled; | 37 using media::CdmPromiseTemplate<T...>::MarkPromiseSettled; |
| 39 | 38 |
| 40 blink::WebContentDecryptionModuleResult web_cdm_result_; | 39 blink::WebContentDecryptionModuleResult web_cdm_result_; |
| 41 | 40 |
| 42 // UMA name to report result to. | 41 // UMA name to report result to. |
| 43 std::string uma_name_; | 42 std::string uma_name_; |
| 44 | 43 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 | 59 |
| 61 template <> | 60 template <> |
| 62 inline void CdmResultPromise<>::resolve() { | 61 inline void CdmResultPromise<>::resolve() { |
| 63 MarkPromiseSettled(); | 62 MarkPromiseSettled(); |
| 64 ReportCdmResultUMA(uma_name_, SUCCESS); | 63 ReportCdmResultUMA(uma_name_, SUCCESS); |
| 65 web_cdm_result_.complete(); | 64 web_cdm_result_.complete(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 template <typename... T> | 67 template <typename... T> |
| 69 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code, | 68 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code, |
| 70 uint32 system_code, | 69 uint32_t system_code, |
| 71 const std::string& error_message) { | 70 const std::string& error_message) { |
| 72 MarkPromiseSettled(); | 71 MarkPromiseSettled(); |
| 73 ReportCdmResultUMA(uma_name_, | 72 ReportCdmResultUMA(uma_name_, |
| 74 ConvertCdmExceptionToResultForUMA(exception_code)); | 73 ConvertCdmExceptionToResultForUMA(exception_code)); |
| 75 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), | 74 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), |
| 76 system_code, | 75 system_code, |
| 77 blink::WebString::fromUTF8(error_message)); | 76 blink::WebString::fromUTF8(error_message)); |
| 78 } | 77 } |
| 79 | 78 |
| 80 } // namespace media | 79 } // namespace media |
| 81 | 80 |
| 82 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_ | 81 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_ |
| OLD | NEW |