| 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/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "media/base/cdm_factory.h" | 15 #include "media/base/cdm_factory.h" |
| 16 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
| 17 #include "media/base/cdm_promise.h" | 17 #include "media/base/cdm_promise.h" |
| 18 #include "media/base/key_systems.h" | 18 #include "media/base/key_systems.h" |
| 19 #include "media/blink/webcontentdecryptionmodule_impl.h" | 19 #include "media/blink/webcontentdecryptionmodule_impl.h" |
| 20 #include "media/blink/webcontentdecryptionmodulesession_impl.h" | 20 #include "media/blink/webcontentdecryptionmodulesession_impl.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const char kMediaEME[] = "Media.EME."; | 26 const char kMediaEME[] = "Media.EME."; |
| 27 const char kDot[] = "."; | 27 const char kDot[] = "."; |
| 28 const char kTimeToCreateCdmUMAName[] = "CreateCdmTime"; | 28 const char kTimeToCreateCdmUMAName[] = "CreateCdmTime"; |
| 29 | |
| 30 void ReleaseCdm(scoped_refptr<MediaKeys> cdm) { | |
| 31 // |cdm| will be freed now. | |
| 32 } | |
| 33 | |
| 34 } // namespace | 29 } // namespace |
| 35 | 30 |
| 36 CdmSessionAdapter::CdmSessionAdapter() | 31 CdmSessionAdapter::CdmSessionAdapter() |
| 37 : trace_id_(0), weak_ptr_factory_(this) {} | 32 : trace_id_(0), weak_ptr_factory_(this) {} |
| 38 | 33 |
| 39 CdmSessionAdapter::~CdmSessionAdapter() { | 34 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_)); | |
| 47 } | |
| 48 } | |
| 49 | 35 |
| 50 void CdmSessionAdapter::CreateCdm( | 36 void CdmSessionAdapter::CreateCdm( |
| 51 CdmFactory* cdm_factory, | 37 CdmFactory* cdm_factory, |
| 52 const std::string& key_system, | 38 const std::string& key_system, |
| 53 const GURL& security_origin, | 39 const GURL& security_origin, |
| 54 const CdmConfig& cdm_config, | 40 const CdmConfig& cdm_config, |
| 55 std::unique_ptr<blink::WebContentDecryptionModuleResult> result) { | 41 std::unique_ptr<blink::WebContentDecryptionModuleResult> result) { |
| 56 TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm", | 42 TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm", |
| 57 ++trace_id_); | 43 ++trace_id_); |
| 58 | 44 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Note: This leaks memory, which is expected behavior. | 234 // Note: This leaks memory, which is expected behavior. |
| 249 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( | 235 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet( |
| 250 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, | 236 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName, |
| 251 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), | 237 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10), |
| 252 50, base::HistogramBase::kUmaTargetedHistogramFlag); | 238 50, base::HistogramBase::kUmaTargetedHistogramFlag); |
| 253 | 239 |
| 254 histogram->AddTime(time); | 240 histogram->AddTime(time); |
| 255 } | 241 } |
| 256 | 242 |
| 257 } // namespace media | 243 } // namespace media |
| OLD | NEW |