OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| 6 #define CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/browser/web_contents_observer.h" |
| 10 |
| 11 namespace content { |
| 12 class WebContents; |
| 13 } // namespace content |
| 14 |
| 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; |
| 27 }; |
| 28 |
| 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); |
| 34 |
| 35 // These metrics are currently experimental, and are only collected in the |
| 36 // dev and canary channels. |
| 37 static bool ShouldCollectMetrics(); |
| 38 |
| 39 private: |
| 40 FirstWebContentsProfiler(content::WebContents* web_contents, |
| 41 Delegate* delegate); |
| 42 |
| 43 // content::WebContentsObserver: |
| 44 void DidFirstVisuallyNonEmptyPaint() override; |
| 45 void DocumentOnLoadCompletedInMainFrame() override; |
| 46 void WebContentsDestroyed() override; |
| 47 |
| 48 // Whether this instance has finished collecting all of its metrics. |
| 49 bool IsFinishedCollectingMetrics(); |
| 50 |
| 51 // Informs the delegate that this instance has finished collecting all of its |
| 52 // metrics. |
| 53 void FinishedCollectingMetrics(); |
| 54 |
| 55 // Whether the "NonEmptyPaint" metric has been collected. If an attempt is |
| 56 // made to collect the metric but the attempt fails, this member is set to |
| 57 // true to prevent this class from sitting around forever attempting to |
| 58 // collect the metric. |
| 59 bool collected_paint_metric_; |
| 60 |
| 61 // Whether the "MainFrameLoad" metric has been collected. If an attempt is |
| 62 // made to collect the metric but the attempt fails, this member is set to |
| 63 // true to prevent this class from sitting around forever attempting to |
| 64 // collect the metric. |
| 65 bool collected_load_metric_; |
| 66 |
| 67 // The time at which the process was created. |
| 68 base::Time process_creation_time_; |
| 69 |
| 70 // |delegate_| owns |this|. |
| 71 Delegate* delegate_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); |
| 74 }; |
| 75 |
| 76 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
OLD | NEW |