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

Unified Diff: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp

Issue 2082463002: Measure the usage of navigator.vibrate in for user gesture & subframe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add back NavigatorVibrateSubFrame UserCounter since we decide to go ahead to remove vibrate from if… Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
diff --git a/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp b/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
index ae5ca2c5c3622862bdb791b90a39b4e520bbbc8e..0a560cf63bccb907c90ba4708aa069737906d161 100644
--- a/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
+++ b/third_party/WebKit/Source/modules/vibration/NavigatorVibration.cpp
@@ -24,6 +24,8 @@
#include "core/frame/UseCounter.h"
#include "core/page/Page.h"
#include "modules/vibration/VibrationController.h"
+#include "platform/Histogram.h"
+#include "platform/UserGestureIndicator.h"
namespace blink {
@@ -70,10 +72,7 @@ bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p
// reference to |window| or |navigator| was retained in another window.
if (!frame)
return false;
-
- UseCounter::count(frame, UseCounter::NavigatorVibrate);
- if (!frame->isMainFrame())
- UseCounter::count(frame, UseCounter::NavigatorVibrateSubFrame);
+ collectHistogramMetrics(*frame);
DCHECK(frame->document());
DCHECK(frame->page());
@@ -84,6 +83,35 @@ bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p
return NavigatorVibration::from(navigator).controller()->vibrate(pattern);
}
+// static
+void NavigatorVibration::collectHistogramMetrics(const LocalFrame& frame)
+{
+ NavigatorVibrationType type;
+ bool userGesture = UserGestureIndicator::processingUserGesture();
+ UseCounter::count(&frame, UseCounter::NavigatorVibrate);
+ if (!frame.isMainFrame()) {
+ UseCounter::count(&frame, UseCounter::NavigatorVibrateSubFrame);
+ if (frame.isCrossOrigin()) {
+ if (userGesture)
+ type = NavigatorVibrationType::CrossOriginSubFrameWithUserGesture;
+ else
+ type = NavigatorVibrationType::CrossOriginSubFrameNoUserGesture;
+ } else {
+ if (userGesture)
+ type = NavigatorVibrationType::SameOriginSubFrameWithUserGesture;
+ else
+ type = NavigatorVibrationType::SameOriginSubFrameNoUserGesture;
+ }
+ } else {
+ if (userGesture)
+ type = NavigatorVibrationType::MainFrameWithUserGesture;
+ else
+ type = NavigatorVibrationType::MainFrameNoUserGesture;
+ }
+ DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibration.Context", NavigatorVibrationType::EnumMax));
+ NavigatorVibrateHistogram.count(type);
+}
+
VibrationController* NavigatorVibration::controller()
{
if (!m_controller && frame())
« no previous file with comments | « third_party/WebKit/Source/modules/vibration/NavigatorVibration.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698