Index: chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc |
diff --git a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc |
index 9055c02b178646427d2b597fe65e7c321dbb6ea2..cd92263a1adec6321607a26a242c4b990cec2347 100644 |
--- a/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc |
+++ b/chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc |
@@ -21,6 +21,9 @@ |
#include "chrome/browser/chrome_browser_main.h" |
#include "chrome/browser/mac/bluetooth_utility.h" |
#include "chrome/browser/shell_integration.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "components/flags_ui/pref_service_flags_storage.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/common/content_switches.h" |
@@ -420,11 +423,34 @@ void ChromeBrowserMainExtraPartsMetrics::PostBrowserStart() { |
is_screen_observer_ = true; |
#if !defined(OS_ANDROID) |
- metrics::BeginFirstWebContentsProfiling(); |
+ const BrowserList* browser_list = BrowserList::GetInstance(); |
+ |
+ auto first_browser = browser_list->begin(); |
+ if (first_browser == browser_list->end()) |
+ DCHECK(0); |
sky
2017/04/07 21:52:14
I'm not entirely sure it's valid to assume there i
eugenebng
2017/04/10 12:04:43
Thank you for comments, overlooked this part of co
|
+ |
+ TabStripModel* tab_strip = (*first_browser)->tab_strip_model(); |
+ DCHECK(tab_strip); |
+ if (tab_strip->empty()) { |
+ // Start web contents profiling later, when there will be a tab to profile |
+ tab_strip->AddObserver(this); |
sky
2017/04/07 21:52:14
Make sure you deal with case of this being deleted
|
+ } else { |
+ metrics::BeginFirstWebContentsProfiling(); |
+ } |
metrics::TabUsageRecorder::InitializeIfNeeded(); |
#endif // !defined(OS_ANDROID) |
} |
+void ChromeBrowserMainExtraPartsMetrics::TabInsertedAt( |
+ TabStripModel* tab_strip_model, |
+ content::WebContents* contents, |
+ int index, |
+ bool foreground) { |
+ VLOG(0) << "begin profiling!"; |
sky
2017/04/07 21:52:14
Remove VLOGs.
|
+ metrics::BeginFirstWebContentsProfiling(); |
+ tab_strip_model->RemoveObserver(this); |
+} |
+ |
void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded( |
const display::Display& new_display) { |
EmitDisplaysChangedMetric(); |