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

Side by Side Diff: media/blink/cdm_session_adapter.cc

Issue 1241263002: media: Add UMA and trace events for CDM creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 5 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 | « media/blink/cdm_session_adapter.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | 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/blink/cdm_session_adapter.h" 5 #include "media/blink/cdm_session_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
9 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/trace_event/trace_event.h"
10 #include "media/base/cdm_factory.h" 12 #include "media/base/cdm_factory.h"
11 #include "media/base/cdm_key_information.h" 13 #include "media/base/cdm_key_information.h"
12 #include "media/base/cdm_promise.h" 14 #include "media/base/cdm_promise.h"
13 #include "media/base/key_systems.h" 15 #include "media/base/key_systems.h"
14 #include "media/blink/webcontentdecryptionmodule_impl.h" 16 #include "media/blink/webcontentdecryptionmodule_impl.h"
15 #include "media/blink/webcontentdecryptionmodulesession_impl.h" 17 #include "media/blink/webcontentdecryptionmodulesession_impl.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 namespace media { 20 namespace media {
19 21
20 const char kMediaEME[] = "Media.EME."; 22 const char kMediaEME[] = "Media.EME.";
21 const char kDot[] = "."; 23 const char kDot[] = ".";
24 const char kTimeToCreateCdmUMAName[] = "CreateCdmTime";
22 25
23 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { 26 CdmSessionAdapter::CdmSessionAdapter()
24 } 27 : trace_id_(0), weak_ptr_factory_(this) {}
25 28
26 CdmSessionAdapter::~CdmSessionAdapter() {} 29 CdmSessionAdapter::~CdmSessionAdapter() {}
27 30
28 void CdmSessionAdapter::CreateCdm( 31 void CdmSessionAdapter::CreateCdm(
29 CdmFactory* cdm_factory, 32 CdmFactory* cdm_factory,
30 const std::string& key_system, 33 const std::string& key_system,
31 const GURL& security_origin, 34 const GURL& security_origin,
32 const CdmConfig& cdm_config, 35 const CdmConfig& cdm_config,
33 blink::WebContentDecryptionModuleResult result) { 36 blink::WebContentDecryptionModuleResult result) {
37 TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm",
38 ++trace_id_);
39
40 base::TimeTicks start_time = base::TimeTicks::Now();
41
34 // Note: WebContentDecryptionModuleImpl::Create() calls this method without 42 // Note: WebContentDecryptionModuleImpl::Create() calls this method without
35 // holding a reference to the CdmSessionAdapter. Bind OnCdmCreated() with 43 // holding a reference to the CdmSessionAdapter. Bind OnCdmCreated() with
36 // |this| instead of |weak_this| to prevent |this| from being destructed. 44 // |this| instead of |weak_this| to prevent |this| from being destructed.
37 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); 45 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr();
38 cdm_factory->Create( 46 cdm_factory->Create(
39 key_system, security_origin, cdm_config, 47 key_system, security_origin, cdm_config,
40 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), 48 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this),
41 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), 49 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this),
42 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this), 50 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this),
43 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), 51 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this),
44 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this), 52 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this),
45 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, result)); 53 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, start_time,
54 result));
46 } 55 }
47 56
48 void CdmSessionAdapter::SetServerCertificate( 57 void CdmSessionAdapter::SetServerCertificate(
49 const std::vector<uint8_t>& certificate, 58 const std::vector<uint8_t>& certificate,
50 scoped_ptr<SimpleCdmPromise> promise) { 59 scoped_ptr<SimpleCdmPromise> promise) {
51 cdm_->SetServerCertificate(certificate, promise.Pass()); 60 cdm_->SetServerCertificate(certificate, promise.Pass());
52 } 61 }
53 62
54 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { 63 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() {
55 return new WebContentDecryptionModuleSessionImpl(this); 64 return new WebContentDecryptionModuleSessionImpl(this);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 113
105 CdmContext* CdmSessionAdapter::GetCdmContext() { 114 CdmContext* CdmSessionAdapter::GetCdmContext() {
106 return cdm_->GetCdmContext(); 115 return cdm_->GetCdmContext();
107 } 116 }
108 117
109 const std::string& CdmSessionAdapter::GetKeySystem() const { 118 const std::string& CdmSessionAdapter::GetKeySystem() const {
110 return key_system_; 119 return key_system_;
111 } 120 }
112 121
113 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const { 122 const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const {
123 DCHECK(!key_system_uma_prefix_.empty());
114 return key_system_uma_prefix_; 124 return key_system_uma_prefix_;
115 } 125 }
116 126
117 void CdmSessionAdapter::OnCdmCreated( 127 void CdmSessionAdapter::OnCdmCreated(
118 const std::string& key_system, 128 const std::string& key_system,
129 base::TimeTicks start_time,
119 blink::WebContentDecryptionModuleResult result, 130 blink::WebContentDecryptionModuleResult result,
120 scoped_ptr<MediaKeys> cdm, 131 scoped_ptr<MediaKeys> cdm,
121 const std::string& error_message) { 132 const std::string& error_message) {
122 DVLOG(2) << __FUNCTION__; 133 DVLOG(2) << __FUNCTION__;
134 DCHECK(!cdm_);
135
136 TRACE_EVENT_ASYNC_END2("media", "CdmSessionAdapter::CreateCdm", trace_id_,
137 "success", (cdm ? "true" : "false"), "error_message",
138 error_message);
139
123 if (!cdm) { 140 if (!cdm) {
124 result.completeWithError( 141 result.completeWithError(
125 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, 142 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
126 blink::WebString::fromUTF8(error_message)); 143 blink::WebString::fromUTF8(error_message));
127 return; 144 return;
128 } 145 }
129 146
130 key_system_ = key_system; 147 key_system_ = key_system;
131 key_system_uma_prefix_ = 148 key_system_uma_prefix_ =
132 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; 149 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot;
150
151 // Only report time for successful CDM creation.
152 ReportTimeToCreateCdmUMA(base::TimeTicks::Now() - start_time);
153
133 cdm_ = cdm.Pass(); 154 cdm_ = cdm.Pass();
134 155
135 result.completeWithContentDecryptionModule( 156 result.completeWithContentDecryptionModule(
136 new WebContentDecryptionModuleImpl(this)); 157 new WebContentDecryptionModuleImpl(this));
137 } 158 }
138 159
139 void CdmSessionAdapter::OnSessionMessage( 160 void CdmSessionAdapter::OnSessionMessage(
140 const std::string& session_id, 161 const std::string& session_id,
141 MediaKeys::MessageType message_type, 162 MediaKeys::MessageType message_type,
142 const std::vector<uint8_t>& message, 163 const std::vector<uint8_t>& message,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 209
189 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( 210 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession(
190 const std::string& session_id) { 211 const std::string& session_id) {
191 // Since session objects may get garbage collected, it is possible that there 212 // Since session objects may get garbage collected, it is possible that there
192 // are events coming back from the CDM and the session has been unregistered. 213 // are events coming back from the CDM and the session has been unregistered.
193 // We can not tell if the CDM is firing events at sessions that never existed. 214 // We can not tell if the CDM is firing events at sessions that never existed.
194 SessionMap::iterator session = sessions_.find(session_id); 215 SessionMap::iterator session = sessions_.find(session_id);
195 return (session != sessions_.end()) ? session->second.get() : NULL; 216 return (session != sessions_.end()) ? session->second.get() : NULL;
196 } 217 }
197 218
219 void CdmSessionAdapter::ReportTimeToCreateCdmUMA(base::TimeDelta time) const {
220 // Note: This leaks memory, which is expected behavior.
221 base::HistogramBase* histogram = base::Histogram::FactoryTimeGet(
222 GetKeySystemUMAPrefix() + kTimeToCreateCdmUMAName,
223 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(10),
224 50, base::HistogramBase::kUmaTargetedHistogramFlag);
225
226 histogram->AddTime(time);
227 }
228
198 } // namespace media 229 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/cdm_session_adapter.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698