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

Side by Side Diff: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp

Issue 2614913005: Add UseCounters for navigator.vibrate usage compared to site engagement. (Closed)
Patch Set: Address comment Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2012 Samsung Electronics 2 * Copyright (C) 2012 Samsung Electronics
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 11 matching lines...) Expand all
22 #include "bindings/core/v8/ConditionalFeatures.h" 22 #include "bindings/core/v8/ConditionalFeatures.h"
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/frame/LocalDOMWindow.h" 24 #include "core/frame/LocalDOMWindow.h"
25 #include "core/frame/LocalFrame.h" 25 #include "core/frame/LocalFrame.h"
26 #include "core/frame/Navigator.h" 26 #include "core/frame/Navigator.h"
27 #include "core/frame/UseCounter.h" 27 #include "core/frame/UseCounter.h"
28 #include "core/page/Page.h" 28 #include "core/page/Page.h"
29 #include "modules/vibration/VibrationController.h" 29 #include "modules/vibration/VibrationController.h"
30 #include "platform/Histogram.h" 30 #include "platform/Histogram.h"
31 #include "platform/UserGestureIndicator.h" 31 #include "platform/UserGestureIndicator.h"
32 #include "public/platform/site_engagement.mojom-blink.h"
32 33
33 namespace blink { 34 namespace blink {
34 35
35 NavigatorVibration::NavigatorVibration(Navigator& navigator) 36 NavigatorVibration::NavigatorVibration(Navigator& navigator)
36 : ContextLifecycleObserver(navigator.frame()->document()) {} 37 : ContextLifecycleObserver(navigator.frame()->document()) {}
37 38
38 NavigatorVibration::~NavigatorVibration() {} 39 NavigatorVibration::~NavigatorVibration() {}
39 40
40 // static 41 // static
41 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) { 42 NavigatorVibration& NavigatorVibration::from(Navigator& navigator) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 118 }
118 } else { 119 } else {
119 if (userGesture) 120 if (userGesture)
120 type = NavigatorVibrationType::MainFrameWithUserGesture; 121 type = NavigatorVibrationType::MainFrameWithUserGesture;
121 else 122 else
122 type = NavigatorVibrationType::MainFrameNoUserGesture; 123 type = NavigatorVibrationType::MainFrameNoUserGesture;
123 } 124 }
124 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, 125 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram,
125 ("Vibration.Context", NavigatorVibrationType::EnumMax)); 126 ("Vibration.Context", NavigatorVibrationType::EnumMax));
126 NavigatorVibrateHistogram.count(type); 127 NavigatorVibrateHistogram.count(type);
128
129 switch (frame.document()->getEngagementLevel()) {
130 case mojom::blink::EngagementLevel::NONE:
131 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementNone);
132 break;
133 case mojom::blink::EngagementLevel::MINIMAL:
134 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMinimal);
135 break;
136 case mojom::blink::EngagementLevel::LOW:
137 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementLow);
138 break;
139 case mojom::blink::EngagementLevel::MEDIUM:
140 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMedium);
141 break;
142 case mojom::blink::EngagementLevel::HIGH:
143 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementHigh);
144 break;
145 case mojom::blink::EngagementLevel::MAX:
146 UseCounter::count(&frame, UseCounter::NavigatorVibrateEngagementMax);
147 break;
148 }
127 } 149 }
128 150
129 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) { 151 VibrationController* NavigatorVibration::controller(const LocalFrame& frame) {
130 if (!m_controller) 152 if (!m_controller)
131 m_controller = new VibrationController(*frame.document()); 153 m_controller = new VibrationController(*frame.document());
132 154
133 return m_controller.get(); 155 return m_controller.get();
134 } 156 }
135 157
136 void NavigatorVibration::contextDestroyed() { 158 void NavigatorVibration::contextDestroyed() {
137 if (m_controller) { 159 if (m_controller) {
138 m_controller->cancel(); 160 m_controller->cancel();
139 m_controller = nullptr; 161 m_controller = nullptr;
140 } 162 }
141 } 163 }
142 164
143 DEFINE_TRACE(NavigatorVibration) { 165 DEFINE_TRACE(NavigatorVibration) {
144 visitor->trace(m_controller); 166 visitor->trace(m_controller);
145 Supplement<Navigator>::trace(visitor); 167 Supplement<Navigator>::trace(visitor);
146 ContextLifecycleObserver::trace(visitor); 168 ContextLifecycleObserver::trace(visitor);
147 } 169 }
148 170
149 } // namespace blink 171 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | third_party/WebKit/Source/modules/vibration/VibrationController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698