Chromium Code Reviews| 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..f09037898bd9041b54d84c70e370054ab8215125 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 CreationTime() const { return creation_time_; } |
|
sky
2016/01/29 17:25:51
nit: CreationTime->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,12 @@ void TabStripModelStatsRecorder::TabInfo::UpdateState(TabState new_state) { |
| NOTREACHED(); |
| break; |
| } |
| + |
| + if (new_state == TabState::CLOSED) { |
| + UMA_HISTOGRAM_MEDIUM_TIMES("Tabs.FineTiming.TabLifetime", |
| + now - creation_time_); |
| + } |
| + |
| last_state_modified_ = now; |
| current_state_ = new_state; |
| } |
| @@ -110,6 +120,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 +143,23 @@ 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.TimeSinceLastTabCreated", |
| + tab_info->CreationTime() - last_creation_time_); |
| + } |
| + last_creation_time_ = tab_info->CreationTime(); |
| + |
| + // 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.TimeSinceLastTabClosed", |
| + tab_info->CreationTime() - last_close_time_); |
| + last_close_time_ = base::TimeTicks(); |
| + } |
| + } |
| + |
| bool was_inactive = tab_info->state() == TabState::INACTIVE; |
| tab_info->UpdateState(TabState::ACTIVE); |