Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/metrics/first_web_contents_profiler.cc

Issue 1415773004: Refactor ownership model for FirstWebContentsProfiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a1_more_abandons_and_umabandons
Patch Set: rebase on leak fix (https://codereview.chromium.org/1449933002) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/metrics/first_web_contents_profiler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if !defined(OS_ANDROID) 5 #if !defined(OS_ANDROID)
6 6
7 #include "chrome/browser/metrics/first_web_contents_profiler.h" 7 #include "chrome/browser/metrics/first_web_contents_profiler.h"
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_iterator.h" 16 #include "chrome/browser/ui/browser_iterator.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "components/metrics/profiler/tracking_synchronizer.h" 18 #include "components/metrics/profiler/tracking_synchronizer.h"
19 #include "components/metrics/proto/profiler_event.pb.h" 19 #include "components/metrics/proto/profiler_event.pb.h"
20 #include "components/startup_metric_utils/browser/startup_metric_utils.h" 20 #include "components/startup_metric_utils/browser/startup_metric_utils.h"
21 #include "content/public/browser/navigation_handle.h" 21 #include "content/public/browser/navigation_handle.h"
22 22
23 scoped_ptr<FirstWebContentsProfiler> 23 // static
24 FirstWebContentsProfiler::CreateProfilerForFirstWebContents( 24 void FirstWebContentsProfiler::Start() {
25 Delegate* delegate) { 25 for (chrome::BrowserIterator browser_it; !browser_it.done();
26 DCHECK(delegate); 26 browser_it.Next()) {
27 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
28 Browser* browser = *iterator;
29 content::WebContents* web_contents = 27 content::WebContents* web_contents =
30 browser->tab_strip_model()->GetActiveWebContents(); 28 browser_it->tab_strip_model()->GetActiveWebContents();
31 if (web_contents) { 29 if (web_contents) {
32 return scoped_ptr<FirstWebContentsProfiler>( 30 // FirstWebContentsProfiler owns itself and is also bound to
33 new FirstWebContentsProfiler(web_contents, delegate)); 31 // |web_contents|'s lifetime by observing WebContentsDestroyed().
32 new FirstWebContentsProfiler(web_contents);
33 return;
34 } 34 }
35 } 35 }
36 return nullptr;
37 } 36 }
38 37
39 FirstWebContentsProfiler::FirstWebContentsProfiler( 38 FirstWebContentsProfiler::FirstWebContentsProfiler(
40 content::WebContents* web_contents, 39 content::WebContents* web_contents)
41 Delegate* delegate)
42 : content::WebContentsObserver(web_contents), 40 : content::WebContentsObserver(web_contents),
43 collected_paint_metric_(false), 41 collected_paint_metric_(false),
44 collected_load_metric_(false), 42 collected_load_metric_(false),
45 collected_main_navigation_start_metric_(false), 43 collected_main_navigation_start_metric_(false),
46 collected_main_navigation_finished_metric_(false), 44 collected_main_navigation_finished_metric_(false),
47 finished_(false), 45 finished_(false) {}
48 delegate_(delegate) {}
49 46
50 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { 47 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() {
51 if (collected_paint_metric_) 48 if (collected_paint_metric_)
52 return; 49 return;
53 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { 50 if (startup_metric_utils::WasNonBrowserUIDisplayed()) {
54 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); 51 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI);
55 return; 52 return;
56 } 53 }
57 54
58 collected_paint_metric_ = true; 55 collected_paint_metric_ = true;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 167 }
171 finished_ = true; 168 finished_ = true;
172 } 169 }
173 170
174 // Continue recording deprecated v1 stats (see |finished_|) except in 171 // Continue recording deprecated v1 stats (see |finished_|) except in
175 // scenarios where stats collection was already being abandonned previously. 172 // scenarios where stats collection was already being abandonned previously.
176 // TODO(gab): Delete right away when getting rid of |finished_|. 173 // TODO(gab): Delete right away when getting rid of |finished_|.
177 if (IsFinishedCollectingMetrics() || 174 if (IsFinishedCollectingMetrics() ||
178 finish_reason == FinishReason::ABANDON_CONTENT_DESTROYED || 175 finish_reason == FinishReason::ABANDON_CONTENT_DESTROYED ||
179 finish_reason == FinishReason::ABANDON_BLOCKING_UI) { 176 finish_reason == FinishReason::ABANDON_BLOCKING_UI) {
180 delegate_->ProfilerFinishedCollectingMetrics(); 177 delete this;
181 } 178 }
182 } 179 }
183 180
184 #endif // !defined(OS_ANDROID) 181 #endif // !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « chrome/browser/metrics/first_web_contents_profiler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698