diff options
| -rw-r--r-- | components/app_modal/javascript_dialog_manager.cc | 30 | ||||
| -rw-r--r-- | tools/metrics/histograms/histograms.xml | 30 |
2 files changed, 60 insertions, 0 deletions
diff --git a/components/app_modal/javascript_dialog_manager.cc b/components/app_modal/javascript_dialog_manager.cc index 43256fe..36153da 100644 --- a/components/app_modal/javascript_dialog_manager.cc +++ b/components/app_modal/javascript_dialog_manager.cc @@ -4,6 +4,7 @@ #include "components/app_modal/javascript_dialog_manager.h" +#include <algorithm> #include <utility> #include "base/bind.h" @@ -25,6 +26,7 @@ #include "ui/gfx/font_list.h" namespace app_modal { + namespace { #if !defined(OS_ANDROID) @@ -56,6 +58,32 @@ bool ShouldDisplaySuppressCheckbox( return extra_data->has_already_shown_a_dialog_; } +enum class DialogType { + JAVASCRIPT, + ON_BEFORE_UNLOAD, +}; + +void LogUMAMessageLengthStats(const base::string16& message, DialogType type) { + if (type == DialogType::JAVASCRIPT) { + UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfJSDialogMessageCharacters", + static_cast<int32_t>(message.length())); + } else { + UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfOnBeforeUnloadMessageCharacters", + static_cast<int32_t>(message.length())); + } + + int32_t newline_count = + std::count_if(message.begin(), message.end(), + [](const base::char16& c) { return c == '\n'; }); + if (type == DialogType::JAVASCRIPT) { + UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfJSDialogMessageNewlines", + newline_count); + } else { + UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfOnBeforeUnloadMessageNewlines", + newline_count); + } +} + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -145,6 +173,7 @@ void JavaScriptDialogManager::RunJavaScriptDialog( extensions_client_->OnDialogOpened(web_contents); + LogUMAMessageLengthStats(message_text, DialogType::JAVASCRIPT); AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( web_contents, &javascript_dialog_extra_data_, @@ -184,6 +213,7 @@ void JavaScriptDialogManager::RunBeforeUnloadDialog( extensions_client_->OnDialogOpened(web_contents); + LogUMAMessageLengthStats(message_text, DialogType::ON_BEFORE_UNLOAD); AppModalDialogQueue::GetInstance()->AddDialog(new JavaScriptAppModalDialog( web_contents, &javascript_dialog_extra_data_, diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 4942854..2bef8c6 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -17914,6 +17914,36 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. </summary> </histogram> +<histogram name="JSDialogs.CountOfJSDialogMessageCharacters"> + <owner>avi@chromium.org</owner> + <summary> + The count of the number of characters in JavaScript dialog messages. + </summary> +</histogram> + +<histogram name="JSDialogs.CountOfJSDialogMessageNewlines"> + <owner>avi@chromium.org</owner> + <summary> + The count of the number of newlines in JavaScript dialog messages. (This + does not count breaks inserted by the UI toolkit in wrapping the messages.) + </summary> +</histogram> + +<histogram name="JSDialogs.CountOfOnBeforeUnloadMessageCharacters"> + <owner>avi@chromium.org</owner> + <summary> + The count of the number of characters in onbeforeunload messages. + </summary> +</histogram> + +<histogram name="JSDialogs.CountOfOnBeforeUnloadMessageNewlines"> + <owner>avi@chromium.org</owner> + <summary> + The count of the number of newlines in onbeforeunload messages. (This does + not count breaks inserted by the UI toolkit in wrapping the messages.) + </summary> +</histogram> + <histogram name="JSDialogs.FineTiming.TimeBetweenDialogClosedAndNextDialogCreated" units="ms"> |
