Index: chrome/browser/metrics/first_web_contents_profiler.h |
diff --git a/chrome/browser/metrics/first_web_contents_profiler.h b/chrome/browser/metrics/first_web_contents_profiler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9637b765a3a7cc85f6f1d5db43a792794662b07e |
--- /dev/null |
+++ b/chrome/browser/metrics/first_web_contents_profiler.h |
@@ -0,0 +1,60 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
+#define CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+namespace content { |
+class WebContents; |
+} // namespace content |
+ |
+class FirstWebContentsProfilerDelegate { |
+ public: |
+ // Called by the FirstWebContentsProfiler when it is finished collecting |
+ // metrics. The delegate should take this opportunity to destroy the |
+ // FirstWebContentsProfiler. |
+ virtual void ProfilerFinishedCollectingMetrics() = 0; |
+}; |
+ |
+// Measures start up performance of the first active web contents. |
+class FirstWebContentsProfiler : public content::WebContentsObserver { |
+ public: |
+ // Creates a profiler for the active web contents. If there are multiple |
+ // browsers, the first one is chosen. If there are no browsers, returns |
+ // nullptr. |
+ static scoped_ptr<FirstWebContentsProfiler> CreateProfilerForFirstWebContents( |
+ FirstWebContentsProfilerDelegate* delegate); |
+ |
+ private: |
+ FirstWebContentsProfiler(content::WebContents* web_contents, |
+ FirstWebContentsProfilerDelegate* delegate); |
+ |
+ // WebContentsObserver overrides. |
+ void DidFirstVisuallyNonEmptyPaint() override; |
+ void DocumentOnLoadCompletedInMainFrame() override; |
+ void WebContentsDestroyed() override; |
+ |
+ // Whether this instance has finished collecting all of its metrics. |
+ bool IsFinishedCollectingMetrics(); |
+ |
+ // Informs the delegate that this instance has finished collecting all of its |
+ // metrics. |
+ void FinishedCollectingMetrics(); |
+ |
+ // Whether the "NonEmptyPaint" metric has been collected. |
+ bool collected_paint_metric_; |
+ |
+ // Whether the "MainFrameLoad" metric has been collected. |
+ bool collected_load_metric_; |
+ |
+ // |delegate_| owns |this|. |
+ FirstWebContentsProfilerDelegate* delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler); |
+}; |
+ |
+#endif // CHROME_BROWSER_METRICS_FIRST_WEB_CONTENTS_PROFILER_H_ |