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 #include "media/base/cdm_promise_adapter.h" | 5 #include "media/base/cdm_promise_adapter.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "media/base/media_keys.h" | 9 #include "media/base/media_keys.h" |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 CdmPromise::ResolveParameterType expected = CdmPromiseTraits<T...>::kType; | 40 CdmPromise::ResolveParameterType expected = CdmPromiseTraits<T...>::kType; |
41 if (type != expected) { | 41 if (type != expected) { |
42 NOTREACHED() << "Promise type mismatch: " << type << " vs " << expected; | 42 NOTREACHED() << "Promise type mismatch: " << type << " vs " << expected; |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 static_cast<CdmPromiseTemplate<T...>*>(promise.get())->resolve(result...); | 46 static_cast<CdmPromiseTemplate<T...>*>(promise.get())->resolve(result...); |
47 } | 47 } |
48 | 48 |
49 void CdmPromiseAdapter::RejectPromise(uint32_t promise_id, | 49 void CdmPromiseAdapter::RejectPromise(uint32_t promise_id, |
50 MediaKeys::Exception exception_code, | 50 CdmPromise::Exception exception_code, |
51 uint32_t system_code, | 51 uint32_t system_code, |
52 const std::string& error_message) { | 52 const std::string& error_message) { |
53 std::unique_ptr<CdmPromise> promise = TakePromise(promise_id); | 53 std::unique_ptr<CdmPromise> promise = TakePromise(promise_id); |
54 if (!promise) { | 54 if (!promise) { |
55 NOTREACHED() << "No promise found for promise_id " << promise_id; | 55 NOTREACHED() << "No promise found for promise_id " << promise_id; |
56 return; | 56 return; |
57 } | 57 } |
58 | 58 |
59 promise->reject(exception_code, system_code, error_message); | 59 promise->reject(exception_code, system_code, error_message); |
60 } | 60 } |
61 | 61 |
62 void CdmPromiseAdapter::Clear() { | 62 void CdmPromiseAdapter::Clear() { |
63 // Reject all outstanding promises. | 63 // Reject all outstanding promises. |
64 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
65 for (auto& promise : promises_) | 65 for (auto& promise : promises_) |
66 promise.second->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted."); | 66 promise.second->reject(CdmPromise::UNKNOWN_ERROR, 0, "Operation aborted."); |
67 promises_.clear(); | 67 promises_.clear(); |
68 } | 68 } |
69 | 69 |
70 std::unique_ptr<CdmPromise> CdmPromiseAdapter::TakePromise( | 70 std::unique_ptr<CdmPromise> CdmPromiseAdapter::TakePromise( |
71 uint32_t promise_id) { | 71 uint32_t promise_id) { |
72 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
73 PromiseMap::iterator it = promises_.find(promise_id); | 73 PromiseMap::iterator it = promises_.find(promise_id); |
74 if (it == promises_.end()) | 74 if (it == promises_.end()) |
75 return nullptr; | 75 return nullptr; |
76 return promises_.take_and_erase(it); | 76 return promises_.take_and_erase(it); |
77 } | 77 } |
78 | 78 |
79 // Explicit instantiation of function templates. | 79 // Explicit instantiation of function templates. |
80 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); | 80 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); |
81 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( | 81 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( |
82 uint32_t, | 82 uint32_t, |
83 const std::string&); | 83 const std::string&); |
84 | 84 |
85 } // namespace media | 85 } // namespace media |
OLD | NEW |