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

Side by Side Diff: media/base/cdm_promise_adapter.cc

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: android Created 4 years, 7 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_promise_adapter.h ('k') | media/base/channel_mixer_unittest.cc » ('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 #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
11 namespace media { 11 namespace media {
12 12
13 CdmPromiseAdapter::CdmPromiseAdapter() : next_promise_id_(1) { 13 CdmPromiseAdapter::CdmPromiseAdapter() : next_promise_id_(1) {
14 } 14 }
15 15
16 CdmPromiseAdapter::~CdmPromiseAdapter() { 16 CdmPromiseAdapter::~CdmPromiseAdapter() {
17 DCHECK(promises_.empty()); 17 DCHECK(promises_.empty());
18 DCHECK(thread_checker_.CalledOnValidThread()); 18 DCHECK(thread_checker_.CalledOnValidThread());
19 Clear(); 19 Clear();
20 } 20 }
21 21
22 uint32_t CdmPromiseAdapter::SavePromise(scoped_ptr<CdmPromise> promise) { 22 uint32_t CdmPromiseAdapter::SavePromise(std::unique_ptr<CdmPromise> promise) {
23 DCHECK(thread_checker_.CalledOnValidThread()); 23 DCHECK(thread_checker_.CalledOnValidThread());
24 uint32_t promise_id = next_promise_id_++; 24 uint32_t promise_id = next_promise_id_++;
25 promises_.add(promise_id, std::move(promise)); 25 promises_.add(promise_id, std::move(promise));
26 return promise_id; 26 return promise_id;
27 } 27 }
28 28
29 template <typename... T> 29 template <typename... T>
30 void CdmPromiseAdapter::ResolvePromise(uint32_t promise_id, 30 void CdmPromiseAdapter::ResolvePromise(uint32_t promise_id,
31 const T&... result) { 31 const T&... result) {
32 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); 32 std::unique_ptr<CdmPromise> promise = TakePromise(promise_id);
33 if (!promise) { 33 if (!promise) {
34 NOTREACHED() << "Promise not found for " << promise_id; 34 NOTREACHED() << "Promise not found for " << promise_id;
35 return; 35 return;
36 } 36 }
37 37
38 // Sanity check the type before we do static_cast. 38 // Sanity check the type before we do static_cast.
39 CdmPromise::ResolveParameterType type = promise->GetResolveParameterType(); 39 CdmPromise::ResolveParameterType type = promise->GetResolveParameterType();
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 MediaKeys::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 scoped_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(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted.");
67 promises_.clear(); 67 promises_.clear();
68 } 68 }
69 69
70 scoped_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(uint32_t promise_id) { 70 std::unique_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(
71 uint32_t promise_id) {
71 DCHECK(thread_checker_.CalledOnValidThread()); 72 DCHECK(thread_checker_.CalledOnValidThread());
72 PromiseMap::iterator it = promises_.find(promise_id); 73 PromiseMap::iterator it = promises_.find(promise_id);
73 if (it == promises_.end()) 74 if (it == promises_.end())
74 return nullptr; 75 return nullptr;
75 return promises_.take_and_erase(it); 76 return promises_.take_and_erase(it);
76 } 77 }
77 78
78 // Explicit instantiation of function templates. 79 // Explicit instantiation of function templates.
79 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); 80 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t);
80 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( 81 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(
81 uint32_t, 82 uint32_t,
82 const std::string&); 83 const std::string&);
83 84
84 } // namespace media 85 } // namespace media
OLDNEW
« no previous file with comments | « media/base/cdm_promise_adapter.h ('k') | media/base/channel_mixer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698