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

Side by Side Diff: media/base/cdm_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
« no previous file with comments | « media/base/cdm_callback_promise.cc ('k') | media/blink/cdm_result_promise.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BASE_CDM_PROMISE_H_ 5 #ifndef MEDIA_BASE_CDM_PROMISE_H_
6 #define MEDIA_BASE_CDM_PROMISE_H_ 6 #define MEDIA_BASE_CDM_PROMISE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // CdmPromise implementation. 92 // CdmPromise implementation.
93 virtual void reject(MediaKeys::Exception exception_code, 93 virtual void reject(MediaKeys::Exception exception_code,
94 uint32_t system_code, 94 uint32_t system_code,
95 const std::string& error_message) = 0; 95 const std::string& error_message) = 0;
96 96
97 ResolveParameterType GetResolveParameterType() const override { 97 ResolveParameterType GetResolveParameterType() const override {
98 return CdmPromiseTraits<T...>::kType; 98 return CdmPromiseTraits<T...>::kType;
99 } 99 }
100 100
101 protected: 101 protected:
102 bool IsPromiseSettled() const { return is_settled_; }
103
102 // All implementations must call this method in resolve() and reject() methods 104 // All implementations must call this method in resolve() and reject() methods
103 // to indicate that the promise has been settled. 105 // to indicate that the promise has been settled.
104 void MarkPromiseSettled() { 106 void MarkPromiseSettled() {
105 // Promise can only be settled once. 107 // Promise can only be settled once.
106 DCHECK(!is_settled_); 108 DCHECK(!is_settled_);
107 is_settled_ = true; 109 is_settled_ = true;
108 } 110 }
109 111
112 // Must be called by the concrete destructor if !IsPromiseSettled().
113 // Note: We can't call reject() in ~CdmPromise() because reject() is virtual.
114 void RejectPromiseOnDestruction() {
115 DCHECK(!is_settled_);
116 std::string message =
117 "Unfulfilled promise rejected automatically during destruction.";
118 DVLOG(1) << message;
119 reject(MediaKeys::INVALID_STATE_ERROR, 0, message);
120 DCHECK(is_settled_);
121 }
122
110 private: 123 private:
111 // Keep track of whether the promise has been resolved or rejected yet. 124 // Keep track of whether the promise has been resolved or rejected yet.
112 bool is_settled_; 125 bool is_settled_;
113 126
114 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate); 127 DISALLOW_COPY_AND_ASSIGN(CdmPromiseTemplate);
115 }; 128 };
116 129
117 } // namespace media 130 } // namespace media
118 131
119 #endif // MEDIA_BASE_CDM_PROMISE_H_ 132 #endif // MEDIA_BASE_CDM_PROMISE_H_
OLDNEW
« no previous file with comments | « media/base/cdm_callback_promise.cc ('k') | media/blink/cdm_result_promise.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698