Add yet more profiling to MediaStreamManager::StartMonitoringOnUIThread.
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_latency_tracker.h
blobbeb972e3506bcf3d1724837bc93cda7ec15fb65b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "cc/base/rolling_time_delta_history.h"
12 #include "content/browser/renderer_host/event_with_latency_info.h"
13 #include "content/common/content_export.h"
14 #include "ui/events/latency_info.h"
16 namespace content {
18 // Utility class for tracking the latency of events passing through
19 // a given RenderWidgetHost.
20 class CONTENT_EXPORT RenderWidgetHostLatencyTracker {
21 public:
22 RenderWidgetHostLatencyTracker();
23 ~RenderWidgetHostLatencyTracker();
25 // Associates the latency tracker with a given route and process.
26 // Called once after the RenderWidgetHost is fully initialized.
27 void Initialize(int routing_id, int process_id);
29 // Populates the LatencyInfo with relevant entries for latency tracking.
30 // Called when an event is received by the RenderWidgetHost, prior to
31 // that event being forwarded to the renderer (via the InputRouter).
32 void OnInputEvent(const blink::WebInputEvent& event,
33 ui::LatencyInfo* latency);
35 // Populates the LatencyInfo with relevant entries for latency tracking, also
36 // terminating latency tracking for events that did not trigger rendering and
37 // performing relevant UMA latency reporting. Called when an event is ack'ed
38 // to the RenderWidgetHost (from the InputRouter).
39 void OnInputEventAck(const blink::WebInputEvent& event,
40 ui::LatencyInfo* latency);
42 // Populates renderer-created LatencyInfo entries with the appropriate latency
43 // component id. Called when the RenderWidgetHost receives a compositor swap
44 // update from the renderer.
45 void OnSwapCompositorFrame(std::vector<ui::LatencyInfo>* latencies);
47 // Terminates latency tracking for events that triggered rendering, also
48 // performing relevant UMA latency reporting.
49 // Called when the RenderWidgetHost receives a swap update from the GPU.
50 void OnFrameSwapped(const ui::LatencyInfo& latency);
52 // Produces an estimate of the time between browser composite and GPU swap,
53 // as informed by historical latency values.
54 base::TimeDelta GetEstimatedBrowserCompositeTime() const;
56 // WebInputEvent coordinates are in DPIs, while LatencyInfo expects
57 // coordinates in device pixels.
58 void set_device_scale_factor(float device_scale_factor) {
59 device_scale_factor_ = device_scale_factor;
62 // Returns the ID that uniquely describes this component to the latency
63 // subsystem.
64 int64 latency_component_id() const { return latency_component_id_; }
66 private:
67 int64 last_event_id_;
68 int64 latency_component_id_;
69 float device_scale_factor_;
70 bool has_seent_first_gesture_scroll_update_;
71 cc::RollingTimeDeltaHistory browser_composite_latency_history_;
73 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTracker);
76 } // namespace content
78 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_