Chromium Code Reviews| 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/blink/cdm_session_adapter.h" | 5 #include "media/blink/cdm_session_adapter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | |
| 13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 14 #include "media/base/cdm_factory.h" | 15 #include "media/base/cdm_factory.h" |
| 15 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
| 16 #include "media/base/cdm_promise.h" | 17 #include "media/base/cdm_promise.h" |
| 17 #include "media/base/key_systems.h" | 18 #include "media/base/key_systems.h" |
| 18 #include "media/blink/webcontentdecryptionmodule_impl.h" | 19 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 19 #include "media/blink/webcontentdecryptionmodulesession_impl.h" | 20 #include "media/blink/webcontentdecryptionmodulesession_impl.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 namespace media { | 23 namespace media { |
| 23 | 24 |
| 25 namespace { | |
| 24 const char kMediaEME[] = "Media.EME."; | 26 const char kMediaEME[] = "Media.EME."; |
| 25 const char kDot[] = "."; | 27 const char kDot[] = "."; |
| 26 const char kTimeToCreateCdmUMAName[] = "CreateCdmTime"; | 28 const char kTimeToCreateCdmUMAName[] = "CreateCdmTime"; |
| 27 | 29 |
| 30 void ReleaseCdm(scoped_refptr<MediaKeys> cdm) { | |
| 31 // |cdm| will be freed now. | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 28 CdmSessionAdapter::CdmSessionAdapter() | 36 CdmSessionAdapter::CdmSessionAdapter() |
| 29 : trace_id_(0), weak_ptr_factory_(this) {} | 37 : trace_id_(0), weak_ptr_factory_(this) {} |
| 30 | 38 |
| 31 CdmSessionAdapter::~CdmSessionAdapter() {} | 39 CdmSessionAdapter::~CdmSessionAdapter() { |
| 40 // Freeing |cdm_| may take a while, so post a task to do it asynchronously. | |
| 41 // Note that freeing the CDM will cause any unfullfilled promises to be | |
| 42 // rejected, and that needs to be done outside of blink gc (which most | |
| 43 // likely triggered our destruction). | |
| 44 if (cdm_) { | |
| 45 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 46 FROM_HERE, base::Bind(&ReleaseCdm, cdm_)); | |
|
xhwang
2016/04/11 16:52:20
nit: This can be done with MessageLoop::ReleaseSoo
| |
| 47 } | |
| 48 } | |
| 32 | 49 |
| 33 void CdmSessionAdapter::CreateCdm( | 50 void CdmSessionAdapter::CreateCdm( |
| 34 CdmFactory* cdm_factory, | 51 CdmFactory* cdm_factory, |
| 35 const std::string& key_system, | 52 const std::string& key_system, |
| 36 const GURL& security_origin, | 53 const GURL& security_origin, |
| 37 const CdmConfig& cdm_config, | 54 const CdmConfig& cdm_config, |
| 38 scoped_ptr<blink::WebContentDecryptionModuleResult> result) { | 55 scoped_ptr<blink::WebContentDecryptionModuleResult> result) { |
| 39 TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm", | 56 TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm", |
| 40 ++trace_id_); | 57 ++trace_id_); |
| 41 | 58 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 // Note: This leaks memory, which is expected behavior. | 244 // Note: This leaks memory, which is expected behavior. |
| 228 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 245 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
| 229 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, | 246 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, |
| 230 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 247 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
| 231 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 248 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 232 | 249 |
| 233 histogram->AddTime(time); | 250 histogram->AddTime(time); |
| 234 } | 251 } |
| 235 | 252 |
| 236 } // namespace media | 253 } // namespace media |
| OLD | NEW |