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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControlsOrientationLockDelegate.cpp

Issue 2581603003: Media: add metrics for orientation lock when video goes fullscreen. (Closed)
Patch Set: Created 4 years 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 | « no previous file | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "MediaControlsOrientationLockDelegate.h" 5 #include "MediaControlsOrientationLockDelegate.h"
6 6
7 #include "core/events/Event.h" 7 #include "core/events/Event.h"
8 #include "core/frame/ScreenOrientationController.h" 8 #include "core/frame/ScreenOrientationController.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/page/ChromeClient.h" 10 #include "core/page/ChromeClient.h"
11 #include "platform/Histogram.h"
11 #include "public/platform/WebScreenInfo.h" 12 #include "public/platform/WebScreenInfo.h"
12 #include "public/platform/modules/screen_orientation/WebLockOrientationCallback. h" 13 #include "public/platform/modules/screen_orientation/WebLockOrientationCallback. h"
13 14
14 namespace blink { 15 namespace blink {
15 16
16 namespace { 17 namespace {
17 18
19 // These values are used for histograms. Do not reorder.
20 enum class MetadataAvailabilityMetrics {
21 Available = 0, // Available when lock was attempted.
22 Missing = 1, // Missing when lock was attempted.
23 Received = 2, // Received after being missing in order to lock.
24
25 // Keep at the end.
26 Max = 3
27 };
28
29 // These values are used for histograms. Do not reorder.
30 enum class LockResultMetrics {
31 AlreadyLocked = 0, // Frame already has a lock.
32 Portrait = 1, // Locked to portrait.
33 Landscape = 2, // Locked to landscape.
34
35 // Keep at the end.
36 Max = 3
37 };
38
39 void recordMetadataAvailability(MetadataAvailabilityMetrics metrics) {
40 DEFINE_STATIC_LOCAL(
41 EnumerationHistogram, metadataHistogram,
42 ("Media.Video.FullscreenOrientationLock.MetadataAvailability",
43 static_cast<int>(MetadataAvailabilityMetrics::Max)));
44 metadataHistogram.count(static_cast<int>(metrics));
45 }
46
47 void recordLockResult(LockResultMetrics metrics) {
48 DEFINE_STATIC_LOCAL(EnumerationHistogram, lockResultHistogram,
49 ("Media.Video.FullscreenOrientationLock.LockResult",
50 static_cast<int>(LockResultMetrics::Max)));
51 lockResultHistogram.count(static_cast<int>(metrics));
52 }
53
18 // WebLockOrientationCallback implementation that will not react to a success 54 // WebLockOrientationCallback implementation that will not react to a success
19 // nor a failure. 55 // nor a failure.
20 class DummyScreenOrientationCallback : public WebLockOrientationCallback { 56 class DummyScreenOrientationCallback : public WebLockOrientationCallback {
21 public: 57 public:
22 void onSuccess() override {} 58 void onSuccess() override {}
23 void onError(WebLockOrientationError) override {} 59 void onError(WebLockOrientationError) override {}
24 }; 60 };
25 61
26 } // anonymous namespace 62 } // anonymous namespace
27 63
28 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate( 64 MediaControlsOrientationLockDelegate::MediaControlsOrientationLockDelegate(
29 HTMLVideoElement& video) 65 HTMLVideoElement& video)
30 : EventListener(CPPEventListenerType), m_videoElement(video) { 66 : EventListener(CPPEventListenerType), m_videoElement(video) {
31 document().addEventListener(EventTypeNames::fullscreenchange, this, true); 67 document().addEventListener(EventTypeNames::fullscreenchange, this, true);
32 videoElement().addEventListener(EventTypeNames::webkitfullscreenchange, this, 68 videoElement().addEventListener(EventTypeNames::webkitfullscreenchange, this,
33 true); 69 true);
34 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true); 70 videoElement().addEventListener(EventTypeNames::loadedmetadata, this, true);
35 } 71 }
36 72
37 bool MediaControlsOrientationLockDelegate::operator==( 73 bool MediaControlsOrientationLockDelegate::operator==(
38 const EventListener& other) const { 74 const EventListener& other) const {
39 return this == &other; 75 return this == &other;
40 } 76 }
41 77
42 void MediaControlsOrientationLockDelegate::maybeLockOrientation() { 78 void MediaControlsOrientationLockDelegate::maybeLockOrientation() {
43 DCHECK(m_state != State::MaybeLockedFullscreen); 79 DCHECK(m_state != State::MaybeLockedFullscreen);
44 80
45 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) { 81 if (videoElement().getReadyState() == HTMLMediaElement::kHaveNothing) {
82 recordMetadataAvailability(MetadataAvailabilityMetrics::Missing);
46 m_state = State::PendingMetadata; 83 m_state = State::PendingMetadata;
47 return; 84 return;
48 } 85 }
49 86
87 if (m_state == State::PendingMetadata)
88 recordMetadataAvailability(MetadataAvailabilityMetrics::Received);
89 else
90 recordMetadataAvailability(MetadataAvailabilityMetrics::Available);
91
50 m_state = State::MaybeLockedFullscreen; 92 m_state = State::MaybeLockedFullscreen;
51 93
52 if (!document().frame()) 94 if (!document().frame())
53 return; 95 return;
54 96
55 auto controller = ScreenOrientationController::from(*document().frame()); 97 auto controller = ScreenOrientationController::from(*document().frame());
56 if (controller->maybeHasActiveLock()) 98 if (controller->maybeHasActiveLock()) {
99 recordLockResult(LockResultMetrics::AlreadyLocked);
57 return; 100 return;
101 }
58 102
59 controller->lock(computeOrientationLock(), 103 WebScreenOrientationLockType orientationLock = computeOrientationLock();
104 controller->lock(orientationLock,
60 WTF::wrapUnique(new DummyScreenOrientationCallback)); 105 WTF::wrapUnique(new DummyScreenOrientationCallback));
61 m_shouldUnlockOrientation = true; 106 m_shouldUnlockOrientation = true;
107
108 if (orientationLock == WebScreenOrientationLockLandscape)
109 recordLockResult(LockResultMetrics::Landscape);
110 else
111 recordLockResult(LockResultMetrics::Portrait);
62 } 112 }
63 113
64 void MediaControlsOrientationLockDelegate::maybeUnlockOrientation() { 114 void MediaControlsOrientationLockDelegate::maybeUnlockOrientation() {
65 DCHECK(m_state != State::PendingFullscreen); 115 DCHECK(m_state != State::PendingFullscreen);
66 116
67 m_state = State::PendingFullscreen; 117 m_state = State::PendingFullscreen;
68 118
69 if (!m_shouldUnlockOrientation) 119 if (!m_shouldUnlockOrientation)
70 return; 120 return;
71 121
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 NOTREACHED(); 192 NOTREACHED();
143 return WebScreenOrientationLockLandscape; 193 return WebScreenOrientationLockLandscape;
144 } 194 }
145 195
146 DEFINE_TRACE(MediaControlsOrientationLockDelegate) { 196 DEFINE_TRACE(MediaControlsOrientationLockDelegate) {
147 EventListener::trace(visitor); 197 EventListener::trace(visitor);
148 visitor->trace(m_videoElement); 198 visitor->trace(m_videoElement);
149 } 199 }
150 200
151 } // namespace blink 201 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698