Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / metrics / first_web_contents_profiler.h
blobfa330e683d334a34cf4a148a8d07a98b49b2fa87
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 "content/public/browser/web_contents_observer.h"
11 namespace content {
12 class WebContents;
13 } // namespace content
15 // Measures start up performance of the first active web contents.
16 // This class is declared on all platforms, but only defined on non-Android
17 // platforms. Android code should not call any non-trivial methods on this
18 // class.
19 class FirstWebContentsProfiler : public content::WebContentsObserver {
20 public:
21 class Delegate {
22 public:
23 // Called by the FirstWebContentsProfiler when it is finished collecting
24 // metrics. The delegate should take this opportunity to destroy the
25 // FirstWebContentsProfiler.
26 virtual void ProfilerFinishedCollectingMetrics() = 0;
29 // Creates a profiler for the active web contents. If there are multiple
30 // browsers, the first one is chosen. If there are no browsers, returns
31 // nullptr.
32 static scoped_ptr<FirstWebContentsProfiler> CreateProfilerForFirstWebContents(
33 Delegate* delegate);
35 private:
36 FirstWebContentsProfiler(content::WebContents* web_contents,
37 Delegate* delegate);
39 // content::WebContentsObserver:
40 void DidFirstVisuallyNonEmptyPaint() override;
41 void DocumentOnLoadCompletedInMainFrame() override;
42 void WebContentsDestroyed() override;
44 // Whether this instance has finished collecting all of its metrics.
45 bool IsFinishedCollectingMetrics();
47 // Informs the delegate that this instance has finished collecting all of its
48 // metrics.
49 void FinishedCollectingMetrics();
51 // Whether the "NonEmptyPaint" metric has been collected. If an attempt is
52 // made to collect the metric but the attempt fails, this member is set to
53 // true to prevent this class from sitting around forever attempting to
54 // collect the metric.
55 bool collected_paint_metric_;
57 // Whether the "MainFrameLoad" metric has been collected. If an attempt is
58 // made to collect the metric but the attempt fails, this member is set to
59 // true to prevent this class from sitting around forever attempting to
60 // collect the metric.
61 bool collected_load_metric_;
63 // The time at which the process was created.
64 base::Time process_creation_time_;
66 // |delegate_| owns |this|.
67 Delegate* delegate_;
69 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler);
72 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_