summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-07 21:32:13 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-07 21:32:13 +0000
commit6a4d7f6028cb493847f51128adf26686c5926d57 (patch)
treeec81722c55682f0fa8b6d9cef5bab31ceecdc1b7
parent33662e580e090d3e5909ed87e124434ac37e1e23 (diff)
downloadchromium_src-6a4d7f6028cb493847f51128adf26686c5926d57.zip
chromium_src-6a4d7f6028cb493847f51128adf26686c5926d57.tar.gz
chromium_src-6a4d7f6028cb493847f51128adf26686c5926d57.tar.bz2
Track input latency with UMA stats
BUG=None TEST=None Review URL: https://codereview.chromium.org/11591006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175386 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/drag_drop/drag_drop_controller.cc12
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc12
-rw-r--r--ash/wm/custom_frame_view_ash_unittest.cc11
-rw-r--r--ash/wm/system_gesture_event_filter_unittest.cc35
-rw-r--r--ash/wm/window_manager_unittest.cc3
-rw-r--r--chrome/browser/ui/panels/panel_browsertest.cc4
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc7
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura_unittest.cc37
-rw-r--r--content/renderer/render_widget.cc61
-rw-r--r--ui/aura/gestures/gesture_recognizer_unittest.cc3
-rw-r--r--ui/aura/test/event_generator.cc21
-rw-r--r--ui/aura/window_unittest.cc3
-rw-r--r--ui/base/events/event.cc116
-rw-r--r--ui/base/events/event.h1
-rw-r--r--ui/base/events/event_utils.cc5
-rw-r--r--ui/base/events/event_utils.h4
-rw-r--r--ui/base/gestures/gesture_recognizer_impl.cc7
-rw-r--r--ui/views/corewm/compound_event_filter_unittest.cc3
18 files changed, 245 insertions, 100 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index 5d1611e..77fbd79 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -21,6 +21,7 @@
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
@@ -64,9 +65,14 @@ gfx::Rect AdjustDragImageBoundsForScaleAndOffset(
void DispatchGestureEndToWindow(aura::Window* window) {
if (window && window->delegate()) {
- ui::GestureEvent gesture_end(ui::ET_GESTURE_END, 0, 0, 0,
- base::Time::Now() - base::Time::FromDoubleT(0),
- ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 0);
+ ui::GestureEvent gesture_end(
+ ui::ET_GESTURE_END,
+ 0,
+ 0,
+ 0,
+ ui::EventTimeForNow(),
+ ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0),
+ 0);
window->delegate()->OnGestureEvent(&gesture_end);
}
}
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index 2af2905..f52893a 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -19,6 +19,7 @@
#include "ui/base/dragdrop/drag_utils.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_types.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/image/image_skia_rep.h"
@@ -266,9 +267,14 @@ void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) {
}
void DispatchGesture(ui::EventType gesture_type, gfx::Point location) {
- ui::GestureEvent gesture_event(gesture_type, location.x(), location.y(), 0,
- base::Time::NowFromSystemTime() - base::Time(),
- ui::GestureEventDetails(gesture_type, 0, 0), 1);
+ ui::GestureEvent gesture_event(
+ gesture_type,
+ location.x(),
+ location.y(),
+ 0,
+ ui::EventTimeForNow(),
+ ui::GestureEventDetails(gesture_type, 0, 0),
+ 1);
Shell::GetPrimaryRootWindow()->DispatchGestureEvent(&gesture_event);
}
diff --git a/ash/wm/custom_frame_view_ash_unittest.cc b/ash/wm/custom_frame_view_ash_unittest.cc
index 5900ae5..f81d299 100644
--- a/ash/wm/custom_frame_view_ash_unittest.cc
+++ b/ash/wm/custom_frame_view_ash_unittest.cc
@@ -18,6 +18,7 @@
#include "ui/aura/test/event_generator.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_configuration.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/test/test_views_delegate.h"
@@ -474,13 +475,17 @@ TEST_F(CustomFrameViewAshTest, MaximizeTap) {
ui::GestureConfiguration::set_default_radius(0);
const int kTouchId = 2;
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, button_pos, kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ button_pos,
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
button_pos.Offset(9, 8);
ui::TouchEvent release(
- ui::ET_TOUCH_RELEASED, button_pos, kTouchId,
+ ui::ET_TOUCH_RELEASED,
+ button_pos,
+ kTouchId,
press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc
index fa93f8f..abde0e6 100644
--- a/ash/wm/system_gesture_event_filter_unittest.cc
+++ b/ash/wm/system_gesture_event_filter_unittest.cc
@@ -25,6 +25,7 @@
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_windows.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/screen.h"
@@ -243,8 +244,10 @@ TEST_F(SystemGestureEventFilterTest, TapOutsideRootWindow) {
const int kTouchId = 5;
// A touch outside the root window will be associated with the root window
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(-10, -10), kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ gfx::Point(-10, -10),
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
scoped_ptr<ui::GestureEvent> event(CreateGesture(
@@ -278,7 +281,7 @@ void MoveToDeviceControlBezelStartPosition(
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
gfx::Point(-10, ypos + ypos_half),
touch_id,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
// There is a noise filter which will require several calls before it
@@ -401,9 +404,10 @@ TEST_F(SystemGestureEventFilterTest, DeviceControl) {
EXPECT_TRUE(consumed);
EXPECT_EQ(2, delegate->handle_percent_count());
- ui::TouchEvent release(
- ui::ET_TOUCH_RELEASED, gfx::Point(2 * xpos, ypos + ypos_half), kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
+ gfx::Point(2 * xpos, ypos + ypos_half),
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
// Check that huge changes will be interpreted as noise as well.
@@ -464,9 +468,9 @@ TEST_F(SystemGestureEventFilterTest, ApplicationControl) {
// Get a target for kTouchId
ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
- gfx::Point(-10, ypos + ypos_half),
- kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ gfx::Point(-10, ypos + ypos_half),
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
scoped_ptr<ui::GestureEvent> event1(CreateGesture(
@@ -514,9 +518,10 @@ TEST_F(SystemGestureEventFilterTest, ApplicationControl) {
EXPECT_TRUE(consumed);
EXPECT_EQ(ash::wm::GetActiveWindow(), active_window);
- ui::TouchEvent release(
- ui::ET_TOUCH_RELEASED, gfx::Point(2 * xpos, ypos + ypos_half), kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
+ gfx::Point(2 * xpos, ypos + ypos_half),
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
// Remove the launcher items again.
@@ -546,8 +551,10 @@ TEST_F(SystemGestureEventFilterTest, LongPressAffordanceStateOnCaptureLoss) {
EXPECT_TRUE(window1->HasCapture());
// Send touch event to first window.
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ gfx::Point(10, 10),
+ kTouchId,
+ ui::EventTimeForNow());
root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
EXPECT_TRUE(window1->HasCapture());
diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc
index 1f7bd1b..bf1317a 100644
--- a/ash/wm/window_manager_unittest.cc
+++ b/ash/wm/window_manager_unittest.cc
@@ -22,6 +22,7 @@
#include "ui/aura/test/test_windows.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/screen.h"
#include "ui/views/corewm/compound_event_filter.h"
@@ -31,7 +32,7 @@
namespace {
base::TimeDelta getTime() {
- return base::Time::NowFromSystemTime() - base::Time();
+ return ui::EventTimeForNow();
}
// A slightly changed TestEventHandler which can be configured to return a
diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc
index cdbc11b..e81e15b 100644
--- a/chrome/browser/ui/panels/panel_browsertest.cc
+++ b/chrome/browser/ui/panels/panel_browsertest.cc
@@ -41,6 +41,7 @@
#include "extensions/common/constants.h"
#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/events/event_utils.h"
#include "ui/gfx/screen.h"
using content::WebContents;
@@ -1720,12 +1721,13 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) {
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
#if defined(USE_AURA)
+ double now = ui::EventTimeForNow().InSecondsF();
content::NativeWebKeyboardEvent key_event(
ui::ET_KEY_PRESSED,
false,
ui::VKEY_W,
ui::EF_CONTROL_DOWN,
- base::Time::Now().ToDoubleT());
+ now);
#elif defined(OS_WIN)
::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 };
content::NativeWebKeyboardEvent key_event(key_msg);
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index 49ef41b..4b86282 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -43,6 +43,7 @@
#include "ui/aura/window_tracker.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_recognizer.h"
#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h"
@@ -1150,12 +1151,13 @@ void RenderWidgetHostViewAura::InsertChar(char16 ch, int flags) {
}
if (host_) {
+ double now = ui::EventTimeForNow().InSecondsF();
// Send a WebKit::WebInputEvent::Char event to |host_|.
NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
true /* is_char */,
ch,
flags,
- base::Time::Now().ToDoubleT());
+ now);
host_->ForwardKeyboardEvent(webkit_event);
}
}
@@ -1458,12 +1460,13 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
// Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
// For keys like VK_BACK/VK_LEFT, etc we need to send the raw keycode to
// the renderer.
+ double now = ui::EventTimeForNow().InSecondsF();
NativeWebKeyboardEvent webkit_event(
event->type(),
false /* is_char */,
event->GetCharacter() ? event->GetCharacter() : event->key_code(),
event->flags(),
- base::Time::Now().ToDoubleT());
+ now);
host_->ForwardKeyboardEvent(webkit_event);
} else {
NativeWebKeyboardEvent webkit_event(event);
diff --git a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
index 7c86610..db93cb5 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura_unittest.cc
@@ -20,6 +20,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/ui_base_types.h"
namespace content {
@@ -173,12 +174,18 @@ TEST_F(RenderWidgetHostViewAuraTest, TouchEventState) {
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, false));
EXPECT_FALSE(widget_host_->ShouldForwardTouchEvent());
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0,
- base::Time::NowFromSystemTime() - base::Time());
- ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
- base::Time::NowFromSystemTime() - base::Time());
- ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ gfx::Point(30, 30),
+ 0,
+ ui::EventTimeForNow());
+ ui::TouchEvent move(ui::ET_TOUCH_MOVED,
+ gfx::Point(20, 20),
+ 0,
+ ui::EventTimeForNow());
+ ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
+ gfx::Point(20, 20),
+ 0,
+ ui::EventTimeForNow());
view_->OnTouchEvent(&press);
EXPECT_FALSE(press.handled());
@@ -261,12 +268,18 @@ TEST_F(RenderWidgetHostViewAuraTest, TouchEventSyncAsync) {
widget_host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
EXPECT_TRUE(widget_host_->ShouldForwardTouchEvent());
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0,
- base::Time::NowFromSystemTime() - base::Time());
- ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 0,
- base::Time::NowFromSystemTime() - base::Time());
- ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ gfx::Point(30, 30),
+ 0,
+ ui::EventTimeForNow());
+ ui::TouchEvent move(ui::ET_TOUCH_MOVED,
+ gfx::Point(20, 20),
+ 0,
+ ui::EventTimeForNow());
+ ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
+ gfx::Point(20, 20),
+ 0,
+ ui::EventTimeForNow());
view_->OnTouchEvent(&press);
EXPECT_TRUE(press.stopped_propagation());
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 6e38df8..ff0cc11 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -73,6 +73,48 @@ using WebKit::WebTouchEvent;
using WebKit::WebVector;
using WebKit::WebWidget;
+namespace {
+const char* GetEventName(WebInputEvent::Type type) {
+#define CASE_TYPE(t) case WebInputEvent::t: return #t
+ switch(type) {
+ CASE_TYPE(Undefined);
+ CASE_TYPE(MouseDown);
+ CASE_TYPE(MouseUp);
+ CASE_TYPE(MouseMove);
+ CASE_TYPE(MouseEnter);
+ CASE_TYPE(MouseLeave);
+ CASE_TYPE(ContextMenu);
+ CASE_TYPE(MouseWheel);
+ CASE_TYPE(RawKeyDown);
+ CASE_TYPE(KeyDown);
+ CASE_TYPE(KeyUp);
+ CASE_TYPE(Char);
+ CASE_TYPE(GestureScrollBegin);
+ CASE_TYPE(GestureScrollEnd);
+ CASE_TYPE(GestureScrollUpdate);
+ CASE_TYPE(GestureFlingStart);
+ CASE_TYPE(GestureFlingCancel);
+ CASE_TYPE(GestureTap);
+ CASE_TYPE(GestureTapDown);
+ CASE_TYPE(GestureTapCancel);
+ CASE_TYPE(GestureDoubleTap);
+ CASE_TYPE(GestureTwoFingerTap);
+ CASE_TYPE(GestureLongPress);
+ CASE_TYPE(GestureLongTap);
+ CASE_TYPE(GesturePinchBegin);
+ CASE_TYPE(GesturePinchEnd);
+ CASE_TYPE(GesturePinchUpdate);
+ CASE_TYPE(TouchStart);
+ CASE_TYPE(TouchMove);
+ CASE_TYPE(TouchEnd);
+ CASE_TYPE(TouchCancel);
+ // Don't include default, so that we get an error when new type is added.
+ }
+#undef CASE_TYPE
+ NOTREACHED();
+ return "Undefined";
+}
+}
namespace content {
RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
@@ -555,6 +597,25 @@ void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
return;
}
+ base::TimeDelta now = base::TimeDelta::FromInternalValue(
+ base::TimeTicks::Now().ToInternalValue());
+
+ int64 delta = static_cast<int64>(
+ (now.InSecondsF() - input_event->timeStampSeconds) *
+ base::Time::kMicrosecondsPerSecond);
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
+ std::string name_for_event =
+ base::StringPrintf("Event.Latency.Renderer.%s",
+ GetEventName(input_event->type));
+ base::Histogram* counter_for_type =
+ base::Histogram::FactoryTimeGet(
+ name_for_event,
+ base::TimeDelta::FromMilliseconds(0),
+ base::TimeDelta::FromMilliseconds(1000000),
+ 100,
+ base::Histogram::kUmaTargetedHistogramFlag);
+ counter_for_type->AddTime(base::TimeDelta::FromMicroseconds(delta));
+
bool prevent_default = false;
if (WebInputEvent::isMouseEventType(input_event->type)) {
const WebMouseEvent& mouse_event =
diff --git a/ui/aura/gestures/gesture_recognizer_unittest.cc b/ui/aura/gestures/gesture_recognizer_unittest.cc
index 6156b4c..b2b9483 100644
--- a/ui/aura/gestures/gesture_recognizer_unittest.cc
+++ b/ui/aura/gestures/gesture_recognizer_unittest.cc
@@ -14,6 +14,7 @@
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_configuration.h"
#include "ui/base/gestures/gesture_recognizer_impl.h"
#include "ui/base/gestures/gesture_sequence.h"
@@ -477,7 +478,7 @@ class TimerTestGestureRecognizer : public TestGestureRecognizer {
};
base::TimeDelta GetTime() {
- return base::Time::NowFromSystemTime() - base::Time();
+ return ui::EventTimeForNow();
}
class TimedEvents {
diff --git a/ui/aura/test/event_generator.cc b/ui/aura/test/event_generator.cc
index 2a6daea..6c55ff4c 100644
--- a/ui/aura/test/event_generator.cc
+++ b/ui/aura/test/event_generator.cc
@@ -7,6 +7,7 @@
#include "base/memory/scoped_ptr.h"
#include "ui/aura/root_window.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/gfx/vector2d_conversions.h"
#if defined(USE_X11)
@@ -33,8 +34,7 @@ class TestTouchEvent : public ui::TouchEvent {
TestTouchEvent(ui::EventType type,
const gfx::Point& root_location,
int flags)
- : TouchEvent(type, root_location, 0,
- base::Time::NowFromSystemTime() - base::Time()) {
+ : TouchEvent(type, root_location, 0, ui::EventTimeForNow()) {
set_flags(flags);
}
@@ -186,8 +186,10 @@ void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
void EventGenerator::GestureTapAt(const gfx::Point& location) {
const int kTouchId = 2;
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ location,
+ kTouchId,
+ ui::EventTimeForNow());
Dispatch(press);
ui::TouchEvent release(
@@ -198,9 +200,10 @@ void EventGenerator::GestureTapAt(const gfx::Point& location) {
void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) {
const int kTouchId = 3;
- ui::TouchEvent press(
- ui::ET_TOUCH_PRESSED, location, kTouchId,
- base::Time::NowFromSystemTime() - base::Time());
+ ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
+ location,
+ kTouchId,
+ ui::EventTimeForNow());
Dispatch(press);
ui::TouchEvent release(
@@ -214,7 +217,7 @@ void EventGenerator::GestureScrollSequence(const gfx::Point& start,
const base::TimeDelta& step_delay,
int steps) {
const int kTouchId = 5;
- base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time();
+ base::TimeDelta timestamp = ui::EventTimeForNow();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp);
Dispatch(press);
@@ -246,7 +249,7 @@ void EventGenerator::GestureMultiFingerScroll(int count,
int delta_x = move_x / steps;
int delta_y = move_y / steps;
- base::TimeDelta press_time = base::Time::NowFromSystemTime() - base::Time();
+ base::TimeDelta press_time = ui::EventTimeForNow();
for (int i = 0; i < count; ++i) {
points[i] = start[i];
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time);
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 4197dfb0..d7e1af6 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -27,6 +27,7 @@
#include "ui/aura/window_observer.h"
#include "ui/aura/window_property.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_configuration.h"
#include "ui/base/hit_test.h"
#include "ui/base/keycodes/keyboard_codes.h"
@@ -239,7 +240,7 @@ class GestureTrackPositionDelegate : public TestWindowDelegate {
};
base::TimeDelta getTime() {
- return base::Time::NowFromSystemTime() - base::Time();
+ return ui::EventTimeForNow();
}
class SelfEventHandlingWindowDelegate : public TestWindowDelegate {
diff --git a/ui/base/events/event.cc b/ui/base/events/event.cc
index e24c176..e999f33 100644
--- a/ui/base/events/event.cc
+++ b/ui/base/events/event.cc
@@ -11,6 +11,8 @@
#include <cmath>
#include <cstring>
+#include "base/metrics/histogram.h"
+#include "base/stringprintf.h"
#include "ui/base/events/event_utils.h"
#include "ui/base/keycodes/keyboard_code_conversion.h"
#include "ui/gfx/point3_f.h"
@@ -53,47 +55,50 @@ gfx::Point CalibratePoint(const gfx::Point& point,
std::string EventTypeName(ui::EventType type) {
#define RETURN_IF_TYPE(t) if (type == ui::t) return #t
- RETURN_IF_TYPE(ET_UNKNOWN);
- RETURN_IF_TYPE(ET_MOUSE_PRESSED);
- RETURN_IF_TYPE(ET_MOUSE_DRAGGED);
- RETURN_IF_TYPE(ET_MOUSE_RELEASED);
- RETURN_IF_TYPE(ET_MOUSE_MOVED);
- RETURN_IF_TYPE(ET_MOUSE_ENTERED);
- RETURN_IF_TYPE(ET_MOUSE_EXITED);
- RETURN_IF_TYPE(ET_KEY_PRESSED);
- RETURN_IF_TYPE(ET_KEY_RELEASED);
- RETURN_IF_TYPE(ET_MOUSEWHEEL);
- RETURN_IF_TYPE(ET_MOUSE_CAPTURE_CHANGED);
- RETURN_IF_TYPE(ET_TOUCH_RELEASED);
- RETURN_IF_TYPE(ET_TOUCH_PRESSED);
- RETURN_IF_TYPE(ET_TOUCH_MOVED);
- RETURN_IF_TYPE(ET_TOUCH_STATIONARY);
- RETURN_IF_TYPE(ET_TOUCH_CANCELLED);
- RETURN_IF_TYPE(ET_DROP_TARGET_EVENT);
- RETURN_IF_TYPE(ET_TRANSLATED_KEY_PRESS);
- RETURN_IF_TYPE(ET_TRANSLATED_KEY_RELEASE);
-
- RETURN_IF_TYPE(ET_GESTURE_SCROLL_BEGIN);
- RETURN_IF_TYPE(ET_GESTURE_SCROLL_END);
- RETURN_IF_TYPE(ET_GESTURE_SCROLL_UPDATE);
- RETURN_IF_TYPE(ET_GESTURE_TAP);
- RETURN_IF_TYPE(ET_GESTURE_TAP_DOWN);
- RETURN_IF_TYPE(ET_GESTURE_TAP_CANCEL);
- RETURN_IF_TYPE(ET_GESTURE_BEGIN);
- RETURN_IF_TYPE(ET_GESTURE_END);
- RETURN_IF_TYPE(ET_GESTURE_DOUBLE_TAP);
- RETURN_IF_TYPE(ET_GESTURE_TWO_FINGER_TAP);
- RETURN_IF_TYPE(ET_GESTURE_PINCH_BEGIN);
- RETURN_IF_TYPE(ET_GESTURE_PINCH_END);
- RETURN_IF_TYPE(ET_GESTURE_PINCH_UPDATE);
- RETURN_IF_TYPE(ET_GESTURE_LONG_PRESS);
- RETURN_IF_TYPE(ET_GESTURE_LONG_TAP);
- RETURN_IF_TYPE(ET_GESTURE_MULTIFINGER_SWIPE);
-
- RETURN_IF_TYPE(ET_SCROLL);
- RETURN_IF_TYPE(ET_SCROLL_FLING_START);
- RETURN_IF_TYPE(ET_SCROLL_FLING_CANCEL);
-#undef RETURN_IF_TYPE
+#define CASE_TYPE(t) case ui::t: return #t
+ switch (type) {
+ CASE_TYPE(ET_UNKNOWN);
+ CASE_TYPE(ET_MOUSE_PRESSED);
+ CASE_TYPE(ET_MOUSE_DRAGGED);
+ CASE_TYPE(ET_MOUSE_RELEASED);
+ CASE_TYPE(ET_MOUSE_MOVED);
+ CASE_TYPE(ET_MOUSE_ENTERED);
+ CASE_TYPE(ET_MOUSE_EXITED);
+ CASE_TYPE(ET_KEY_PRESSED);
+ CASE_TYPE(ET_KEY_RELEASED);
+ CASE_TYPE(ET_MOUSEWHEEL);
+ CASE_TYPE(ET_MOUSE_CAPTURE_CHANGED);
+ CASE_TYPE(ET_TOUCH_RELEASED);
+ CASE_TYPE(ET_TOUCH_PRESSED);
+ CASE_TYPE(ET_TOUCH_MOVED);
+ CASE_TYPE(ET_TOUCH_STATIONARY);
+ CASE_TYPE(ET_TOUCH_CANCELLED);
+ CASE_TYPE(ET_DROP_TARGET_EVENT);
+ CASE_TYPE(ET_TRANSLATED_KEY_PRESS);
+ CASE_TYPE(ET_TRANSLATED_KEY_RELEASE);
+ CASE_TYPE(ET_GESTURE_SCROLL_BEGIN);
+ CASE_TYPE(ET_GESTURE_SCROLL_END);
+ CASE_TYPE(ET_GESTURE_SCROLL_UPDATE);
+ CASE_TYPE(ET_GESTURE_TAP);
+ CASE_TYPE(ET_GESTURE_TAP_DOWN);
+ CASE_TYPE(ET_GESTURE_TAP_CANCEL);
+ CASE_TYPE(ET_GESTURE_BEGIN);
+ CASE_TYPE(ET_GESTURE_END);
+ CASE_TYPE(ET_GESTURE_DOUBLE_TAP);
+ CASE_TYPE(ET_GESTURE_TWO_FINGER_TAP);
+ CASE_TYPE(ET_GESTURE_PINCH_BEGIN);
+ CASE_TYPE(ET_GESTURE_PINCH_END);
+ CASE_TYPE(ET_GESTURE_PINCH_UPDATE);
+ CASE_TYPE(ET_GESTURE_LONG_PRESS);
+ CASE_TYPE(ET_GESTURE_LONG_TAP);
+ CASE_TYPE(ET_GESTURE_MULTIFINGER_SWIPE);
+ CASE_TYPE(ET_SCROLL);
+ CASE_TYPE(ET_SCROLL_FLING_START);
+ CASE_TYPE(ET_SCROLL_FLING_CANCEL);
+ case ui::ET_LAST: NOTREACHED(); return std::string();
+ // Don't include default, so that we get an error when new type is added.
+ }
+#undef CASE_TYPE
NOTREACHED();
return std::string();
@@ -162,8 +167,21 @@ Event::Event(const base::NativeEvent& native_event,
target_(NULL),
phase_(EP_PREDISPATCH),
result_(ER_UNHANDLED) {
+ base::TimeDelta delta = ui::EventTimeForNow() - time_stamp_;
if (type_ < ET_LAST)
name_ = EventTypeName(type_);
+ UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Browser",
+ delta.InMicroseconds(), 0, 1000000, 100);
+ std::string name_for_event =
+ base::StringPrintf("Event.Latency.Browser.%s", name_.c_str());
+ base::Histogram* counter_for_type =
+ base::Histogram::FactoryTimeGet(
+ name_for_event,
+ base::TimeDelta::FromMilliseconds(0),
+ base::TimeDelta::FromMilliseconds(1000000),
+ 100,
+ base::Histogram::kUmaTargetedHistogramFlag);
+ counter_for_type->AddTime(delta);
InitWithNativeEvent(native_event);
}
@@ -253,8 +271,11 @@ MouseEvent::MouseEvent(EventType type,
const gfx::Point& location,
const gfx::Point& root_location,
int flags)
- : LocatedEvent(type, location, root_location,
- base::Time::NowFromSystemTime() - base::Time(), flags),
+ : LocatedEvent(type,
+ location,
+ root_location,
+ ui::EventTimeForNow(),
+ flags),
changed_button_flags_(0) {
if (this->type() == ET_MOUSE_MOVED && IsAnyButton())
SetType(ET_MOUSE_DRAGGED);
@@ -455,7 +476,7 @@ KeyEvent::KeyEvent(EventType type,
KeyboardCode key_code,
int flags,
bool is_char)
- : Event(type, base::Time::NowFromSystemTime() - base::Time(), flags),
+ : Event(type, EventTimeForNow(), flags),
key_code_(key_code),
is_char_(is_char),
character_(GetCharacterFromKeyCode(key_code, flags)),
@@ -579,8 +600,11 @@ DropTargetEvent::DropTargetEvent(const OSExchangeData& data,
const gfx::Point& location,
const gfx::Point& root_location,
int source_operations)
- : LocatedEvent(ET_DROP_TARGET_EVENT, location, root_location,
- base::Time::NowFromSystemTime() - base::Time(), 0),
+ : LocatedEvent(ET_DROP_TARGET_EVENT,
+ location,
+ root_location,
+ ui::EventTimeForNow(),
+ 0),
data_(data),
source_operations_(source_operations) {
}
diff --git a/ui/base/events/event.h b/ui/base/events/event.h
index 99b2eec..a5d2887 100644
--- a/ui/base/events/event.h
+++ b/ui/base/events/event.h
@@ -195,7 +195,6 @@ class UI_EXPORT Event {
delete_native_event_ = delete_native_event;
}
void set_cancelable(bool cancelable) { cancelable_ = cancelable; }
- void set_time_stamp(base::TimeDelta time_stamp) { time_stamp_ = time_stamp; }
void set_dispatch_to_hidden_targets(bool dispatch_to_hidden_targets) {
dispatch_to_hidden_targets_ = dispatch_to_hidden_targets;
}
diff --git a/ui/base/events/event_utils.cc b/ui/base/events/event_utils.cc
index ef16fb9e..ac09854 100644
--- a/ui/base/events/event_utils.cc
+++ b/ui/base/events/event_utils.cc
@@ -20,4 +20,9 @@ int RegisterCustomEventType() {
return ++g_custom_event_types;
}
+base::TimeDelta EventTimeForNow() {
+ return base::TimeDelta::FromInternalValue(
+ base::TimeTicks::Now().ToInternalValue());
+}
+
} // namespace ui
diff --git a/ui/base/events/event_utils.h b/ui/base/events/event_utils.h
index 77e542f..49a6b09 100644
--- a/ui/base/events/event_utils.h
+++ b/ui/base/events/event_utils.h
@@ -35,9 +35,13 @@ UI_EXPORT EventType EventTypeFromNative(const base::NativeEvent& native_event);
// Get the EventFlags from a native event.
UI_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
+// Get the timestamp from a native event.
UI_EXPORT base::TimeDelta EventTimeFromNative(
const base::NativeEvent& native_event);
+// Create a timestamp based on the current time.
+UI_EXPORT base::TimeDelta EventTimeForNow();
+
// Get the location from a native event. The coordinate system of the resultant
// |Point| has the origin at top-left of the "root window". The nature of
// this "root window" and how it maps to platform-specific drawing surfaces is
diff --git a/ui/base/gestures/gesture_recognizer_impl.cc b/ui/base/gestures/gesture_recognizer_impl.cc
index 2a569ee..fb1aec2 100644
--- a/ui/base/gestures/gesture_recognizer_impl.cc
+++ b/ui/base/gestures/gesture_recognizer_impl.cc
@@ -9,6 +9,7 @@
#include "base/time.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_constants.h"
+#include "ui/base/events/event_utils.h"
#include "ui/base/gestures/gesture_configuration.h"
#include "ui/base/gestures/gesture_sequence.h"
#include "ui/base/gestures/gesture_types.h"
@@ -161,8 +162,10 @@ void GestureRecognizerImpl::TransferEventsTo(GestureConsumer* current_consumer,
if (i->second != new_consumer &&
(i->second != current_consumer || new_consumer == NULL) &&
i->second != gesture_consumer_ignorer_.get()) {
- TouchEvent touch_event(ui::ET_TOUCH_CANCELLED, gfx::Point(0, 0),
- i->first, base::Time::NowFromSystemTime() - base::Time());
+ TouchEvent touch_event(ui::ET_TOUCH_CANCELLED,
+ gfx::Point(0, 0),
+ i->first,
+ ui::EventTimeForNow());
helper_->DispatchCancelTouchEvent(&touch_event);
i->second = gesture_consumer_ignorer_.get();
}
diff --git a/ui/views/corewm/compound_event_filter_unittest.cc b/ui/views/corewm/compound_event_filter_unittest.cc
index 20442a3..34458f8 100644
--- a/ui/views/corewm/compound_event_filter_unittest.cc
+++ b/ui/views/corewm/compound_event_filter_unittest.cc
@@ -13,11 +13,12 @@
#include "ui/aura/test/test_activation_client.h"
#include "ui/aura/test/test_windows.h"
#include "ui/base/events/event.h"
+#include "ui/base/events/event_utils.h"
namespace {
base::TimeDelta GetTime() {
- return base::Time::NowFromSystemTime() - base::Time();
+ return ui::EventTimeForNow();
}
class TestCursorClient : public aura::client::CursorClient {