| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ | 5 #ifndef CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| 6 #define CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ | 6 #define CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "content/public/browser/web_contents_observer.h" | 10 #include "content/public/browser/web_contents_observer.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 class WebContents; | 13 class WebContents; |
| 14 } // namespace content | 14 } // namespace content |
| 15 | 15 |
| 16 // Measures start up performance of the first active web contents. | 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 | 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 | 18 // platforms. Android code should not call any non-trivial methods on this |
| 19 // class. | 19 // class. |
| 20 class FirstWebContentsProfiler : public content::WebContentsObserver { | 20 class FirstWebContentsProfiler : public content::WebContentsObserver { |
| 21 public: | 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; | |
| 28 }; | |
| 29 | |
| 30 // Creates a profiler for the active web contents. If there are multiple | 22 // 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 | 23 // browsers, the first one is chosen. The resulting FirstWebContentsProfiler |
| 32 // nullptr. | 24 // owns itself. |
| 33 static scoped_ptr<FirstWebContentsProfiler> CreateProfilerForFirstWebContents( | 25 static void Start(); |
| 34 Delegate* delegate); | |
| 35 | 26 |
| 36 private: | 27 private: |
| 37 // Reasons for which profiling is deemed complete. Logged in UMA (do not re- | 28 // Reasons for which profiling is deemed complete. Logged in UMA (do not re- |
| 38 // order or re-assign). | 29 // order or re-assign). |
| 39 enum FinishReason { | 30 enum FinishReason { |
| 40 // All metrics were successfully gathered. | 31 // All metrics were successfully gathered. |
| 41 DONE = 0, | 32 DONE = 0, |
| 42 // Abandon if blocking UI was shown during startup. | 33 // Abandon if blocking UI was shown during startup. |
| 43 ABANDON_BLOCKING_UI = 1, | 34 ABANDON_BLOCKING_UI = 1, |
| 44 // Abandon if the content is hidden (lowers scheduling priority). | 35 // Abandon if the content is hidden (lowers scheduling priority). |
| 45 ABANDON_CONTENT_HIDDEN = 2, | 36 ABANDON_CONTENT_HIDDEN = 2, |
| 46 // Abandon if the content is destroyed. | 37 // Abandon if the content is destroyed. |
| 47 ABANDON_CONTENT_DESTROYED = 3, | 38 ABANDON_CONTENT_DESTROYED = 3, |
| 48 // Abandon if the WebContents navigates away from its initial page. | 39 // Abandon if the WebContents navigates away from its initial page. |
| 49 ABANDON_NAVIGATION = 4, | 40 ABANDON_NAVIGATION = 4, |
| 50 ENUM_MAX | 41 ENUM_MAX |
| 51 }; | 42 }; |
| 52 | 43 |
| 53 FirstWebContentsProfiler(content::WebContents* web_contents, | 44 explicit FirstWebContentsProfiler(content::WebContents* web_contents); |
| 54 Delegate* delegate); | 45 ~FirstWebContentsProfiler() override = default; |
| 55 | 46 |
| 56 // content::WebContentsObserver: | 47 // content::WebContentsObserver: |
| 57 void DidFirstVisuallyNonEmptyPaint() override; | 48 void DidFirstVisuallyNonEmptyPaint() override; |
| 58 void DocumentOnLoadCompletedInMainFrame() override; | 49 void DocumentOnLoadCompletedInMainFrame() override; |
| 59 void NavigationEntryCommitted( | 50 void NavigationEntryCommitted( |
| 60 const content::LoadCommittedDetails& load_details) override; | 51 const content::LoadCommittedDetails& load_details) override; |
| 61 void WasHidden() override; | 52 void WasHidden() override; |
| 62 void WebContentsDestroyed() override; | 53 void WebContentsDestroyed() override; |
| 63 | 54 |
| 64 // Whether this instance has finished collecting all of its metrics. | 55 // Whether this instance has finished collecting all of its metrics. |
| 65 bool IsFinishedCollectingMetrics(); | 56 bool IsFinishedCollectingMetrics(); |
| 66 | 57 |
| 67 // Informs the delegate that this instance has finished collecting all of its | 58 // Logs |finish_reason| to UMA and deletes this FirstWebContentsProfiler. |
| 68 // metrics. Logs |finish_reason| to UMA. | |
| 69 void FinishedCollectingMetrics(FinishReason finish_reason); | 59 void FinishedCollectingMetrics(FinishReason finish_reason); |
| 70 | 60 |
| 71 // Initialize histograms for unresponsiveness metrics. | 61 // Initialize histograms for unresponsiveness metrics. |
| 72 void InitHistograms(); | 62 void InitHistograms(); |
| 73 | 63 |
| 74 // Becomes true on the first invocation of NavigationEntryCommitted() for the | 64 // Becomes true on the first invocation of NavigationEntryCommitted() for the |
| 75 // main frame. Any follow-up navigation to a different page will result in | 65 // main frame. Any follow-up navigation to a different page will result in |
| 76 // aborting first WebContents profiling. | 66 // aborting first WebContents profiling. |
| 77 bool initial_entry_committed_; | 67 bool initial_entry_committed_; |
| 78 | 68 |
| 79 // Whether an attempt was made to collect the "NonEmptyPaint" metric. | 69 // Whether an attempt was made to collect the "NonEmptyPaint" metric. |
| 80 bool collected_paint_metric_; | 70 bool collected_paint_metric_; |
| 81 | 71 |
| 82 // Whether an attempt was made to collect the "MainFrameLoad" metric. | 72 // Whether an attempt was made to collect the "MainFrameLoad" metric. |
| 83 bool collected_load_metric_; | 73 bool collected_load_metric_; |
| 84 | 74 |
| 85 // |delegate_| owns |this|. | |
| 86 Delegate* delegate_; | |
| 87 | |
| 88 // Histogram that keeps track of response times for the watched thread. | 75 // Histogram that keeps track of response times for the watched thread. |
| 89 base::HistogramBase* responsiveness_histogram_; | 76 base::HistogramBase* responsiveness_histogram_; |
| 90 | 77 |
| 91 // Histogram that keeps track of response times for the watched thread. | 78 // Histogram that keeps track of response times for the watched thread. |
| 92 base::HistogramBase* responsiveness_1sec_histogram_; | 79 base::HistogramBase* responsiveness_1sec_histogram_; |
| 93 | 80 |
| 94 // Histogram that keeps track of response times for the watched thread. | 81 // Histogram that keeps track of response times for the watched thread. |
| 95 base::HistogramBase* responsiveness_10sec_histogram_; | 82 base::HistogramBase* responsiveness_10sec_histogram_; |
| 96 | 83 |
| 97 // Histogram that keeps track of response times for the watched thread. | 84 // Histogram that keeps track of response times for the watched thread. |
| 98 base::HistogramBase* unresponsiveness_histogram_; | 85 base::HistogramBase* unresponsiveness_histogram_; |
| 99 | 86 |
| 100 // Histogram that keeps track of response times for the watched thread. | 87 // Histogram that keeps track of response times for the watched thread. |
| 101 base::HistogramBase* unresponsiveness_1sec_histogram_; | 88 base::HistogramBase* unresponsiveness_1sec_histogram_; |
| 102 | 89 |
| 103 // Histogram that keeps track of response times for the watched thread. | 90 // Histogram that keeps track of response times for the watched thread. |
| 104 base::HistogramBase* unresponsiveness_10sec_histogram_; | 91 base::HistogramBase* unresponsiveness_10sec_histogram_; |
| 105 | 92 |
| 106 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); | 93 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); |
| 107 }; | 94 }; |
| 108 | 95 |
| 109 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ | 96 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| OLD | NEW |