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

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

Issue 1849033002: Reject outstanding promises asynchronously when cleared (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | 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 "base/bind.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
9 #include "media/base/media_keys.h" 13 #include "media/base/media_keys.h"
10 14
11 namespace media { 15 namespace media {
12 16
17 static void AbortPromise(scoped_ptr<CdmPromise> promise) {
18 promise->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted.");
19 }
20
13 CdmPromiseAdapter::CdmPromiseAdapter() : next_promise_id_(1) { 21 CdmPromiseAdapter::CdmPromiseAdapter() : next_promise_id_(1) {
14 } 22 }
15 23
16 CdmPromiseAdapter::~CdmPromiseAdapter() { 24 CdmPromiseAdapter::~CdmPromiseAdapter() {
17 DCHECK(promises_.empty()); 25 DCHECK(promises_.empty());
18 DCHECK(thread_checker_.CalledOnValidThread()); 26 DCHECK(thread_checker_.CalledOnValidThread());
19 Clear(); 27 Clear();
20 } 28 }
21 29
22 uint32_t CdmPromiseAdapter::SavePromise(scoped_ptr<CdmPromise> promise) { 30 uint32_t CdmPromiseAdapter::SavePromise(scoped_ptr<CdmPromise> promise) {
(...skipping 30 matching lines...) Expand all
53 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); 61 scoped_ptr<CdmPromise> promise = TakePromise(promise_id);
54 if (!promise) { 62 if (!promise) {
55 NOTREACHED() << "No promise found for promise_id " << promise_id; 63 NOTREACHED() << "No promise found for promise_id " << promise_id;
56 return; 64 return;
57 } 65 }
58 66
59 promise->reject(exception_code, system_code, error_message); 67 promise->reject(exception_code, system_code, error_message);
60 } 68 }
61 69
62 void CdmPromiseAdapter::Clear() { 70 void CdmPromiseAdapter::Clear() {
63 // Reject all outstanding promises. 71 // Reject all outstanding promises asynchronously. This is done as it
72 // may be triggered by gc in blink, and it doesn't like executing code
73 // while gc is running.
64 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
65 for (auto& promise : promises_) 75 while (promises_.begin() != promises_.end()) {
66 promise.second->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted."); 76 scoped_ptr<CdmPromise> promise(promises_.take_and_erase(promises_.begin()));
77 base::ThreadTaskRunnerHandle::Get()->PostTask(
78 FROM_HERE, base::Bind(&AbortPromise, base::Passed(&promise)));
79 }
67 promises_.clear(); 80 promises_.clear();
68 } 81 }
69 82
70 scoped_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(uint32_t promise_id) { 83 scoped_ptr<CdmPromise> CdmPromiseAdapter::TakePromise(uint32_t promise_id) {
71 DCHECK(thread_checker_.CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
72 PromiseMap::iterator it = promises_.find(promise_id); 85 PromiseMap::iterator it = promises_.find(promise_id);
73 if (it == promises_.end()) 86 if (it == promises_.end())
74 return nullptr; 87 return nullptr;
75 return promises_.take_and_erase(it); 88 return promises_.take_and_erase(it);
76 } 89 }
77 90
78 // Explicit instantiation of function templates. 91 // Explicit instantiation of function templates.
79 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t); 92 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(uint32_t);
80 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise( 93 template MEDIA_EXPORT void CdmPromiseAdapter::ResolvePromise(
81 uint32_t, 94 uint32_t,
82 const std::string&); 95 const std::string&);
83 96
84 } // namespace media 97 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698