| 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 <memory> | 8 namespace metrics { |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 // Measures startup performance of the first active web contents. |
| 11 #include "content/public/browser/web_contents_observer.h" | 11 void BeginFirstWebContentsProfiling(); |
| 12 | 12 |
| 13 namespace content { | 13 } // namespace metrics |
| 14 class WebContents; | |
| 15 } // namespace content | |
| 16 | |
| 17 // Measures start up performance of the first active web contents. | |
| 18 // This class is declared on all platforms, but only defined on non-Android | |
| 19 // platforms. Android code should not call any non-trivial methods on this | |
| 20 // class. | |
| 21 class FirstWebContentsProfiler : public content::WebContentsObserver { | |
| 22 public: | |
| 23 // Creates a profiler for the active web contents. If there are multiple | |
| 24 // browsers, the first one is chosen. The resulting FirstWebContentsProfiler | |
| 25 // owns itself. | |
| 26 static void Start(); | |
| 27 | |
| 28 private: | |
| 29 // Reasons for which profiling is deemed complete. Logged in UMA (do not re- | |
| 30 // order or re-assign). | |
| 31 enum FinishReason { | |
| 32 // All metrics were successfully gathered. | |
| 33 DONE = 0, | |
| 34 // Abandon if blocking UI was shown during startup. | |
| 35 ABANDON_BLOCKING_UI = 1, | |
| 36 // Abandon if the content is hidden (lowers scheduling priority). | |
| 37 ABANDON_CONTENT_HIDDEN = 2, | |
| 38 // Abandon if the content is destroyed. | |
| 39 ABANDON_CONTENT_DESTROYED = 3, | |
| 40 // Abandon if the WebContents navigates away from its initial page. | |
| 41 ABANDON_NEW_NAVIGATION = 4, | |
| 42 // Abandon if the WebContents fails to load (e.g. network error, etc.). | |
| 43 ABANDON_NAVIGATION_ERROR = 5, | |
| 44 ENUM_MAX | |
| 45 }; | |
| 46 explicit FirstWebContentsProfiler(content::WebContents* web_contents); | |
| 47 ~FirstWebContentsProfiler() override = default; | |
| 48 | |
| 49 // content::WebContentsObserver: | |
| 50 void DidFirstVisuallyNonEmptyPaint() override; | |
| 51 void DocumentOnLoadCompletedInMainFrame() override; | |
| 52 void DidStartNavigation( | |
| 53 content::NavigationHandle* navigation_handle) override; | |
| 54 void DidFinishNavigation( | |
| 55 content::NavigationHandle* navigation_handle) override; | |
| 56 void WasHidden() override; | |
| 57 void WebContentsDestroyed() override; | |
| 58 | |
| 59 // Whether this instance has finished collecting first-paint and main-frame- | |
| 60 // load metrics (navigation metrics are recorded on a best effort but don't | |
| 61 // prevent the FirstWebContentsProfiler from calling it). | |
| 62 bool IsFinishedCollectingMetrics(); | |
| 63 | |
| 64 // Logs |finish_reason| to UMA and deletes this FirstWebContentsProfiler. | |
| 65 void FinishedCollectingMetrics(FinishReason finish_reason); | |
| 66 | |
| 67 // Whether an attempt was made to collect the "NonEmptyPaint" metric. | |
| 68 bool collected_paint_metric_; | |
| 69 | |
| 70 // Whether an attempt was made to collect the "MainFrameLoad" metric. | |
| 71 bool collected_load_metric_; | |
| 72 | |
| 73 // Whether an attempt was made to collect the "MainNavigationStart" metric. | |
| 74 bool collected_main_navigation_start_metric_; | |
| 75 | |
| 76 // Whether an attempt was made to collect the "MainNavigationFinished" metric. | |
| 77 bool collected_main_navigation_finished_metric_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); | |
| 80 }; | |
| 81 | 14 |
| 82 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ | 15 #endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
| OLD | NEW |