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

Side by Side Diff: media/mojo/services/mojo_cdm_promise.cc

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 #include "media/mojo/services/mojo_cdm_promise.h" 5 #include "media/mojo/services/mojo_cdm_promise.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 template <typename... T> 32 template <typename... T>
33 MojoCdmPromise<T...>::MojoCdmPromise(const CallbackType& callback) 33 MojoCdmPromise<T...>::MojoCdmPromise(const CallbackType& callback)
34 : callback_(callback) { 34 : callback_(callback) {
35 DCHECK(!callback_.is_null()); 35 DCHECK(!callback_.is_null());
36 } 36 }
37 37
38 template <typename... T> 38 template <typename... T>
39 MojoCdmPromise<T...>::~MojoCdmPromise() { 39 MojoCdmPromise<T...>::~MojoCdmPromise() {
40 if (!callback_.is_null()) 40 if (IsPromiseSettled())
41 DVLOG(1) << "Promise not resolved before destruction."; 41 return;
42
43 DCHECK(!callback_.is_null());
44 RejectPromiseOnDestruction();
42 } 45 }
43 46
44 template <typename... T> 47 template <typename... T>
45 void MojoCdmPromise<T...>::resolve(const T&... result) { 48 void MojoCdmPromise<T...>::resolve(const T&... result) {
46 MarkPromiseSettled(); 49 MarkPromiseSettled();
47 interfaces::CdmPromiseResultPtr cdm_promise_result( 50 interfaces::CdmPromiseResultPtr cdm_promise_result(
48 interfaces::CdmPromiseResult::New()); 51 interfaces::CdmPromiseResult::New());
49 cdm_promise_result->success = true; 52 cdm_promise_result->success = true;
50 callback_.Run( 53 callback_.Run(
51 std::move(cdm_promise_result), 54 std::move(cdm_promise_result),
52 mojo::TypeConverter<typename MojoTypeTrait<T>::MojoType, T>::Convert( 55 mojo::TypeConverter<typename MojoTypeTrait<T>::MojoType, T>::Convert(
53 result)...); 56 result)...);
54 callback_.reset(); 57 callback_.reset();
55 } 58 }
56 59
57 template <typename... T> 60 template <typename... T>
58 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception, 61 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception,
59 uint32_t system_code, 62 uint32_t system_code,
60 const std::string& error_message) { 63 const std::string& error_message) {
61 MarkPromiseSettled(); 64 MarkPromiseSettled();
62 callback_.Run(GetRejectResult(exception, system_code, error_message), 65 callback_.Run(GetRejectResult(exception, system_code, error_message),
63 MojoTypeTrait<T>::DefaultValue()...); 66 MojoTypeTrait<T>::DefaultValue()...);
64 callback_.reset(); 67 callback_.reset();
65 } 68 }
66 69
67 template class MojoCdmPromise<>; 70 template class MojoCdmPromise<>;
68 template class MojoCdmPromise<std::string>; 71 template class MojoCdmPromise<std::string>;
69 72
70 } // namespace media 73 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698