Disable draw_properties benchmark on Android.
[chromium-blink-merge.git] / chrome / browser / metrics / first_web_contents_profiler.cc
blobae97bac1bed4d80caea5663f85161163524bca7c
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.
5 #if !defined(OS_ANDROID)
7 #include "chrome/browser/metrics/first_web_contents_profiler.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "base/process/process_info.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_iterator.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 scoped_ptr<FirstWebContentsProfiler>
17 FirstWebContentsProfiler::CreateProfilerForFirstWebContents(
18 Delegate* delegate) {
19 DCHECK(delegate);
20 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
21 Browser* browser = *iterator;
22 content::WebContents* web_contents =
23 browser->tab_strip_model()->GetActiveWebContents();
24 if (web_contents) {
25 return scoped_ptr<FirstWebContentsProfiler>(
26 new FirstWebContentsProfiler(web_contents, delegate));
29 return nullptr;
32 FirstWebContentsProfiler::FirstWebContentsProfiler(
33 content::WebContents* web_contents,
34 Delegate* delegate)
35 : content::WebContentsObserver(web_contents),
36 collected_paint_metric_(false),
37 collected_load_metric_(false),
38 delegate_(delegate) {
39 process_creation_time_ = base::CurrentProcessInfo::CreationTime();
42 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() {
43 if (collected_paint_metric_)
44 return;
46 collected_paint_metric_ = true;
47 if (!process_creation_time_.is_null()) {
48 base::TimeDelta elapsed = base::Time::Now() - process_creation_time_;
50 UMA_HISTOGRAM_LONG_TIMES_100("Startup.FirstWebContents.NonEmptyPaint",
51 elapsed);
54 if (IsFinishedCollectingMetrics())
55 FinishedCollectingMetrics();
58 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() {
59 if (collected_load_metric_)
60 return;
62 collected_load_metric_ = true;
63 if (!process_creation_time_.is_null()) {
64 base::TimeDelta elapsed = base::Time::Now() - process_creation_time_;
66 UMA_HISTOGRAM_LONG_TIMES_100("Startup.FirstWebContents.MainFrameLoad",
67 elapsed);
70 if (IsFinishedCollectingMetrics())
71 FinishedCollectingMetrics();
74 void FirstWebContentsProfiler::WebContentsDestroyed() {
75 FinishedCollectingMetrics();
78 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() {
79 return collected_paint_metric_ && collected_load_metric_;
82 void FirstWebContentsProfiler::FinishedCollectingMetrics() {
83 delegate_->ProfilerFinishedCollectingMetrics();
86 #endif // !defined(OS_ANDROID)