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

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

Issue 274057: Add histogram for how tab closing time. Did some cleanup along the way. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/tab_contents/tab_contents.h" 5 #include "chrome/browser/tab_contents/tab_contents.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 last_search_result_(), 258 last_search_result_(),
259 capturing_contents_(false), 259 capturing_contents_(false),
260 is_being_destroyed_(false), 260 is_being_destroyed_(false),
261 notify_disconnection_(false), 261 notify_disconnection_(false),
262 history_requests_(), 262 history_requests_(),
263 #if defined(OS_WIN) 263 #if defined(OS_WIN)
264 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), 264 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
265 #endif 265 #endif
266 last_javascript_message_dismissal_(), 266 last_javascript_message_dismissal_(),
267 suppress_javascript_messages_(false), 267 suppress_javascript_messages_(false),
268 is_showing_before_unload_dialog_(false),
268 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI) { 269 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI) {
269 pending_install_.page_id = 0; 270 pending_install_.page_id = 0;
270 pending_install_.callback_functor = NULL; 271 pending_install_.callback_functor = NULL;
271 272
272 #if defined(OS_CHROMEOS) 273 #if defined(OS_CHROMEOS)
273 // Make sure the thumbnailer is started before starting the render manager. 274 // Make sure the thumbnailer is started before starting the render manager.
274 // The thumbnailer will want to listen for RVH creations, one of which will 275 // The thumbnailer will want to listen for RVH creations, one of which will
275 // happen in RVHManager::Init. 276 // happen in RVHManager::Init.
276 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); 277 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
277 if (generator) 278 if (generator)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 368 }
368 infobar_delegates_.clear(); 369 infobar_delegates_.clear();
369 370
370 // TODO(brettw) this should be moved to the view. 371 // TODO(brettw) this should be moved to the view.
371 #if defined(OS_WIN) 372 #if defined(OS_WIN)
372 // If we still have a window handle, destroy it. GetNativeView can return 373 // If we still have a window handle, destroy it. GetNativeView can return
373 // NULL if this contents was part of a window that closed. 374 // NULL if this contents was part of a window that closed.
374 if (GetNativeView()) 375 if (GetNativeView())
375 ::DestroyWindow(GetNativeView()); 376 ::DestroyWindow(GetNativeView());
376 #endif 377 #endif
378
379 // OnCloseStarted isn't called in unit tests.
380 if (!tab_close_start_time_.is_null()) {
381 UMA_HISTOGRAM_TIMES("Tab.Close",
382 base::TimeTicks::Now() - tab_close_start_time_);
383 }
377 } 384 }
378 385
379 // static 386 // static
380 void TabContents::RegisterUserPrefs(PrefService* prefs) { 387 void TabContents::RegisterUserPrefs(PrefService* prefs) {
381 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); 388 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
382 389
383 WebPreferences pref_defaults; 390 WebPreferences pref_defaults;
384 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, 391 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
385 pref_defaults.javascript_enabled); 392 pref_defaults.javascript_enabled);
386 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, 393 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1112 }
1106 1113
1107 void TabContents::GetPageLanguage() { 1114 void TabContents::GetPageLanguage() {
1108 render_view_host()->GetPageLanguage(); 1115 render_view_host()->GetPageLanguage();
1109 } 1116 }
1110 1117
1111 void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg, 1118 void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1112 bool success, 1119 bool success,
1113 const std::wstring& prompt) { 1120 const std::wstring& prompt) {
1114 last_javascript_message_dismissal_ = base::TimeTicks::Now(); 1121 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1115 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt); 1122 if (is_showing_before_unload_dialog_ && !success) {
1123 // If a beforeunload dialog is canceled, we need to stop the throbber from
1124 // spinning, since we forced it to start spinning in Navigate.
1125 DidStopLoading();
1126
1127 tab_close_start_time_ = base::TimeTicks();
1128 }
1129 is_showing_before_unload_dialog_ = false;
1130 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
1116 } 1131 }
1117 1132
1118 void TabContents::OnSavePage() { 1133 void TabContents::OnSavePage() {
1119 // If we can not save the page, try to download it. 1134 // If we can not save the page, try to download it.
1120 if (!SavePackage::IsSavableContents(contents_mime_type())) { 1135 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1121 DownloadManager* dlm = profile()->GetDownloadManager(); 1136 DownloadManager* dlm = profile()->GetDownloadManager();
1122 const GURL& current_page_url = GetURL(); 1137 const GURL& current_page_url = GetURL();
1123 if (dlm && current_page_url.is_valid()) 1138 if (dlm && current_page_url.is_valid())
1124 dlm->DownloadUrl(current_page_url, GURL(), "", this); 1139 dlm->DownloadUrl(current_page_url, GURL(), "", this);
1125 return; 1140 return;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 void TabContents::LogNewTabTime(const std::string& event_name) { 1188 void TabContents::LogNewTabTime(const std::string& event_name) {
1174 // Not all new tab pages get timed. In those cases, we don't have a 1189 // Not all new tab pages get timed. In those cases, we don't have a
1175 // new_tab_start_time_. 1190 // new_tab_start_time_.
1176 if (new_tab_start_time_.is_null()) 1191 if (new_tab_start_time_.is_null())
1177 return; 1192 return;
1178 1193
1179 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_; 1194 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
1180 MetricEventDurationDetails details(event_name, 1195 MetricEventDurationDetails details(event_name,
1181 static_cast<int>(duration.InMilliseconds())); 1196 static_cast<int>(duration.InMilliseconds()));
1182 1197
1183 if (event_name == "NewTab.ScriptStart") { 1198 if (event_name == "Tab.NewTabScriptStart") {
1184 UMA_HISTOGRAM_TIMES("NewTab.ScriptStart", duration); 1199 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1185 } else if (event_name == "NewTab.DOMContentLoaded") { 1200 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1186 UMA_HISTOGRAM_TIMES("NewTab.DOMContentLoaded", duration); 1201 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1187 } else if (event_name == "NewTab.Onload") { 1202 } else if (event_name == "Tab.NewTabOnload") {
1188 UMA_HISTOGRAM_TIMES("NewTab.Onload", duration); 1203 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
1189 // The new tab page has finished loading; reset it. 1204 // The new tab page has finished loading; reset it.
1190 new_tab_start_time_ = base::TimeTicks(); 1205 new_tab_start_time_ = base::TimeTicks();
1191 } else { 1206 } else {
1192 NOTREACHED(); 1207 NOTREACHED();
1193 } 1208 }
1194 NotificationService::current()->Notify( 1209 NotificationService::current()->Notify(
1195 NotificationType::METRIC_EVENT_DURATION, 1210 NotificationType::METRIC_EVENT_DURATION,
1196 Source<TabContents>(this), 1211 Source<TabContents>(this),
1197 Details<MetricEventDurationDetails>(&details)); 1212 Details<MetricEventDurationDetails>(&details));
1198 } 1213 }
1199 1214
1215 void TabContents::OnCloseStarted() {
1216 if (tab_close_start_time_.is_null())
tony 2009/10/14 23:20:06 Is it possible for this to be called twice?
jam 2009/10/14 23:31:11 Yes it does, since InternalCloseTabs will get call
1217 tab_close_start_time_ = base::TimeTicks::Now();
1218 }
1219
1200 // Notifies the RenderWidgetHost instance about the fact that the page is 1220 // Notifies the RenderWidgetHost instance about the fact that the page is
1201 // loading, or done loading and calls the base implementation. 1221 // loading, or done loading and calls the base implementation.
1202 void TabContents::SetIsLoading(bool is_loading, 1222 void TabContents::SetIsLoading(bool is_loading,
1203 LoadNotificationDetails* details) { 1223 LoadNotificationDetails* details) {
1204 if (is_loading == is_loading_) 1224 if (is_loading == is_loading_)
1205 return; 1225 return;
1206 1226
1207 if (!is_loading) { 1227 if (!is_loading) {
1208 load_state_ = net::LOAD_STATE_IDLE; 1228 load_state_ = net::LOAD_STATE_IDLE;
1209 load_state_host_.clear(); 1229 load_state_host_.clear();
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 // Ignore this if it comes from a RenderViewHost that we aren't showing. 2163 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2144 if (delegate() && rvh == render_view_host()) 2164 if (delegate() && rvh == render_view_host())
2145 delegate()->CloseContents(this); 2165 delegate()->CloseContents(this);
2146 } 2166 }
2147 2167
2148 void TabContents::RequestMove(const gfx::Rect& new_bounds) { 2168 void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2149 if (delegate() && delegate()->IsPopup(this)) 2169 if (delegate() && delegate()->IsPopup(this))
2150 delegate()->MoveContents(this, new_bounds); 2170 delegate()->MoveContents(this, new_bounds);
2151 } 2171 }
2152 2172
2153 void TabContents::DidStartLoading(RenderViewHost* rvh) { 2173 void TabContents::DidStartLoading() {
2154 SetIsLoading(true, NULL); 2174 SetIsLoading(true, NULL);
2155 } 2175 }
2156 2176
2157 void TabContents::DidStopLoading(RenderViewHost* rvh) { 2177 void TabContents::DidStopLoading() {
2158 scoped_ptr<LoadNotificationDetails> details; 2178 scoped_ptr<LoadNotificationDetails> details;
2159 2179
2160 NavigationEntry* entry = controller_.GetActiveEntry(); 2180 NavigationEntry* entry = controller_.GetActiveEntry();
2161 // An entry may not exist for a stop when loading an initial blank page or 2181 // An entry may not exist for a stop when loading an initial blank page or
2162 // if an iframe injected by script into a blank page finishes loading. 2182 // if an iframe injected by script into a blank page finishes loading.
2163 if (entry) { 2183 if (entry) {
2164 scoped_ptr<base::ProcessMetrics> metrics( 2184 scoped_ptr<base::ProcessMetrics> metrics(
2165 base::ProcessMetrics::CreateProcessMetrics( 2185 base::ProcessMetrics::CreateProcessMetrics(
2166 process()->process().handle())); 2186 process()->process().handle()));
2167 2187
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2286 show_suppress_checkbox, reply_msg); 2306 show_suppress_checkbox, reply_msg);
2287 } else { 2307 } else {
2288 // If we are suppressing messages, just reply as is if the user immediately 2308 // If we are suppressing messages, just reply as is if the user immediately
2289 // pressed "Cancel". 2309 // pressed "Cancel".
2290 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring()); 2310 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2291 } 2311 }
2292 } 2312 }
2293 2313
2294 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, 2314 void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2295 IPC::Message* reply_msg) { 2315 IPC::Message* reply_msg) {
2316 is_showing_before_unload_dialog_ = true;
2296 RunBeforeUnloadDialog(this, message, reply_msg); 2317 RunBeforeUnloadDialog(this, message, reply_msg);
2297 } 2318 }
2298 2319
2299 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, 2320 void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2300 const std::string& json_arguments, 2321 const std::string& json_arguments,
2301 IPC::Message* reply_msg) { 2322 IPC::Message* reply_msg) {
2302 if (delegate()) { 2323 if (delegate()) {
2303 HtmlDialogUIDelegate* dialog_delegate = 2324 HtmlDialogUIDelegate* dialog_delegate =
2304 new ModalHtmlDialogDelegate(url, width, height, json_arguments, 2325 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
2305 reply_msg, this); 2326 reply_msg, this);
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 2619
2599 default: 2620 default:
2600 NOTREACHED(); 2621 NOTREACHED();
2601 } 2622 }
2602 } 2623 }
2603 2624
2604 void TabContents::set_encoding(const std::string& encoding) { 2625 void TabContents::set_encoding(const std::string& encoding) {
2605 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); 2626 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2606 } 2627 }
2607 2628
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698