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

Side by Side Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.cc

Issue 2313973004: Collect data on site engagement vs dialogs. (Closed)
Patch Set: update Created 4 years, 3 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" 5 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
6 6
7 #include "base/feature_list.h" 7 #include "base/feature_list.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/engagement/site_engagement_service.h"
10 #include "chrome/browser/profiles/profile.h"
8 #include "components/app_modal/javascript_dialog_manager.h" 11 #include "components/app_modal/javascript_dialog_manager.h"
9 12
10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper); 13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(JavaScriptDialogTabHelper);
11 14
12 namespace { 15 namespace {
13 16
14 const base::Feature kAutoDismissingDialogsFeature{ 17 const base::Feature kAutoDismissingDialogsFeature{
15 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT}; 18 "AutoDismissingDialogs", base::FEATURE_DISABLED_BY_DEFAULT};
16 19
17 bool IsEnabled() { 20 bool IsEnabled() {
(...skipping 18 matching lines...) Expand all
36 } 39 }
37 40
38 void JavaScriptDialogTabHelper::RunJavaScriptDialog( 41 void JavaScriptDialogTabHelper::RunJavaScriptDialog(
39 content::WebContents* web_contents, 42 content::WebContents* web_contents,
40 const GURL& origin_url, 43 const GURL& origin_url,
41 content::JavaScriptMessageType message_type, 44 content::JavaScriptMessageType message_type,
42 const base::string16& message_text, 45 const base::string16& message_text,
43 const base::string16& default_prompt_text, 46 const base::string16& default_prompt_text,
44 const DialogClosedCallback& callback, 47 const DialogClosedCallback& callback,
45 bool* did_suppress_message) { 48 bool* did_suppress_message) {
46 if (!IsEnabled()) { 49 SiteEngagementService* site_engagement_service = SiteEngagementService::Get(
47 return AppModalDialogManager()->RunJavaScriptDialog( 50 Profile::FromBrowserContext(web_contents->GetBrowserContext()));
51 double engagement_score = site_engagement_service->GetScore(origin_url);
52 UMA_HISTOGRAM_PERCENTAGE("JSDialogs.SiteKarmaOfDialogs", engagement_score);
53 int32_t message_length = static_cast<int32_t>(message_text.length());
54 if (engagement_score == 0) {
55 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharactersKarmaNone",
56 message_length);
57 } else if (engagement_score < 1) {
58 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharactersKarmaLessThanOne",
59 message_length);
60 } else if (engagement_score < 5) {
61 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharactersKarmaOneToFive",
62 message_length);
63 } else {
64 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharactersKarmaHigher",
65 message_length);
66 }
67
68 if (IsEnabled()) {
69 NOTREACHED() << "auto-dismissing dialog code does not yet exist";
70 } else {
71 AppModalDialogManager()->RunJavaScriptDialog(
48 web_contents, origin_url, message_type, message_text, 72 web_contents, origin_url, message_type, message_text,
49 default_prompt_text, callback, did_suppress_message); 73 default_prompt_text, callback, did_suppress_message);
50 } 74 }
51 75
52 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; 76 if (did_suppress_message) {
77 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharactersUserSuppressed",
78 message_length);
79 }
53 } 80 }
54 81
55 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( 82 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog(
56 content::WebContents* web_contents, 83 content::WebContents* web_contents,
57 bool is_reload, 84 bool is_reload,
58 const DialogClosedCallback& callback) { 85 const DialogClosedCallback& callback) {
86 Profile* profile =
87 Profile::FromBrowserContext(web_contents->GetBrowserContext());
88 SiteEngagementService* site_engagement_service =
89 SiteEngagementService::Get(profile);
90 UMA_HISTOGRAM_PERCENTAGE(
91 "JSDialogs.SiteKarmaOfBeforeUnload",
Rick Byers 2016/09/07 18:40:15 You need to add this one to histograms.xml still,
Avi (use Gerrit) 2016/09/07 20:40:12 Yep!
92 site_engagement_service->GetScore(web_contents->GetLastCommittedURL()));
93
59 // onbeforeunload dialogs are always handled with an app-modal dialog, because 94 // onbeforeunload dialogs are always handled with an app-modal dialog, because
60 // - they are critical to the user not losing data 95 // - they are critical to the user not losing data
61 // - they can be requested for tabs that are not foremost 96 // - they can be requested for tabs that are not foremost
62 // - they can be requested for many tabs at the same time 97 // - they can be requested for many tabs at the same time
63 // and therefore auto-dismissal is inappropriate for them. 98 // and therefore auto-dismissal is inappropriate for them.
64 99
65 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, 100 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload,
66 callback); 101 callback);
67 } 102 }
68 103
(...skipping 19 matching lines...) Expand all
88 } 123 }
89 124
90 void JavaScriptDialogTabHelper::ResetDialogState( 125 void JavaScriptDialogTabHelper::ResetDialogState(
91 content::WebContents* web_contents) { 126 content::WebContents* web_contents) {
92 // Reset any app-modal dialog state that may exist. 127 // Reset any app-modal dialog state that may exist.
93 if (!IsEnabled()) 128 if (!IsEnabled())
94 return AppModalDialogManager()->ResetDialogState(web_contents); 129 return AppModalDialogManager()->ResetDialogState(web_contents);
95 130
96 // More work here for the auto-dismissing dialogs. 131 // More work here for the auto-dismissing dialogs.
97 } 132 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698