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

Unified Diff: media/blink/cdm_session_adapter.cc

Issue 1870883003: Destroy the CDM asynchronously (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/cdm_session_adapter.cc
diff --git a/media/blink/cdm_session_adapter.cc b/media/blink/cdm_session_adapter.cc
index 693779187c7622b7ab2729e18c5997a69ec5e9df..3e1cd6095b6a195c51dc421a35725c7e7fcecc40 100644
--- a/media/blink/cdm_session_adapter.cc
+++ b/media/blink/cdm_session_adapter.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
+#include "base/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "media/base/cdm_factory.h"
#include "media/base/cdm_key_information.h"
@@ -21,14 +22,30 @@
namespace media {
+namespace {
const char kMediaEME[] = "Media.EME.";
const char kDot[] = ".";
const char kTimeToCreateCdmUMAName[] = "CreateCdmTime";
+void ReleaseCdm(scoped_refptr<MediaKeys> cdm) {
+ // |cdm| will be freed now.
+}
+
+} // namespace
+
CdmSessionAdapter::CdmSessionAdapter()
: trace_id_(0), weak_ptr_factory_(this) {}
-CdmSessionAdapter::~CdmSessionAdapter() {}
+CdmSessionAdapter::~CdmSessionAdapter() {
+ // Freeing |cdm_| may take a while, so post a task to do it asynchronously.
+ // Note that freeing the CDM will cause any unfullfilled promises to be
+ // rejected, and that needs to be done outside of blink gc (which most
+ // likely triggered our destruction).
+ if (cdm_) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&ReleaseCdm, cdm_));
xhwang 2016/04/11 16:52:20 nit: This can be done with MessageLoop::ReleaseSoo
+ }
+}
void CdmSessionAdapter::CreateCdm(
CdmFactory* cdm_factory,
« 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