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

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: Rename histograms; ignore blocked JS dialogs 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
98 if (extra_data->suppress_javascript_messages_) { 99 if (extra_data->suppress_javascript_messages_) {
99 *did_suppress_message = true; 100 *did_suppress_message = true;
100 return; 101 return;
101 } 102 }
102 103
104 base::TimeTicks now = base::TimeTicks::Now();
105 if (!last_creation_time_.is_null()) {
106 // A new dialog has been created: log the time since the last one was
107 // created.
108 UMA_HISTOGRAM_MEDIUM_TIMES(
109 "JSDialogs.FineTiming.TimeBetweenDialogCreatedAndNextDialogCreated",
110 now - last_creation_time_);
111 }
112 last_creation_time_ = now;
113
114 // Also log the time since a dialog was closed, but only if this is the first
115 // dialog that was opened since the closing.
116 if (!last_close_time_.is_null()) {
117 UMA_HISTOGRAM_MEDIUM_TIMES(
118 "JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated",
119 now - last_close_time_);
120 last_close_time_ = base::TimeTicks();
121 }
122
103 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT; 123 bool is_alert = message_type == content::JAVASCRIPT_MESSAGE_TYPE_ALERT;
104 base::string16 dialog_title = 124 base::string16 dialog_title =
105 GetTitle(web_contents, origin_url, accept_lang, is_alert); 125 GetTitle(web_contents, origin_url, accept_lang, is_alert);
106 126
107 extensions_client_->OnDialogOpened(web_contents); 127 extensions_client_->OnDialogOpened(web_contents);
108 128
109 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( 129 AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog(
110 web_contents, 130 web_contents,
111 &javascript_dialog_extra_data_, 131 &javascript_dialog_extra_data_,
112 dialog_title, 132 dialog_title,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 void JavaScriptDialogManager::OnDialogClosed( 262 void JavaScriptDialogManager::OnDialogClosed(
243 content::WebContents* web_contents, 263 content::WebContents* web_contents,
244 DialogClosedCallback callback, 264 DialogClosedCallback callback,
245 bool success, 265 bool success,
246 const base::string16& user_input) { 266 const base::string16& user_input) {
247 // If an extension opened this dialog then the extension may shut down its 267 // 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 268 // lazy background page after the dialog closes. (Dialogs are closed before
249 // their WebContents is destroyed so |web_contents| is still valid here.) 269 // their WebContents is destroyed so |web_contents| is still valid here.)
250 extensions_client_->OnDialogClosed(web_contents); 270 extensions_client_->OnDialogClosed(web_contents);
251 271
272 last_close_time_ = base::TimeTicks::Now();
273
252 callback.Run(success, user_input); 274 callback.Run(success, user_input);
253 } 275 }
254 276
255 } // namespace app_modal 277 } // namespace app_modal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698