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

Side by Side Diff: third_party/WebKit/Source/core/html/media/AutoplayUmaHelper.cpp

Issue 2780403004: Create core/html/media/ and move auxiliary media files in it. (Closed)
Patch Set: actually add autoplay files Created 3 years, 8 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
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 "core/html/AutoplayUmaHelper.h" 5 #include "core/html/media/AutoplayUmaHelper.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ElementVisibilityObserver.h" 8 #include "core/dom/ElementVisibilityObserver.h"
9 #include "core/events/Event.h" 9 #include "core/events/Event.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
11 #include "core/html/HTMLMediaElement.h" 11 #include "core/html/HTMLMediaElement.h"
12 #include "platform/Histogram.h" 12 #include "platform/Histogram.h"
13 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
14 #include "wtf/CurrentTime.h" 14 #include "wtf/CurrentTime.h"
15 15
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return; 225 return;
226 226
227 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true); 227 maybeStopRecordingMutedVideoPlayMethodBecomeVisible(true);
228 } 228 }
229 229
230 void AutoplayUmaHelper::onVisibilityChangedForMutedVideoOffscreenDuration( 230 void AutoplayUmaHelper::onVisibilityChangedForMutedVideoOffscreenDuration(
231 bool isVisible) { 231 bool isVisible) {
232 if (isVisible == m_isVisible) 232 if (isVisible == m_isVisible)
233 return; 233 return;
234 234
235 if (isVisible) 235 if (isVisible) {
236 m_mutedVideoAutoplayOffscreenDurationMS += 236 m_mutedVideoAutoplayOffscreenDurationMS +=
237 static_cast<int64_t>(monotonicallyIncreasingTimeMS()) - 237 static_cast<int64_t>(monotonicallyIncreasingTimeMS()) -
238 m_mutedVideoAutoplayOffscreenStartTimeMS; 238 m_mutedVideoAutoplayOffscreenStartTimeMS;
239 else 239 } else {
240 m_mutedVideoAutoplayOffscreenStartTimeMS = 240 m_mutedVideoAutoplayOffscreenStartTimeMS =
241 static_cast<int64_t>(monotonicallyIncreasingTimeMS()); 241 static_cast<int64_t>(monotonicallyIncreasingTimeMS());
242 }
242 243
243 m_isVisible = isVisible; 244 m_isVisible = isVisible;
244 } 245 }
245 246
246 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext, 247 void AutoplayUmaHelper::handleEvent(ExecutionContext* executionContext,
247 Event* event) { 248 Event* event) {
248 if (event->type() == EventTypeNames::playing) 249 if (event->type() == EventTypeNames::playing)
249 handlePlayingEvent(); 250 handlePlayingEvent();
250 else if (event->type() == EventTypeNames::pause) 251 else if (event->type() == EventTypeNames::pause)
251 handlePauseEvent(); 252 handlePauseEvent();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 wrapWeakPersistent(this))); 320 wrapWeakPersistent(this)));
320 m_mutedVideoOffscreenDurationVisibilityObserver->start(); 321 m_mutedVideoOffscreenDurationVisibilityObserver->start();
321 m_element->addEventListener(EventTypeNames::pause, this, false); 322 m_element->addEventListener(EventTypeNames::pause, this, false);
322 setContext(&m_element->document()); 323 setContext(&m_element->document());
323 } 324 }
324 325
325 void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() { 326 void AutoplayUmaHelper::maybeStopRecordingMutedVideoOffscreenDuration() {
326 if (!m_mutedVideoOffscreenDurationVisibilityObserver) 327 if (!m_mutedVideoOffscreenDurationVisibilityObserver)
327 return; 328 return;
328 329
329 if (!m_isVisible) 330 if (!m_isVisible) {
330 m_mutedVideoAutoplayOffscreenDurationMS += 331 m_mutedVideoAutoplayOffscreenDurationMS +=
331 static_cast<int64_t>(monotonicallyIncreasingTimeMS()) - 332 static_cast<int64_t>(monotonicallyIncreasingTimeMS()) -
332 m_mutedVideoAutoplayOffscreenStartTimeMS; 333 m_mutedVideoAutoplayOffscreenStartTimeMS;
334 }
333 335
334 // Since histograms uses int32_t, the duration needs to be limited to 336 // Since histograms uses int32_t, the duration needs to be limited to
335 // std::numeric_limits<int32_t>::max(). 337 // std::numeric_limits<int32_t>::max().
336 int32_t boundedTime = static_cast<int32_t>( 338 int32_t boundedTime = static_cast<int32_t>(
337 std::min<int64_t>(m_mutedVideoAutoplayOffscreenDurationMS, 339 std::min<int64_t>(m_mutedVideoAutoplayOffscreenDurationMS,
338 std::numeric_limits<int32_t>::max())); 340 std::numeric_limits<int32_t>::max()));
339 341
340 DCHECK(m_sources.count(AutoplaySource::Method)); 342 DCHECK(m_sources.count(AutoplaySource::Method));
341 343
342 DEFINE_STATIC_LOCAL( 344 DEFINE_STATIC_LOCAL(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 388
387 DEFINE_TRACE(AutoplayUmaHelper) { 389 DEFINE_TRACE(AutoplayUmaHelper) {
388 EventListener::trace(visitor); 390 EventListener::trace(visitor);
389 ContextLifecycleObserver::trace(visitor); 391 ContextLifecycleObserver::trace(visitor);
390 visitor->trace(m_element); 392 visitor->trace(m_element);
391 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver); 393 visitor->trace(m_mutedVideoPlayMethodVisibilityObserver);
392 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver); 394 visitor->trace(m_mutedVideoOffscreenDurationVisibilityObserver);
393 } 395 }
394 396
395 } // namespace blink 397 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698