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

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: xml tweaks 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.SiteEngagementOfDialogs",
53 engagement_score);
54 int32_t message_length = static_cast<int32_t>(message_text.length());
55 if (engagement_score == 0) {
56 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharacters.EngagementNone",
57 message_length);
58 } else if (engagement_score < 1) {
59 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharacters.EngagementLessThanOne",
60 message_length);
61 } else if (engagement_score < 5) {
62 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharacters.EngagementOneToFive",
63 message_length);
64 } else {
65 UMA_HISTOGRAM_COUNTS("JSDialogs.CountOfCharacters.EngagementHigher",
66 message_length);
67 }
68
69 if (IsEnabled()) {
70 NOTREACHED() << "auto-dismissing dialog code does not yet exist";
71 } else {
72 AppModalDialogManager()->RunJavaScriptDialog(
48 web_contents, origin_url, message_type, message_text, 73 web_contents, origin_url, message_type, message_text,
49 default_prompt_text, callback, did_suppress_message); 74 default_prompt_text, callback, did_suppress_message);
50 } 75 }
51 76
52 NOTREACHED() << "auto-dismissing dialog code does not yet exist"; 77 if (did_suppress_message) {
78 UMA_HISTOGRAM_COUNTS("JSDialogs.CharacterCountUserSuppressed",
79 message_length);
80 }
53 } 81 }
54 82
55 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog( 83 void JavaScriptDialogTabHelper::RunBeforeUnloadDialog(
56 content::WebContents* web_contents, 84 content::WebContents* web_contents,
57 bool is_reload, 85 bool is_reload,
58 const DialogClosedCallback& callback) { 86 const DialogClosedCallback& callback) {
87 Profile* profile =
88 Profile::FromBrowserContext(web_contents->GetBrowserContext());
89 SiteEngagementService* site_engagement_service =
90 SiteEngagementService::Get(profile);
91 UMA_HISTOGRAM_PERCENTAGE(
92 "JSDialogs.SiteEngagementOfBeforeUnload",
93 site_engagement_service->GetScore(web_contents->GetLastCommittedURL()));
94
59 // onbeforeunload dialogs are always handled with an app-modal dialog, because 95 // onbeforeunload dialogs are always handled with an app-modal dialog, because
60 // - they are critical to the user not losing data 96 // - they are critical to the user not losing data
61 // - they can be requested for tabs that are not foremost 97 // - they can be requested for tabs that are not foremost
62 // - they can be requested for many tabs at the same time 98 // - they can be requested for many tabs at the same time
63 // and therefore auto-dismissal is inappropriate for them. 99 // and therefore auto-dismissal is inappropriate for them.
64 100
65 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload, 101 return AppModalDialogManager()->RunBeforeUnloadDialog(web_contents, is_reload,
66 callback); 102 callback);
67 } 103 }
68 104
(...skipping 19 matching lines...) Expand all
88 } 124 }
89 125
90 void JavaScriptDialogTabHelper::ResetDialogState( 126 void JavaScriptDialogTabHelper::ResetDialogState(
91 content::WebContents* web_contents) { 127 content::WebContents* web_contents) {
92 // Reset any app-modal dialog state that may exist. 128 // Reset any app-modal dialog state that may exist.
93 if (!IsEnabled()) 129 if (!IsEnabled())
94 return AppModalDialogManager()->ResetDialogState(web_contents); 130 return AppModalDialogManager()->ResetDialogState(web_contents);
95 131
96 // More work here for the auto-dismissing dialogs. 132 // More work here for the auto-dismissing dialogs.
97 } 133 }
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