Chromium Code Reviews| Index: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc |
| diff --git a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc |
| index 86199c0a73b23835851d915851406c43bc56f667..a284efdabe2ee29dfa82d609d1d4612b625f40b4 100644 |
| --- a/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc |
| +++ b/chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc |
| @@ -5,6 +5,9 @@ |
| #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
| #include "base/feature_list.h" |
| +#include "base/metrics/histogram_macros.h" |
| +#include "chrome/browser/engagement/site_engagement_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "components/app_modal/javascript_dialog_manager.h" |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); |
| @@ -43,19 +46,62 @@ void JavaScriptDialogTabHelper::RunJavaScriptDialog( |
| const base::string16& default_prompt_text, |
| const DialogClosedCallback& callback, |
| bool* did_suppress_message) { |
| - if (!IsEnabled()) { |
| - return AppModalDialogManager()->RunJavaScriptDialog( |
| + Profile* profile = |
|
dominickn
2016/09/06 23:50:29
Minor nit - you could inline the Profile::FromBrow
Avi (use Gerrit)
2016/09/07 16:41:55
Done.
|
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + SiteEngagementService* site_engagement_service = |
| + SiteEngagementService::Get(profile); |
| + UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteKarmaOfDialogs", |
| + site_engagement_service->GetScore(origin_url)); |
| + int32_t message_length = static_cast<int32_t>(message_text.length()); |
| + switch (site_engagement_service->GetEngagementLevel(origin_url)) { |
| + case SiteEngagementService::ENGAGEMENT_LEVEL_NONE: { |
|
dominickn
2016/09/06 23:50:29
I think it might be better to base these histogram
Avi (use Gerrit)
2016/09/07 16:41:55
Done.
Also, is it OK to use "karma" as a term in
|
| + UMA_HISTOGRAM_COUNTS( |
| + "JSDialogs.CountOfJSDialogMessageCharactersKarmaNone", |
| + message_length); |
| + break; |
| + } |
| + |
| + case SiteEngagementService::ENGAGEMENT_LEVEL_LOW: { |
| + UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfJSDialogMessageCharactersKarmaLow", |
| + message_length); |
| + break; |
| + } |
| + |
| + default: { |
| + UMA_HISTOGRAM_COUNTS( |
| + "JSDialogs.CountOfJSDialogMessageCharactersKarmaHigher", |
| + message_length); |
| + break; |
| + } |
| + } |
| + |
| + if (IsEnabled()) { |
| + NOTREACHED() << "auto-dismissing dialog code does not yet exist"; |
| + } else { |
| + AppModalDialogManager()->RunJavaScriptDialog( |
| web_contents, origin_url, message_type, message_text, |
| default_prompt_text, callback, did_suppress_message); |
| } |
| - NOTREACHED() << "auto-dismissing dialog code does not yet exist"; |
| + if (did_suppress_message) { |
| + UMA_HISTOGRAM_COUNTS( |
| + "JSDialogs.CountOfJSDialogMessageCharactersUserSuppressed", |
| + message_length); |
| + } |
| } |
| void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( |
| content::WebContents* web_contents, |
| bool is_reload, |
| const DialogClosedCallback& callback) { |
| + Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + SiteEngagementService* site_engagement_service = |
| + SiteEngagementService::Get(profile); |
| + UMA_HISTOGRAM_PERCENTAGE( |
| + "JSDialogs.SiteKarmaOfBeforeUnload", |
| + site_engagement_service->GetScore(web_contents->GetLastCommittedURL())); |
| + |
| // onbeforeunload dialogs are always handled with an app-modal dialog, because |
| // - they are critical to the user not losing data |
| // - they can be requested for tabs that are not foremost |