Chromium Code Reviews| 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 "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 class WebContents; | 12 class WebContents; |
| 13 } // namespace content | 13 } // namespace content |
| 14 | 14 |
| 15 // Measures start up performance of the first active web contents. | 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 | 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 | 17 // platforms. Android code should not call any non-trivial methods on this |
| 18 // class. | 18 // class. |
| 19 class FirstWebContentsProfiler : public content::WebContentsObserver { | 19 class FirstWebContentsProfiler : public content::WebContentsObserver { |
| 20 public: | 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 | 21 // 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 | 22 // browsers, the first one is chosen. The resulting FirstWebContentsProfiler |
| 31 // nullptr. | 23 // owns itself. |
| 32 static scoped_ptr<FirstWebContentsProfiler> CreateProfilerForFirstWebContents( | 24 static void Start(); |
| 33 Delegate* delegate); | |
| 34 | 25 |
| 35 private: | 26 private: |
| 36 // Reasons for which profiling is deemed complete. Logged in UMA (do not re- | 27 // Reasons for which profiling is deemed complete. Logged in UMA (do not re- |
| 37 // order or re-assign). | 28 // order or re-assign). |
| 38 enum FinishReason { | 29 enum FinishReason { |
| 39 // All metrics were successfully gathered. | 30 // All metrics were successfully gathered. |
| 40 DONE = 0, | 31 DONE = 0, |
| 41 // Abandon if blocking UI was shown during startup. | 32 // Abandon if blocking UI was shown during startup. |
| 42 ABANDON_BLOCKING_UI = 1, | 33 ABANDON_BLOCKING_UI = 1, |
| 43 // Abandon if the content is hidden (lowers scheduling priority). | 34 // Abandon if the content is hidden (lowers scheduling priority). |
| 44 ABANDON_CONTENT_HIDDEN = 2, | 35 ABANDON_CONTENT_HIDDEN = 2, |
| 45 // Abandon if the content is destroyed. | 36 // Abandon if the content is destroyed. |
| 46 ABANDON_CONTENT_DESTROYED = 3, | 37 ABANDON_CONTENT_DESTROYED = 3, |
| 47 // Abandon if the WebContents navigates away from its initial page. | 38 // Abandon if the WebContents navigates away from its initial page. |
| 48 ABANDON_NEW_NAVIGATION = 4, | 39 ABANDON_NEW_NAVIGATION = 4, |
| 49 // Abandon if the WebContents fails to load (e.g. network error, etc.). | 40 // Abandon if the WebContents fails to load (e.g. network error, etc.). |
| 50 ABANDON_NAVIGATION_ERROR = 5, | 41 ABANDON_NAVIGATION_ERROR = 5, |
| 51 ENUM_MAX | 42 ENUM_MAX |
| 52 }; | 43 }; |
| 53 | 44 |
| 54 FirstWebContentsProfiler(content::WebContents* web_contents, | 45 explicit FirstWebContentsProfiler(content::WebContents* web_contents); |
| 55 Delegate* delegate); | 46 ~FirstWebContentsProfiler() override = default; |
| 56 | 47 |
| 57 // content::WebContentsObserver: | 48 // content::WebContentsObserver: |
| 58 void DidFirstVisuallyNonEmptyPaint() override; | 49 void DidFirstVisuallyNonEmptyPaint() override; |
| 59 void DocumentOnLoadCompletedInMainFrame() override; | 50 void DocumentOnLoadCompletedInMainFrame() override; |
| 60 void DidStartNavigation( | 51 void DidStartNavigation( |
| 61 content::NavigationHandle* navigation_handle) override; | 52 content::NavigationHandle* navigation_handle) override; |
| 62 void DidFinishNavigation( | 53 void DidFinishNavigation( |
| 63 content::NavigationHandle* navigation_handle) override; | 54 content::NavigationHandle* navigation_handle) override; |
| 64 void WasHidden() override; | 55 void WasHidden() override; |
| 65 void WebContentsDestroyed() override; | 56 void WebContentsDestroyed() override; |
| 66 | 57 |
| 67 // Whether this instance has finished collecting first-paint and main-frame- | 58 // Whether this instance has finished collecting first-paint and main-frame- |
| 68 // load metrics (navigation metrics are recorded on a best effort but don't | 59 // load metrics (navigation metrics are recorded on a best effort but don't |
| 69 // prevent the FirstWebContentsProfiler from calling it). | 60 // prevent the FirstWebContentsProfiler from calling it). |
| 70 bool IsFinishedCollectingMetrics(); | 61 bool IsFinishedCollectingMetrics(); |
| 71 | 62 |
| 72 // Informs the delegate that this instance has finished collecting all of its | 63 // // Logs |finish_reason| to UMA and deletes this FirstWebContentsProfiler. |
|
Alexei Svitkine (slow)
2015/11/13 19:24:33
Nit: Extra "// "
gab
2015/11/13 19:29:05
Oops, good catch, manual merge mistake.. Done.
| |
| 73 // metrics. Logs |finish_reason| to UMA. | |
| 74 void FinishedCollectingMetrics(FinishReason finish_reason); | 64 void FinishedCollectingMetrics(FinishReason finish_reason); |
| 75 | 65 |
| 76 // Whether an attempt was made to collect the "NonEmptyPaint" metric. | 66 // Whether an attempt was made to collect the "NonEmptyPaint" metric. |
| 77 bool collected_paint_metric_; | 67 bool collected_paint_metric_; |
| 78 | 68 |
| 79 // Whether an attempt was made to collect the "MainFrameLoad" metric. | 69 // Whether an attempt was made to collect the "MainFrameLoad" metric. |
| 80 bool collected_load_metric_; | 70 bool collected_load_metric_; |
| 81 | 71 |
| 82 // Whether an attempt was made to collect the "MainNavigationStart" metric. | 72 // Whether an attempt was made to collect the "MainNavigationStart" metric. |
| 83 bool collected_main_navigation_start_metric_; | 73 bool collected_main_navigation_start_metric_; |
| 84 | 74 |
| 85 // Whether an attempt was made to collect the "MainNavigationFinished" metric. | 75 // Whether an attempt was made to collect the "MainNavigationFinished" metric. |
| 86 bool collected_main_navigation_finished_metric_; | 76 bool collected_main_navigation_finished_metric_; |
| 87 | 77 |
| 88 // Whether core metric collection is complete. Used to keep reporting old | 78 // Whether core metric collection is complete. Used to keep reporting old |
| 89 // stats post abandon to give us an intra-milestone comparison basis initially | 79 // stats post abandon to give us an intra-milestone comparison basis initially |
| 90 // between the old and new stats. TODO(gab): Remove this in M49. | 80 // between the old and new stats. TODO(gab): Remove this in M49. |
| 91 bool finished_; | 81 bool finished_; |
| 92 | 82 |
| 93 // |delegate_| owns |this|. | |
| 94 Delegate* delegate_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); | 83 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); |
| 97 }; | 84 }; |
| 98 | 85 |
| 99 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ | 86 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| OLD | NEW |