| Index: media/base/cdm_promise_adapter.cc
|
| diff --git a/media/base/cdm_promise_adapter.cc b/media/base/cdm_promise_adapter.cc
|
| index 5df17d861cbc00af784c6e79b8e7ab673bf8e83e..a9e189d1c4ce723ba3b152d55ffb082ababf0470 100644
|
| --- a/media/base/cdm_promise_adapter.cc
|
| +++ b/media/base/cdm_promise_adapter.cc
|
| @@ -6,10 +6,18 @@
|
|
|
| #include <utility>
|
|
|
| +#include "base/bind.h"
|
| +#include "base/location.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| #include "media/base/media_keys.h"
|
|
|
| namespace media {
|
|
|
| +static void AbortPromise(scoped_ptr<CdmPromise> promise) {
|
| + promise->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted.");
|
| +}
|
| +
|
| CdmPromiseAdapter::CdmPromiseAdapter() : next_promise_id_(1) {
|
| }
|
|
|
| @@ -60,10 +68,15 @@ void CdmPromiseAdapter::RejectPromise(uint32_t promise_id,
|
| }
|
|
|
| void CdmPromiseAdapter::Clear() {
|
| - // Reject all outstanding promises.
|
| + // Reject all outstanding promises asynchronously. This is done as it
|
| + // may be triggered by gc in blink, and it doesn't like executing code
|
| + // while gc is running.
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - for (auto& promise : promises_)
|
| - promise.second->reject(MediaKeys::UNKNOWN_ERROR, 0, "Operation aborted.");
|
| + while (promises_.begin() != promises_.end()) {
|
| + scoped_ptr<CdmPromise> promise(promises_.take_and_erase(promises_.begin()));
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE, base::Bind(&AbortPromise, base::Passed(&promise)));
|
| + }
|
| promises_.clear();
|
| }
|
|
|
|
|