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

Side by Side 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: Keep depcreated UserCounter metrics and suffix the labels with (obsolete). Created 4 years, 5 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "modules/vibration/NavigatorVibration.h" 20 #include "modules/vibration/NavigatorVibration.h"
21 21
22 #include "core/frame/LocalFrame.h" 22 #include "core/frame/LocalFrame.h"
23 #include "core/frame/Navigator.h" 23 #include "core/frame/Navigator.h"
24 #include "core/frame/UseCounter.h" 24 #include "core/frame/UseCounter.h"
Michael van Ouwerkerk 2016/06/28 11:45:52 Delete this as it is no longer used.
25 #include "core/page/Page.h" 25 #include "core/page/Page.h"
26 #include "modules/vibration/VibrationController.h" 26 #include "modules/vibration/VibrationController.h"
27 #include "platform/Histogram.h"
28 #include "platform/UserGestureIndicator.h"
27 29
28 namespace blink { 30 namespace blink {
29 31
30 NavigatorVibration::NavigatorVibration(Navigator& navigator) 32 NavigatorVibration::NavigatorVibration(Navigator& navigator)
31 : DOMWindowProperty(navigator.frame()) 33 : DOMWindowProperty(navigator.frame())
32 { 34 {
33 } 35 }
34 36
35 NavigatorVibration::~NavigatorVibration() 37 NavigatorVibration::~NavigatorVibration()
36 { 38 {
(...skipping 27 matching lines...) Expand all
64 // static 66 // static
65 bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p attern) 67 bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p attern)
66 { 68 {
67 LocalFrame* frame = navigator.frame(); 69 LocalFrame* frame = navigator.frame();
68 70
69 // There will be no frame if the window has been closed, but a JavaScript 71 // There will be no frame if the window has been closed, but a JavaScript
70 // reference to |window| or |navigator| was retained in another window. 72 // reference to |window| or |navigator| was retained in another window.
71 if (!frame) 73 if (!frame)
72 return false; 74 return false;
73 75
74 UseCounter::count(frame, UseCounter::NavigatorVibrate); 76 const unsigned userGestureBit = 0x1;
Michael van Ouwerkerk 2016/06/28 11:45:53 I don't find this section very readable, using bit
75 if (!frame->isMainFrame()) 77 const unsigned subFrameBit = 0x2;
76 UseCounter::count(frame, UseCounter::NavigatorVibrateSubFrame); 78 const unsigned crossOriginFrameBit = 0x4;
79 unsigned vibrateParams = 0;
80 if (UserGestureIndicator::processingUserGesture())
81 vibrateParams |= userGestureBit;
82 if (!frame->isMainFrame()) {
83 if (frame->isCrossOrigin())
84 vibrateParams |= crossOriginFrameBit;
85 else
86 vibrateParams |= subFrameBit;
87 }
88 DEFINE_STATIC_LOCAL(EnumerationHistogram, NavigatorVibrateHistogram, ("Vibra tion.Context", NavigatorVibrationType::EnumMax));
89 NavigatorVibrateHistogram.count(static_cast<NavigatorVibrationType>(vibrateP arams));
77 90
78 DCHECK(frame->document()); 91 DCHECK(frame->document());
79 DCHECK(frame->page()); 92 DCHECK(frame->page());
80 93
81 if (!frame->page()->isPageVisible()) 94 if (!frame->page()->isPageVisible())
82 return false; 95 return false;
83 96
84 return NavigatorVibration::from(navigator).controller()->vibrate(pattern); 97 return NavigatorVibration::from(navigator).controller()->vibrate(pattern);
85 } 98 }
86 99
(...skipping 14 matching lines...) Expand all
101 } 114 }
102 115
103 DEFINE_TRACE(NavigatorVibration) 116 DEFINE_TRACE(NavigatorVibration)
104 { 117 {
105 visitor->trace(m_controller); 118 visitor->trace(m_controller);
106 Supplement<Navigator>::trace(visitor); 119 Supplement<Navigator>::trace(visitor);
107 DOMWindowProperty::trace(visitor); 120 DOMWindowProperty::trace(visitor);
108 } 121 }
109 122
110 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698