Chromium Code Reviews| 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 99e8752bb20b00b2c654c7d017bf5d085d95af8f..b5a50c1ad58ee1ba3f3ea03cc65bb670b6069686 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" |
| @@ -440,6 +443,8 @@ ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() |
| ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() { |
| if (is_screen_observer_) |
| display::Screen::GetScreen()->RemoveObserver(this); |
| + for (auto* browser : *BrowserList::GetInstance()) |
| + browser->tab_strip_model()->RemoveObserver(this); |
| } |
| void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() { |
| @@ -510,11 +515,32 @@ 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()) { |
| + 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); |
|
gab
2017/06/09 16:59:19
This isn't correct as first web contents profiling
eugenebng
2017/06/13 12:10:02
Done.
|
| + } else { |
| + metrics::BeginFirstWebContentsProfiling(); |
| + } |
| + } |
| metrics::TabUsageRecorder::InitializeIfNeeded(); |
| #endif // !defined(OS_ANDROID) |
| } |
| +void ChromeBrowserMainExtraPartsMetrics::TabInsertedAt( |
| + TabStripModel* tab_strip_model, |
| + content::WebContents* contents, |
| + int index, |
| + bool foreground) { |
| + metrics::BeginFirstWebContentsProfiling(); |
| + tab_strip_model->RemoveObserver(this); |
| +} |
| + |
| void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded( |
| const display::Display& new_display) { |
| EmitDisplaysChangedMetric(); |