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

Unified Diff: chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc

Issue 1638013002: Add UMA histograms to track very brief or frequent tabs and JS dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename histograms; ignore blocked JS dialogs Created 4 years, 11 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/ui/tabs/tab_strip_model_stats_recorder.cc
diff --git a/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc b/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc
index e61fc3dd31518c1d04064a864579264b8af04a4f..ea85b8092f2672796acc810fa0d56d403939137c 100644
--- a/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model_stats_recorder.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/supports_user_data.h"
+#include "base/time/time.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list.h"
@@ -42,9 +43,12 @@ class TabStripModelStatsRecorder::TabInfo
return info;
}
+ base::TimeTicks creation_time() const { return creation_time_; }
+
private:
TabState current_state_ = TabState::INITIAL;
base::TimeTicks last_state_modified_;
+ base::TimeTicks creation_time_ = base::TimeTicks::Now();
static const char kKey[];
};
@@ -102,6 +106,13 @@ void TabStripModelStatsRecorder::TabInfo::UpdateState(TabState new_state) {
NOTREACHED();
break;
}
+
+ if (new_state == TabState::CLOSED) {
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "Tabs.FineTiming.TimeBetweenTabCreatedAndSameTabClosed",
+ now - creation_time_);
+ }
+
last_state_modified_ = now;
current_state_ = new_state;
}
@@ -110,6 +121,7 @@ void TabStripModelStatsRecorder::TabClosingAt(TabStripModel*,
content::WebContents* contents,
int index) {
TabInfo::Get(contents)->UpdateState(TabState::CLOSED);
+ last_close_time_ = base::TimeTicks::Now();
// Avoid having stale pointer in active_tab_history_
std::replace(active_tab_history_.begin(), active_tab_history_.end(), contents,
@@ -132,6 +144,25 @@ void TabStripModelStatsRecorder::ActiveTabChanged(
DCHECK(new_contents);
TabInfo* tab_info = TabInfo::Get(new_contents);
+ if (tab_info->state() == TabState::INITIAL) {
+ // A new tab has been created: log the time since the last one was created.
+ if (!last_creation_time_.is_null()) {
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "Tabs.FineTiming.TimeBetweenTabCreatedAndNextTabCreated",
+ tab_info->creation_time() - last_creation_time_);
+ }
+ last_creation_time_ = tab_info->creation_time();
+
+ // Also log the time since a tab was closed, but only if this is the first
+ // tab that was opened since the closing.
+ if (!last_close_time_.is_null()) {
+ UMA_HISTOGRAM_MEDIUM_TIMES(
+ "Tabs.FineTiming.TimeBetweenTabClosedAndNextTabCreated",
+ tab_info->creation_time() - last_close_time_);
+ last_close_time_ = base::TimeTicks();
+ }
+ }
+
bool was_inactive = tab_info->state() == TabState::INACTIVE;
tab_info->UpdateState(TabState::ACTIVE);

Powered by Google App Engine
This is Rietveld 408576698