| OLD | NEW |
| 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 #ifndef AutoplayUmaHelper_h | 5 #ifndef AutoplayUmaHelper_h |
| 6 #define AutoplayUmaHelper_h | 6 #define AutoplayUmaHelper_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/dom/ContextLifecycleObserver.h" |
| 8 #include "core/events/EventListener.h" | 10 #include "core/events/EventListener.h" |
| 9 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 10 | 12 |
| 11 namespace blink { | 13 namespace blink { |
| 12 | 14 |
| 13 // These values are used for histograms. Do not reorder. | 15 // These values are used for histograms. Do not reorder. |
| 14 enum class AutoplaySource { | 16 enum class AutoplaySource { |
| 15 // Autoplay comes from HTMLMediaElement `autoplay` attribute. | 17 // Autoplay comes from HTMLMediaElement `autoplay` attribute. |
| 16 Attribute = 0, | 18 Attribute = 0, |
| 17 // Autoplay comes from `play()` method. | 19 // Autoplay comes from `play()` method. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 33 AutoplayBlockedReasonSetting = 1, | 35 AutoplayBlockedReasonSetting = 1, |
| 34 AutoplayBlockedReasonDataSaverAndSetting = 2, | 36 AutoplayBlockedReasonDataSaverAndSetting = 2, |
| 35 // Keey at the end. | 37 // Keey at the end. |
| 36 AutoplayBlockedReasonMax = 3 | 38 AutoplayBlockedReasonMax = 3 |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 class Document; | 41 class Document; |
| 40 class ElementVisibilityObserver; | 42 class ElementVisibilityObserver; |
| 41 class HTMLMediaElement; | 43 class HTMLMediaElement; |
| 42 | 44 |
| 43 class AutoplayUmaHelper final : public EventListener { | 45 class CORE_EXPORT AutoplayUmaHelper : public EventListener, |
| 46 public ContextLifecycleObserver { |
| 47 USING_GARBAGE_COLLECTED_MIXIN(AutoplayUmaHelper); |
| 48 |
| 44 public: | 49 public: |
| 45 static AutoplayUmaHelper* create(HTMLMediaElement*); | 50 static AutoplayUmaHelper* create(HTMLMediaElement*); |
| 46 | 51 |
| 47 ~AutoplayUmaHelper(); | 52 ~AutoplayUmaHelper(); |
| 48 | 53 |
| 49 bool operator==(const EventListener&) const override; | 54 bool operator==(const EventListener&) const override; |
| 50 | 55 |
| 56 void contextDestroyed() override; |
| 57 |
| 51 void onAutoplayInitiated(AutoplaySource); | 58 void onAutoplayInitiated(AutoplaySource); |
| 52 | 59 |
| 53 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); | 60 void recordAutoplayUnmuteStatus(AutoplayUnmuteActionStatus); |
| 54 | 61 |
| 55 void didMoveToNewDocument(Document& oldDocument); | 62 void didMoveToNewDocument(Document& oldDocument); |
| 56 | 63 |
| 57 bool isVisible() const { return m_isVisible; } | 64 bool isVisible() const { return m_isVisible; } |
| 58 | 65 |
| 59 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } | 66 bool hasSource() const { return m_source != AutoplaySource::NumberOfSources; } |
| 60 | 67 |
| 61 DECLARE_VIRTUAL_TRACE(); | 68 DECLARE_VIRTUAL_TRACE(); |
| 62 | 69 |
| 63 private: | 70 private: |
| 71 friend class MockAutoplayUmaHelper; |
| 72 |
| 64 explicit AutoplayUmaHelper(HTMLMediaElement*); | 73 explicit AutoplayUmaHelper(HTMLMediaElement*); |
| 65 | |
| 66 void handleEvent(ExecutionContext*, Event*) override; | 74 void handleEvent(ExecutionContext*, Event*) override; |
| 67 | |
| 68 void handlePlayingEvent(); | 75 void handlePlayingEvent(); |
| 69 void handlePauseEvent(); | 76 void handlePauseEvent(); |
| 70 void handleUnloadEvent(); | 77 virtual void handleContextDestroyed(); // Make virtual for testing. |
| 71 | 78 |
| 72 void maybeUnregisterUnloadListener(); | 79 void maybeUnregisterContextDestroyedObserver(); |
| 73 | 80 |
| 74 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); | 81 void maybeStartRecordingMutedVideoPlayMethodBecomeVisible(); |
| 75 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); | 82 void maybeStopRecordingMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 76 | 83 |
| 77 void maybeStartRecordingMutedVideoOffscreenDuration(); | 84 void maybeStartRecordingMutedVideoOffscreenDuration(); |
| 78 void maybeStopRecordingMutedVideoOffscreenDuration(); | 85 void maybeStopRecordingMutedVideoOffscreenDuration(); |
| 79 | 86 |
| 80 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); | 87 void onVisibilityChangedForMutedVideoOffscreenDuration(bool isVisibile); |
| 81 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); | 88 void onVisibilityChangedForMutedVideoPlayMethodBecomeVisible(bool isVisible); |
| 82 | 89 |
| 83 bool shouldListenToUnloadEvent() const; | 90 bool shouldListenToContextDestroyed() const; |
| 84 | 91 |
| 85 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid | 92 // The autoplay source. Use AutoplaySource::NumberOfSources for invalid |
| 86 // source. | 93 // source. |
| 87 AutoplaySource m_source; | 94 AutoplaySource m_source; |
| 88 // The media element this UMA helper is attached to. |m_element| owns |this|. | 95 // The media element this UMA helper is attached to. |m_element| owns |this|. |
| 89 Member<HTMLMediaElement> m_element; | 96 Member<HTMLMediaElement> m_element; |
| 90 | 97 |
| 91 // The observer is used to observe whether a muted video autoplaying by play() | 98 // The observer is used to observe whether a muted video autoplaying by play() |
| 92 // method become visible at some point. | 99 // method become visible at some point. |
| 93 // The UMA is pending for recording as long as this observer is non-null. | 100 // The UMA is pending for recording as long as this observer is non-null. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 111 // The observer is used to observer an autoplaying muted video changing it's | 118 // The observer is used to observer an autoplaying muted video changing it's |
| 112 // visibility, which is used for offscreen duration UMA. The UMA is pending | 119 // visibility, which is used for offscreen duration UMA. The UMA is pending |
| 113 // for recording as long as this observer is non-null. | 120 // for recording as long as this observer is non-null. |
| 114 Member<ElementVisibilityObserver> | 121 Member<ElementVisibilityObserver> |
| 115 m_mutedVideoOffscreenDurationVisibilityObserver; | 122 m_mutedVideoOffscreenDurationVisibilityObserver; |
| 116 }; | 123 }; |
| 117 | 124 |
| 118 } // namespace blink | 125 } // namespace blink |
| 119 | 126 |
| 120 #endif // AutoplayUmaHelper_h | 127 #endif // AutoplayUmaHelper_h |
| OLD | NEW |