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

Unified Diff: chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.cc

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Added test, fixed opening URL case when browser is already started. Created 3 years, 8 months 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/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 9be497ed78fe9e1b116e1177a63150ac28562ccf..5fa086b5df979660f830f71b4870331d14ccbb2a 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"
@@ -354,6 +357,10 @@ ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics()
ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
if (is_screen_observer_)
display::Screen::GetScreen()->RemoveObserver(this);
+ const BrowserList* browser_list = BrowserList::GetInstance();
+ for (auto* browser : *browser_list) {
sky 2017/05/04 23:40:46 no {} optional: don't use a local for browser_list
eugenebng 2017/05/15 06:17:08 Done.
+ browser->tab_strip_model()->RemoveObserver(this);
+ }
}
void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
@@ -420,11 +427,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);
+ } 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();

Powered by Google App Engine
This is Rietveld 408576698