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

Unified 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: +lifetime comment on new 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/first_web_contents_profiler.cc
diff --git a/chrome/browser/metrics/first_web_contents_profiler.cc b/chrome/browser/metrics/first_web_contents_profiler.cc
index 8626bf40ee96244283fd69842927e3da6db1af9e..0ec5220214d926f3bc2662c0d5e4f391733d9119 100644
--- a/chrome/browser/metrics/first_web_contents_profiler.cc
+++ b/chrome/browser/metrics/first_web_contents_profiler.cc
@@ -20,32 +20,29 @@
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "content/public/browser/navigation_handle.h"
-scoped_ptr<FirstWebContentsProfiler>
-FirstWebContentsProfiler::CreateProfilerForFirstWebContents(
- Delegate* delegate) {
- DCHECK(delegate);
- for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
- Browser* browser = *iterator;
+// static
+void FirstWebContentsProfiler::Start() {
+ for (chrome::BrowserIterator browser_it; !browser_it.done();
+ browser_it.Next()) {
content::WebContents* web_contents =
- browser->tab_strip_model()->GetActiveWebContents();
+ browser_it->tab_strip_model()->GetActiveWebContents();
if (web_contents) {
- return scoped_ptr<FirstWebContentsProfiler>(
- new FirstWebContentsProfiler(web_contents, delegate));
+ // FirstWebContentsProfiler owns itself and is also bound to
+ // |web_contents|'s lifetime by observing WebContentsDestroyed().
+ new FirstWebContentsProfiler(web_contents);
+ return;
}
}
- return nullptr;
}
FirstWebContentsProfiler::FirstWebContentsProfiler(
- content::WebContents* web_contents,
- Delegate* delegate)
+ content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
collected_paint_metric_(false),
collected_load_metric_(false),
collected_main_navigation_start_metric_(false),
collected_main_navigation_finished_metric_(false),
- finished_(false),
- delegate_(delegate) {}
+ finished_(false) {}
void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() {
if (collected_paint_metric_)
@@ -172,7 +169,7 @@ void FirstWebContentsProfiler::FinishedCollectingMetrics(
}
// TODO(gab): Delete right away when getting rid of |finished_|.
if (IsFinishedCollectingMetrics())
- delegate_->ProfilerFinishedCollectingMetrics();
+ delete this;
}
#endif // !defined(OS_ANDROID)

Powered by Google App Engine
This is Rietveld 408576698