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

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: 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 (callback_.is_null())
41 DVLOG(1) << "Promise not resolved before destruction."; 41 return;
42
43 std::string message =
ddorwin 2016/02/25 19:14:12 We have the same code in 4 places. Does it make se
xhwang 2016/02/25 19:53:11 reject() is virtual and we have to call the reject
44 "Unfulfilled promise rejected automatically during destruction.";
45 DVLOG(1) << message;
46 reject(MediaKeys::INVALID_STATE_ERROR, 0, message);
42 } 47 }
43 48
44 template <typename... T> 49 template <typename... T>
45 void MojoCdmPromise<T...>::resolve(const T&... result) { 50 void MojoCdmPromise<T...>::resolve(const T&... result) {
46 MarkPromiseSettled(); 51 MarkPromiseSettled();
47 interfaces::CdmPromiseResultPtr cdm_promise_result( 52 interfaces::CdmPromiseResultPtr cdm_promise_result(
48 interfaces::CdmPromiseResult::New()); 53 interfaces::CdmPromiseResult::New());
49 cdm_promise_result->success = true; 54 cdm_promise_result->success = true;
50 callback_.Run( 55 callback_.Run(
51 std::move(cdm_promise_result), 56 std::move(cdm_promise_result),
52 mojo::TypeConverter<typename MojoTypeTrait<T>::MojoType, T>::Convert( 57 mojo::TypeConverter<typename MojoTypeTrait<T>::MojoType, T>::Convert(
53 result)...); 58 result)...);
54 callback_.reset(); 59 callback_.reset();
55 } 60 }
56 61
57 template <typename... T> 62 template <typename... T>
58 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception, 63 void MojoCdmPromise<T...>::reject(MediaKeys::Exception exception,
59 uint32_t system_code, 64 uint32_t system_code,
60 const std::string& error_message) { 65 const std::string& error_message) {
61 MarkPromiseSettled(); 66 MarkPromiseSettled();
62 callback_.Run(GetRejectResult(exception, system_code, error_message), 67 callback_.Run(GetRejectResult(exception, system_code, error_message),
63 MojoTypeTrait<T>::DefaultValue()...); 68 MojoTypeTrait<T>::DefaultValue()...);
64 callback_.reset(); 69 callback_.reset();
65 } 70 }
66 71
67 template class MojoCdmPromise<>; 72 template class MojoCdmPromise<>;
68 template class MojoCdmPromise<std::string>; 73 template class MojoCdmPromise<std::string>;
69 74
70 } // namespace media 75 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698