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

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: Tweak comment, move JS close logic to helper func Created 4 years, 11 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_FINE_TIMES_100(
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_FINE_TIMES_100(
113 "JSDialogs.FineTiming.TimeSinceLastDialogClosed",
114 now - last_close_time_);
115 last_close_time_ = base::TimeTicks();
116 }
117
98 if (extra_data->suppress_javascript_messages_) { 118 if (extra_data->suppress_javascript_messages_) {
99 *did_suppress_message = true; 119 *did_suppress_message = true;
120
121 // Record this as a dialog that was immediately cancelled.
122 UMA_HISTOGRAM_FINE_TIMES_100(
123 "JSDialogs.FineTiming.DialogLifetime",
124 base::TimeDelta());
125 last_close_time_ = base::TimeTicks::Now();
100 return; 126 return;
101 } 127 }
102 128
103 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; 129 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT;
104 base::string16 dialog_title = 130 base::string16 dialog_title =
105 GetTitle(web_contents, origin_url, accept_lang, is_alert); 131 GetTitle(web_contents, origin_url, accept_lang, is_alert);
106 132
107 extensions_client_->OnDialogOpened(web_contents); 133 extensions_client_->OnDialogOpened(web_contents);
108 134
109 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 135 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void JavaScriptDialogManager::OnDialogClosed( 268 void JavaScriptDialogManager::OnDialogClosed(
243 content::WebContents* web_contents, 269 content::WebContents* web_contents,
244 DialogClosedCallback callback, 270 DialogClosedCallback callback,
245 bool success, 271 bool success,
246 const base::string16& user_input) { 272 const base::string16& user_input) {
247 // If an extension opened this dialog then the extension may shut down its 273 // 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 274 // lazy background page after the dialog closes. (Dialogs are closed before
249 // their WebContents is destroyed so |web_contents| is still valid here.) 275 // their WebContents is destroyed so |web_contents| is still valid here.)
250 extensions_client_->OnDialogClosed(web_contents); 276 extensions_client_->OnDialogClosed(web_contents);
251 277
278 last_close_time_ = base::TimeTicks::Now();
279
252 callback.Run(success, user_input); 280 callback.Run(success, user_input);
253 } 281 }
254 282
255 } // namespace app_modal 283 } // namespace app_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698