QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / metrics / first_web_contents_profiler.h
blob23a51a288af72075a16d9e632e7e87c52de062e1
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 CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_
6 #define CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h"
10 #include "content/public/browser/web_contents_observer.h"
12 namespace content {
13 class WebContents;
14 } // namespace content
16 // Measures start up performance of the first active web contents.
17 // This class is declared on all platforms, but only defined on non-Android
18 // platforms. Android code should not call any non-trivial methods on this
19 // class.
20 class FirstWebContentsProfiler : public content::WebContentsObserver {
21 public:
22 class Delegate {
23 public:
24 // Called by the FirstWebContentsProfiler when it is finished collecting
25 // metrics. The delegate should take this opportunity to destroy the
26 // FirstWebContentsProfiler.
27 virtual void ProfilerFinishedCollectingMetrics() = 0;
30 // Creates a profiler for the active web contents. If there are multiple
31 // browsers, the first one is chosen. If there are no browsers, returns
32 // nullptr.
33 static scoped_ptr<FirstWebContentsProfiler> CreateProfilerForFirstWebContents(
34 Delegate* delegate);
36 private:
37 FirstWebContentsProfiler(content::WebContents* web_contents,
38 Delegate* delegate);
40 // content::WebContentsObserver:
41 void DidFirstVisuallyNonEmptyPaint() override;
42 void DocumentOnLoadCompletedInMainFrame() override;
43 void WebContentsDestroyed() override;
45 // Whether this instance has finished collecting all of its metrics.
46 bool IsFinishedCollectingMetrics();
48 // Informs the delegate that this instance has finished collecting all of its
49 // metrics.
50 void FinishedCollectingMetrics();
52 // Initialize histograms for unresponsiveness metrics.
53 void InitHistograms();
55 // Whether an attempt was made to collect the "NonEmptyPaint" metric.
56 bool collected_paint_metric_;
58 // Whether an attempt was made to collect the "MainFrameLoad" metric.
59 bool collected_load_metric_;
61 // |delegate_| owns |this|.
62 Delegate* delegate_;
64 // Histogram that keeps track of response times for the watched thread.
65 base::HistogramBase* responsiveness_histogram_;
67 // Histogram that keeps track of response times for the watched thread.
68 base::HistogramBase* responsiveness_1sec_histogram_;
70 // Histogram that keeps track of response times for the watched thread.
71 base::HistogramBase* responsiveness_10sec_histogram_;
73 // Histogram that keeps track of response times for the watched thread.
74 base::HistogramBase* unresponsiveness_histogram_;
76 // Histogram that keeps track of response times for the watched thread.
77 base::HistogramBase* unresponsiveness_1sec_histogram_;
79 // Histogram that keeps track of response times for the watched thread.
80 base::HistogramBase* unresponsiveness_10sec_histogram_;
82 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler);
85 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_