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

Side by Side Diff: components/app_modal/javascript_dialog_manager.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: Use standard UMA time macros Created 4 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/app_modal/javascript_dialog_manager.h" 5 #include "components/app_modal/javascript_dialog_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "components/app_modal/app_modal_dialog.h" 14 #include "components/app_modal/app_modal_dialog.h"
14 #include "components/app_modal/app_modal_dialog_queue.h" 15 #include "components/app_modal/app_modal_dialog_queue.h"
15 #include "components/app_modal/javascript_app_modal_dialog.h" 16 #include "components/app_modal/javascript_app_modal_dialog.h"
16 #include "components/app_modal/javascript_dialog_extensions_client.h" 17 #include "components/app_modal/javascript_dialog_extensions_client.h"
17 #include "components/app_modal/javascript_native_dialog_factory.h" 18 #include "components/app_modal/javascript_native_dialog_factory.h"
18 #include "components/app_modal/native_app_modal_dialog.h" 19 #include "components/app_modal/native_app_modal_dialog.h"
19 #include "components/url_formatter/elide_url.h" 20 #include "components/url_formatter/elide_url.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/javascript_message_type.h" 22 #include "content/public/common/javascript_message_type.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 const base::string16& default_prompt_text, 89 const base::string16& default_prompt_text,
89 const DialogClosedCallback& callback, 90 const DialogClosedCallback& callback,
90 bool* did_suppress_message) { 91 bool* did_suppress_message) {
91 *did_suppress_message = false; 92 *did_suppress_message = false;
92 93
93 ChromeJavaScriptDialogExtraData* extra_data = 94 ChromeJavaScriptDialogExtraData* extra_data =
94 &javascript_dialog_extra_data_ 95 &javascript_dialog_extra_data_
95 [JavaScriptAppModalDialog::GetSerializedOriginForWebContents( 96 [JavaScriptAppModalDialog::GetSerializedOriginForWebContents(
96 web_contents)]; 97 web_contents)];
97 98
99 base::TimeTicks now = base::TimeTicks::Now();
100 if (!last_creation_time_.is_null()) {
101 // A new dialog has been created: log the time since the last one was
102 // created.
103 UMA_HISTOGRAM_MEDIUM_TIMES(
104 "JSDialogs.FineTiming.TimeSinceLastDialogCreated",
105 now - last_creation_time_);
106 }
107 last_creation_time_ = now;
108
109 // Also log the time since a dialog was closed, but only if this is the first
110 // dialog that was opened since the closing.
111 if (!last_close_time_.is_null()) {
112 UMA_HISTOGRAM_MEDIUM_TIMES("JSDialogs.FineTiming.TimeSinceLastDialogClosed",
113 now - last_close_time_);
114 last_close_time_ = base::TimeTicks();
115 }
116
98 if (extra_data->suppress_javascript_messages_) { 117 if (extra_data->suppress_javascript_messages_) {
99 *did_suppress_message = true; 118 *did_suppress_message = true;
119
120 // Record this as a dialog that was immediately cancelled.
121 UMA_HISTOGRAM_MEDIUM_TIMES("JSDialogs.FineTiming.DialogLifetime",
122 base::TimeDelta());
123 last_close_time_ = base::TimeTicks::Now();
100 return; 124 return;
101 } 125 }
102 126
103 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; 127 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT;
104 base::string16 dialog_title = 128 base::string16 dialog_title =
105 GetTitle(web_contents, origin_url, accept_lang, is_alert); 129 GetTitle(web_contents, origin_url, accept_lang, is_alert);
106 130
107 extensions_client_->OnDialogOpened(web_contents); 131 extensions_client_->OnDialogOpened(web_contents);
108 132
109 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 133 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void JavaScriptDialogManager::OnDialogClosed( 266 void JavaScriptDialogManager::OnDialogClosed(
243 content::WebContents* web_contents, 267 content::WebContents* web_contents,
244 DialogClosedCallback callback, 268 DialogClosedCallback callback,
245 bool success, 269 bool success,
246 const base::string16& user_input) { 270 const base::string16& user_input) {
247 // If an extension opened this dialog then the extension may shut down its 271 // If an extension opened this dialog then the extension may shut down its
248 // lazy background page after the dialog closes. (Dialogs are closed before 272 // lazy background page after the dialog closes. (Dialogs are closed before
249 // their WebContents is destroyed so |web_contents| is still valid here.) 273 // their WebContents is destroyed so |web_contents| is still valid here.)
250 extensions_client_->OnDialogClosed(web_contents); 274 extensions_client_->OnDialogClosed(web_contents);
251 275
276 last_close_time_ = base::TimeTicks::Now();
277
252 callback.Run(success, user_input); 278 callback.Run(success, user_input);
253 } 279 }
254 280
255 } // namespace app_modal 281 } // namespace app_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698