diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 21:29:12 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 21:29:12 +0000 |
commit | 6d65a46ab8dff07d44aea625222587e09aae06ca (patch) | |
tree | 68d59bf622916f4a487308e3fbfa82224699e486 /chrome/browser/ui | |
parent | e52291df4e21fb9857f7225b86ca50fbcb8cc583 (diff) | |
download | chromium_src-6d65a46ab8dff07d44aea625222587e09aae06ca.zip chromium_src-6d65a46ab8dff07d44aea625222587e09aae06ca.tar.gz chromium_src-6d65a46ab8dff07d44aea625222587e09aae06ca.tar.bz2 |
Move histograms and supporting code that don't belong in content out.
This CL was originally based on top of r205149 (Fast Tab Closure) and committed as r207181. The Fast Tab Closure CL was backed out together with the previous version of this CL.
Here's another shot, doing the same cleanup as before but with r205149 reverted.
BUG=
Review URL: https://chromiumcodereview.appspot.com/17153008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207925 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser_tabstrip.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/applescript/window_applescript.mm | 8 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/core_tab_helper.cc | 32 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/core_tab_helper.h | 35 | ||||
-rw-r--r-- | chrome/browser/ui/tabs/tab_strip_model.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/webui/metrics_handler.cc | 10 |
6 files changed, 84 insertions, 10 deletions
diff --git a/chrome/browser/ui/browser_tabstrip.cc b/chrome/browser/ui/browser_tabstrip.cc index aa308e0..9ffa615 100644 --- a/chrome/browser/ui/browser_tabstrip.cc +++ b/chrome/browser/ui/browser_tabstrip.cc @@ -9,6 +9,7 @@ #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" @@ -28,7 +29,9 @@ void AddBlankTabAt(Browser* browser, int index, bool foreground) { params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; params.tabstrip_index = index; chrome::Navigate(¶ms); - params.target_contents->SetNewTabStartTime(new_tab_start_time); + CoreTabHelper* core_tab_helper = + CoreTabHelper::FromWebContents(params.target_contents); + core_tab_helper->set_new_tab_start_time(new_tab_start_time); } content::WebContents* AddSelectedTabWithURL( diff --git a/chrome/browser/ui/cocoa/applescript/window_applescript.mm b/chrome/browser/ui/cocoa/applescript/window_applescript.mm index fe9e055..fe6677f 100644 --- a/chrome/browser/ui/cocoa/applescript/window_applescript.mm +++ b/chrome/browser/ui/cocoa/applescript/window_applescript.mm @@ -21,6 +21,7 @@ #include "chrome/browser/ui/cocoa/applescript/error_applescript.h" #import "chrome/browser/ui/cocoa/applescript/tab_applescript.h" #include "chrome/browser/ui/host_desktop.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/url_constants.h" #include "content/public/browser/web_contents.h" @@ -179,7 +180,8 @@ browser_, GURL(chrome::kChromeUINewTabURL), content::PAGE_TRANSITION_TYPED); - contents->SetNewTabStartTime(newTabStartTime); + CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(contents); + core_tab_helper->set_new_tab_start_time(newTabStartTime); [aTab setWebContents:contents]; } @@ -196,7 +198,9 @@ params.disposition = NEW_FOREGROUND_TAB; params.tabstrip_index = index; chrome::Navigate(¶ms); - params.target_contents->SetNewTabStartTime(newTabStartTime); + CoreTabHelper* core_tab_helper = + CoreTabHelper::FromWebContents(params.target_contents); + core_tab_helper->set_new_tab_start_time(newTabStartTime); [aTab setWebContents:params.target_contents]; } diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.cc b/chrome/browser/ui/tab_contents/core_tab_helper.cc index 502a3f8..a785366 100644 --- a/chrome/browser/ui/tab_contents/core_tab_helper.cc +++ b/chrome/browser/ui/tab_contents/core_tab_helper.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/tab_contents/core_tab_helper.h" +#include "base/metrics/histogram.h" #include "chrome/browser/renderer_host/web_cache_manager.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -84,6 +85,16 @@ string16 CoreTabHelper::GetStatusText() const { return string16(); } +void CoreTabHelper::OnCloseStarted() { + if (close_start_time_.is_null()) + close_start_time_ = base::TimeTicks::Now(); +} + +void CoreTabHelper::OnCloseCanceled() { + close_start_time_ = base::TimeTicks(); + before_unload_end_time_ = base::TimeTicks(); +} + //////////////////////////////////////////////////////////////////////////////// // WebContentsObserver overrides @@ -91,3 +102,24 @@ void CoreTabHelper::WasShown() { WebCacheManager::GetInstance()->ObserveActivity( web_contents()->GetRenderProcessHost()->GetID()); } + +void CoreTabHelper::WebContentsDestroyed(WebContents* web_contents) { + // OnCloseStarted isn't called in unit tests. + if (!close_start_time_.is_null()) { + base::TimeTicks now = base::TimeTicks::Now(); + base::TimeTicks unload_start_time = close_start_time_; + if (!before_unload_end_time_.is_null()) + unload_start_time = before_unload_end_time_; + UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_); + UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time); + } + +} + +void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { + before_unload_end_time_ = proceed_time; +} + +void CoreTabHelper::BeforeUnloadDialogCancelled() { + OnCloseCanceled(); +} diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.h b/chrome/browser/ui/tab_contents/core_tab_helper.h index 834613e..66244b2 100644 --- a/chrome/browser/ui/tab_contents/core_tab_helper.h +++ b/chrome/browser/ui/tab_contents/core_tab_helper.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ #define CHROME_BROWSER_UI_TAB_CONTENTS_CORE_TAB_HELPER_H_ +#include "base/time.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" @@ -16,25 +17,53 @@ class CoreTabHelper : public content::WebContentsObserver, public: virtual ~CoreTabHelper(); - CoreTabHelperDelegate* delegate() const { return delegate_; } - void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; } - // Initial title assigned to NavigationEntries from Navigate. static string16 GetDefaultTitle(); // Returns a human-readable description the tab's loading state. string16 GetStatusText() const; + // Notification that tab closing has started. This can be called multiple + // times, subsequent calls are ignored. + void OnCloseStarted(); + + // Notification that tab closing was cancelled. This can happen when a user + // cancels a window close via another tab's beforeunload dialog. + void OnCloseCanceled(); + + CoreTabHelperDelegate* delegate() const { return delegate_; } + void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; } + + void set_new_tab_start_time(const base::TimeTicks& time) { + new_tab_start_time_ = time; + } + + base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; } + private: explicit CoreTabHelper(content::WebContents* web_contents); friend class content::WebContentsUserData<CoreTabHelper>; // content::WebContentsObserver overrides: virtual void WasShown() OVERRIDE; + virtual void WebContentsDestroyed( + content::WebContents* web_contents) OVERRIDE; + virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE; + virtual void BeforeUnloadDialogCancelled() OVERRIDE; // Delegate for notifying our owner about stuff. Not owned by us. CoreTabHelperDelegate* delegate_; + // The time when we started to create the new tab page. This time is from + // before we created this WebContents. + base::TimeTicks new_tab_start_time_; + + // The time that we started to close this WebContents. + base::TimeTicks close_start_time_; + + // The time when onbeforeunload ended. + base::TimeTicks before_unload_end_time_; + DISALLOW_COPY_AND_ASSIGN(CoreTabHelper); }; diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc index 78c8f0e..a550ca0 100644 --- a/chrome/browser/ui/tabs/tab_strip_model.cc +++ b/chrome/browser/ui/tabs/tab_strip_model.cc @@ -1115,7 +1115,9 @@ bool TabStripModel::InternalCloseTabs(const std::vector<int>& indices, if (index == kNoTab) continue; - closing_contents->OnCloseStarted(); + CoreTabHelper* core_tab_helper = + CoreTabHelper::FromWebContents(closing_contents); + core_tab_helper->OnCloseStarted(); // Update the explicitly closed state. If the unload handlers cancel the // close the state is reset in Browser. We don't update the explicitly diff --git a/chrome/browser/ui/webui/metrics_handler.cc b/chrome/browser/ui/webui/metrics_handler.cc index b57ce0f..9394e07 100644 --- a/chrome/browser/ui/webui/metrics_handler.cc +++ b/chrome/browser/ui/webui/metrics_handler.cc @@ -11,6 +11,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/metrics/metric_event_duration_details.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/user_metrics.h" @@ -82,10 +83,12 @@ void MetricsHandler::HandleLogEventTime(const ListValue* args) { // Not all new tab pages get timed. In those cases, we don't have a // new_tab_start_time_. - if (tab->GetNewTabStartTime().is_null()) + CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); + if (core_tab_helper->new_tab_start_time().is_null()) return; - base::TimeDelta duration = base::TimeTicks::Now() - tab->GetNewTabStartTime(); + base::TimeDelta duration = + base::TimeTicks::Now() - core_tab_helper->new_tab_start_time(); MetricEventDurationDetails details(event_name, static_cast<int>(duration.InMilliseconds())); @@ -96,7 +99,8 @@ void MetricsHandler::HandleLogEventTime(const ListValue* args) { } else if (event_name == "Tab.NewTabOnload") { UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); // The new tab page has finished loading; reset it. - tab->SetNewTabStartTime(base::TimeTicks()); + CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(tab); + core_tab_helper->set_new_tab_start_time(base::TimeTicks()); } else { NOTREACHED(); } |