Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: media/blink/cdm_result_promise.h

Issue 1729063003: media: Reject pending CDM promise during destruction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
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 media::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(media::MediaKeys::Exception exception_code, 35 void reject(MediaKeys::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 media::CdmPromiseTemplate<T...>::MarkPromiseSettled; 40 using CdmPromiseTemplate<T...>::IsPromiseSettled;
41 using CdmPromiseTemplate<T...>::MarkPromiseSettled;
42 using CdmPromiseTemplate<T...>::RejectPromiseOnDestruction;
41 43
42 blink::WebContentDecryptionModuleResult web_cdm_result_; 44 blink::WebContentDecryptionModuleResult web_cdm_result_;
43 45
44 // UMA name to report result to. 46 // UMA name to report result to.
45 std::string uma_name_; 47 std::string uma_name_;
46 48
47 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise); 49 DISALLOW_COPY_AND_ASSIGN(CdmResultPromise);
48 }; 50 };
49 51
50 template <typename... T> 52 template <typename... T>
51 CdmResultPromise<T...>::CdmResultPromise( 53 CdmResultPromise<T...>::CdmResultPromise(
52 const blink::WebContentDecryptionModuleResult& result, 54 const blink::WebContentDecryptionModuleResult& result,
53 const std::string& uma_name) 55 const std::string& uma_name)
54 : web_cdm_result_(result), uma_name_(uma_name) { 56 : web_cdm_result_(result), uma_name_(uma_name) {
55 } 57 }
56 58
57 template <typename... T> 59 template <typename... T>
58 CdmResultPromise<T...>::~CdmResultPromise() { 60 CdmResultPromise<T...>::~CdmResultPromise() {
61 if (IsPromiseSettled())
62 return;
63
64 DCHECK(!web_cdm_result_.isCompleted());
65 RejectPromiseOnDestruction();
59 } 66 }
60 67
61 // "inline" is needed to prevent multiple definition error. 68 // "inline" is needed to prevent multiple definition error.
62 69
63 template <> 70 template <>
64 inline void CdmResultPromise<>::resolve() { 71 inline void CdmResultPromise<>::resolve() {
65 MarkPromiseSettled(); 72 MarkPromiseSettled();
66 ReportCdmResultUMA(uma_name_, SUCCESS); 73 ReportCdmResultUMA(uma_name_, SUCCESS);
67 web_cdm_result_.complete(); 74 web_cdm_result_.complete();
68 } 75 }
69 76
70 template <typename... T> 77 template <typename... T>
71 void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code, 78 void CdmResultPromise<T...>::reject(MediaKeys::Exception exception_code,
72 uint32_t system_code, 79 uint32_t system_code,
73 const std::string& error_message) { 80 const std::string& error_message) {
74 MarkPromiseSettled(); 81 MarkPromiseSettled();
75 ReportCdmResultUMA(uma_name_, 82 ReportCdmResultUMA(uma_name_,
76 ConvertCdmExceptionToResultForUMA(exception_code)); 83 ConvertCdmExceptionToResultForUMA(exception_code));
77 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), 84 web_cdm_result_.completeWithError(ConvertCdmException(exception_code),
78 system_code, 85 system_code,
79 blink::WebString::fromUTF8(error_message)); 86 blink::WebString::fromUTF8(error_message));
80 } 87 }
81 88
82 } // namespace media 89 } // namespace media
83 90
84 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_ 91 #endif // MEDIA_BLINK_CDM_RESULT_PROMISE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698