From 0acca44b3b1071de445a09484cdf1c1ffac729cc Mon Sep 17 00:00:00 2001 From: xhwang Date: Wed, 17 Jun 2015 17:43:31 -0700 Subject: media: Add RAPPOR metrics for media player origin URLs. - Plumb RAPPOR reporting to MediaClient. - Add origin URL report for both MSE and SRC playback. - Move metrics reporting to a central place. - Remove redundant param in Create*WebMediaPlayer*() functions. TBR=nasko@chromium.org BUG=499949 Review URL: https://codereview.chromium.org/1175383004 Cr-Commit-Position: refs/heads/master@{#334968} --- media/base/key_systems_unittest.cc | 6 ++++++ media/base/media_client.h | 7 ++++++- media/blink/webmediaplayer_impl.cc | 9 ++++----- media/blink/webmediaplayer_util.cc | 35 ++++++++++++++++++++++++++++++++++- media/blink/webmediaplayer_util.h | 6 ++++-- 5 files changed, 54 insertions(+), 9 deletions(-) (limited to 'media') diff --git a/media/base/key_systems_unittest.cc b/media/base/key_systems_unittest.cc index 1a29488..a1e95e0 100644 --- a/media/base/key_systems_unittest.cc +++ b/media/base/key_systems_unittest.cc @@ -126,6 +126,7 @@ class TestMediaClient : public MediaClient { bool IsKeySystemsUpdateNeeded() final; void AddSupportedKeySystems( std::vector* key_systems_info) override; + void RecordRapporURL(const std::string& metric, const GURL& url) final; // Helper function to test the case where IsKeySystemsUpdateNeeded() is true // after AddSupportedKeySystems() is called. @@ -177,6 +178,11 @@ void TestMediaClient::AddSupportedKeySystems( is_update_needed_ = false; } +void TestMediaClient::RecordRapporURL(const std::string& /* metric */, + const GURL& /* url */) { + NOTIMPLEMENTED(); +} + void TestMediaClient::SetKeySystemsUpdateNeeded() { is_update_needed_ = true; } diff --git a/media/base/media_client.h b/media/base/media_client.h index f6af053..4b6bef5 100644 --- a/media/base/media_client.h +++ b/media/base/media_client.h @@ -10,6 +10,7 @@ #include "media/base/key_system_info.h" #include "media/base/media_export.h" +#include "url/gurl.h" namespace media { @@ -22,7 +23,7 @@ MEDIA_EXPORT void SetMediaClient(MediaClient* media_client); // Media's embedder API should only be used by media. #if defined(MEDIA_IMPLEMENTATION) // Getter for the client. Returns NULL if no customized client is needed. -MediaClient* GetMediaClient(); +MEDIA_EXPORT MediaClient* GetMediaClient(); #endif struct MEDIA_EXPORT KeySystemInfoForUMA { @@ -65,6 +66,10 @@ class MEDIA_EXPORT MediaClient { // Adds info for supported key systems. virtual void AddSupportedKeySystems( std::vector* key_systems_info) = 0; + + // Records a domain and registry of a url to a Rappor privacy-preserving + // metric. See: https://www.chromium.org/developers/design-documents/rappor + virtual void RecordRapporURL(const std::string& metric, const GURL& url) = 0; }; } // namespace media diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc index ece98bb..aa7b073 100644 --- a/media/blink/webmediaplayer_impl.cc +++ b/media/blink/webmediaplayer_impl.cc @@ -43,6 +43,8 @@ #include "third_party/WebKit/public/platform/WebSize.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURL.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "third_party/WebKit/public/web/WebSecurityOrigin.h" @@ -211,7 +213,8 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type, DCHECK(main_task_runner_->BelongsToCurrentThread()); GURL gurl(url); - ReportMediaSchemeUma(gurl); + ReportMetrics(load_type, gurl, + GURL(frame_->document().securityOrigin().toString())); // Set subresource URL for crash reporting. base::debug::SetCrashKeyValue("subresource_url", gurl.spec()); @@ -892,10 +895,6 @@ void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { void WebMediaPlayerImpl::StartPipeline() { DCHECK(main_task_runner_->BelongsToCurrentThread()); - // Keep track if this is a MSE or non-MSE playback. - UMA_HISTOGRAM_BOOLEAN("Media.MSE.Playback", - (load_type_ == LoadTypeMediaSource)); - Demuxer::EncryptedMediaInitDataCB encrypted_media_init_data_cb = BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnEncryptedMediaInitData); diff --git a/media/blink/webmediaplayer_util.cc b/media/blink/webmediaplayer_util.cc index 1b41ee8..fc1a079 100644 --- a/media/blink/webmediaplayer_util.cc +++ b/media/blink/webmediaplayer_util.cc @@ -8,6 +8,7 @@ #include "base/metrics/histogram.h" #include "media/base/bind_to_current_loop.h" +#include "media/base/media_client.h" #include "media/base/media_keys.h" #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" @@ -106,11 +107,43 @@ URLSchemeForHistogram URLScheme(const GURL& url) { return kUnknownURLScheme; } +std::string LoadTypeToString(blink::WebMediaPlayer::LoadType load_type) { + switch (load_type) { + case blink::WebMediaPlayer::LoadTypeURL: + return "SRC"; + case blink::WebMediaPlayer::LoadTypeMediaSource: + return "MSE"; + case blink::WebMediaPlayer::LoadTypeMediaStream: + return "MS"; + } + + NOTREACHED(); + return "Unknown"; +} + } // namespace -void ReportMediaSchemeUma(const GURL& url) { +// TODO(xhwang): Call this from WebMediaPlayerMS to report metrics for +// MediaStream as well. +void ReportMetrics(blink::WebMediaPlayer::LoadType load_type, + const GURL& url, + const GURL& origin_url) { + // Report URL scheme, such as http, https, file, blob etc. UMA_HISTOGRAM_ENUMERATION("Media.URLScheme", URLScheme(url), kMaxURLScheme + 1); + + // Keep track if this is a MSE or non-MSE playback. + // TODO(xhwang): This name is not intuitive. We should have a histogram for + // all load types. + UMA_HISTOGRAM_BOOLEAN( + "Media.MSE.Playback", + load_type == blink::WebMediaPlayer::LoadTypeMediaSource); + + // Report the origin from where the media player is created. + if (GetMediaClient()) { + GetMediaClient()->RecordRapporURL( + "Media.OriginUrl." + LoadTypeToString(load_type), origin_url); + } } EmeInitDataType ConvertToEmeInitDataType( diff --git a/media/blink/webmediaplayer_util.h b/media/blink/webmediaplayer_util.h index 23fa1c7..9aaa512 100644 --- a/media/blink/webmediaplayer_util.h +++ b/media/blink/webmediaplayer_util.h @@ -32,8 +32,10 @@ blink::WebTimeRanges MEDIA_EXPORT ConvertToWebTimeRanges( blink::WebMediaPlayer::NetworkState MEDIA_EXPORT PipelineErrorToNetworkState( PipelineStatus error); -// Report the scheme of Media URIs. -void MEDIA_EXPORT ReportMediaSchemeUma(const GURL& url); +// Report various metrics to UMA and RAPPOR. +void MEDIA_EXPORT ReportMetrics(blink::WebMediaPlayer::LoadType load_type, + const GURL& url, + const GURL& origin_url); // Convert Initialization Data Types. EmeInitDataType MEDIA_EXPORT -- cgit v1.1