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

Side by Side Diff: chrome/browser/ui/tab_contents/core_tab_helper.cc

Issue 17571018: Reland fast tab closure behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, 2nd attempt to land. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 5 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
6 6
7 #include "base/command_line.h"
7 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
8 #include "chrome/browser/renderer_host/web_cache_manager.h" 9 #include "chrome/browser/renderer_host/web_cache_manager.h"
10 #include "chrome/common/chrome_switches.h"
9 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
10 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
12 #include "net/base/load_states.h" 14 #include "net/base/load_states.h"
13 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 17
16 using content::WebContents; 18 using content::WebContents;
17 19
18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 88 }
87 89
88 void CoreTabHelper::OnCloseStarted() { 90 void CoreTabHelper::OnCloseStarted() {
89 if (close_start_time_.is_null()) 91 if (close_start_time_.is_null())
90 close_start_time_ = base::TimeTicks::Now(); 92 close_start_time_ = base::TimeTicks::Now();
91 } 93 }
92 94
93 void CoreTabHelper::OnCloseCanceled() { 95 void CoreTabHelper::OnCloseCanceled() {
94 close_start_time_ = base::TimeTicks(); 96 close_start_time_ = base::TimeTicks();
95 before_unload_end_time_ = base::TimeTicks(); 97 before_unload_end_time_ = base::TimeTicks();
98 unload_detached_start_time_ = base::TimeTicks();
99 }
100
101 void CoreTabHelper::OnUnloadStarted() {
102 before_unload_end_time_ = base::TimeTicks::Now();
103 }
104
105 void CoreTabHelper::OnUnloadDetachedStarted() {
106 if (unload_detached_start_time_.is_null())
107 unload_detached_start_time_ = base::TimeTicks::Now();
96 } 108 }
97 109
98 //////////////////////////////////////////////////////////////////////////////// 110 ////////////////////////////////////////////////////////////////////////////////
99 // WebContentsObserver overrides 111 // WebContentsObserver overrides
100 112
101 void CoreTabHelper::WasShown() { 113 void CoreTabHelper::WasShown() {
102 WebCacheManager::GetInstance()->ObserveActivity( 114 WebCacheManager::GetInstance()->ObserveActivity(
103 web_contents()->GetRenderProcessHost()->GetID()); 115 web_contents()->GetRenderProcessHost()->GetID());
104 } 116 }
105 117
106 void CoreTabHelper::WebContentsDestroyed(WebContents* web_contents) { 118 void CoreTabHelper::WebContentsDestroyed(WebContents* web_contents) {
107 // OnCloseStarted isn't called in unit tests. 119 // OnCloseStarted isn't called in unit tests.
108 if (!close_start_time_.is_null()) { 120 if (!close_start_time_.is_null()) {
109 base::TimeTicks now = base::TimeTicks::Now(); 121 bool fast_tab_close_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
110 base::TimeTicks unload_start_time = close_start_time_; 122 switches::kEnableFastUnload);
111 if (!before_unload_end_time_.is_null()) 123
112 unload_start_time = before_unload_end_time_; 124 if (fast_tab_close_enabled) {
113 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_); 125 base::TimeTicks now = base::TimeTicks::Now();
114 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time); 126 base::TimeDelta close_time = now - close_start_time_;
127 UMA_HISTOGRAM_TIMES("Tab.Close", close_time);
128
129 base::TimeTicks unload_start_time = close_start_time_;
130 base::TimeTicks unload_end_time = now;
131 if (!before_unload_end_time_.is_null())
132 unload_start_time = before_unload_end_time_;
133 if (!unload_detached_start_time_.is_null())
134 unload_end_time = unload_detached_start_time_;
135 base::TimeDelta unload_time = unload_end_time - unload_start_time;
136 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", unload_time);
137 } else {
138 base::TimeTicks now = base::TimeTicks::Now();
139 base::TimeTicks unload_start_time = close_start_time_;
140 if (!before_unload_end_time_.is_null())
141 unload_start_time = before_unload_end_time_;
142 UMA_HISTOGRAM_TIMES("Tab.Close", now - close_start_time_);
143 UMA_HISTOGRAM_TIMES("Tab.Close.UnloadTime", now - unload_start_time);
144 }
115 } 145 }
116 146
117 } 147 }
118 148
119 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) { 149 void CoreTabHelper::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
120 before_unload_end_time_ = proceed_time; 150 before_unload_end_time_ = proceed_time;
121 } 151 }
122 152
123 void CoreTabHelper::BeforeUnloadDialogCancelled() { 153 void CoreTabHelper::BeforeUnloadDialogCancelled() {
124 OnCloseCanceled(); 154 OnCloseCanceled();
125 } 155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698