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

Side by Side Diff: chrome/browser/ui/webui/sync_promo_handler.cc

Issue 8528054: Sync Promo: Add more UMA metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more code review changes Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/webui/sync_promo_handler.h" 5 #include "chrome/browser/ui/webui/sync_promo_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/time.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
13 #include "chrome/browser/sync/sync_setup_flow.h" 14 #include "chrome/browser/sync/sync_setup_flow.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 15 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/webui/sync_promo_ui.h" 18 #include "chrome/browser/ui/webui/sync_promo_ui.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "content/browser/tab_contents/tab_contents.h" 23 #include "content/browser/tab_contents/tab_contents.h"
24 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_details.h" 26
27 namespace {
28
29 // User actions on the sync promo (aka "Sign in to Chrome").
30 enum SyncPromoUserFlowActionEnums {
31 SYNC_PROMO_VIEWED,
32 SYNC_PROMO_LEARN_MORE_CLICKED,
33 SYNC_PROMO_ACCOUNT_HELP_CLICKED,
34 SYNC_PROMO_CREATE_ACCOUNT_CLICKED,
35 SYNC_PROMO_SKIP_CLICKED,
36 SYNC_PROMO_SIGN_IN_ATTEMPTED,
37 SYNC_PROMO_SIGNED_IN_SUCCESSFULLY,
38 SYNC_PROMO_ADVANCED_CLICKED,
39 SYNC_PROMO_ENCRYPTION_HELP_CLICKED,
40 SYNC_PROMO_CANCELLED_AFTER_SIGN_IN,
41 SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN,
42 SYNC_PROMO_CLOSED_TAB,
43 SYNC_PROMO_CLOSED_WINDOW,
44 SYNC_PROMO_LEFT_DURING_THROBBER,
45 SYNC_PROMO_BUCKET_BOUNDARY,
46 SYNC_PROMO_FIRST_VALID_JS_ACTION = SYNC_PROMO_LEARN_MORE_CLICKED,
47 SYNC_PROMO_LAST_VALID_JS_ACTION = SYNC_PROMO_CONFIRMED_AFTER_SIGN_IN,
48 };
49
50 // This was added because of the need to change the existing UMA enum for the
51 // sync promo mid-flight. Ideally these values would be contiguous, but the
52 // real world is not always ideal.
53 static bool IsValidUserFlowAction(int action) {
54 return (action >= SYNC_PROMO_FIRST_VALID_JS_ACTION &&
55 action <= SYNC_PROMO_LAST_VALID_JS_ACTION) ||
56 action == SYNC_PROMO_LEFT_DURING_THROBBER;
57 }
58
59 } // namespace
25 60
26 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager) 61 SyncPromoHandler::SyncPromoHandler(ProfileManager* profile_manager)
27 : SyncSetupHandler(profile_manager), 62 : SyncSetupHandler(profile_manager),
28 window_already_closed_(false) { 63 window_already_closed_(false) {
29 } 64 }
30 65
31 SyncPromoHandler::~SyncPromoHandler() { 66 SyncPromoHandler::~SyncPromoHandler() {
32 } 67 }
33 68
34 // static 69 // static
(...skipping 25 matching lines...) Expand all
60 return SyncSetupHandler::Attach(web_ui); 95 return SyncSetupHandler::Attach(web_ui);
61 } 96 }
62 97
63 void SyncPromoHandler::RegisterMessages() { 98 void SyncPromoHandler::RegisterMessages() {
64 web_ui_->RegisterMessageCallback("SyncPromo:Close", 99 web_ui_->RegisterMessageCallback("SyncPromo:Close",
65 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo, 100 base::Bind(&SyncPromoHandler::HandleCloseSyncPromo,
66 base::Unretained(this))); 101 base::Unretained(this)));
67 web_ui_->RegisterMessageCallback("SyncPromo:Initialize", 102 web_ui_->RegisterMessageCallback("SyncPromo:Initialize",
68 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo, 103 base::Bind(&SyncPromoHandler::HandleInitializeSyncPromo,
69 base::Unretained(this))); 104 base::Unretained(this)));
105 web_ui_->RegisterMessageCallback("SyncPromo:RecordSignInAttempts",
106 base::Bind(&SyncPromoHandler::HandleRecordSignInAttempts,
107 base::Unretained(this)));
108 web_ui_->RegisterMessageCallback("SyncPromo:RecordThrobberTime",
109 base::Bind(&SyncPromoHandler::HandleRecordThrobberTime,
110 base::Unretained(this)));
111 web_ui_->RegisterMessageCallback("SyncPromo:ShowAdvancedSettings",
112 base::Bind(&SyncPromoHandler::HandleShowAdvancedSettings,
113 base::Unretained(this)));
70 web_ui_->RegisterMessageCallback("SyncPromo:UserFlowAction", 114 web_ui_->RegisterMessageCallback("SyncPromo:UserFlowAction",
71 base::Bind(&SyncPromoHandler::HandleUserFlowAction, 115 base::Bind(&SyncPromoHandler::HandleUserFlowAction,
72 base::Unretained(this))); 116 base::Unretained(this)));
73 web_ui_->RegisterMessageCallback("SyncPromo:ShowAdvancedSettings", 117 web_ui_->RegisterMessageCallback("SyncPromo:UserSkipped",
74 base::Bind(&SyncPromoHandler::HandleShowAdvancedSettings, 118 base::Bind(&SyncPromoHandler::HandleUserSkipped,
75 base::Unretained(this))); 119 base::Unretained(this)));
76 SyncSetupHandler::RegisterMessages(); 120 SyncSetupHandler::RegisterMessages();
77 } 121 }
78 122
79 void SyncPromoHandler::ShowConfigure(const base::DictionaryValue& args) { 123 void SyncPromoHandler::ShowConfigure(const base::DictionaryValue& args) {
80 bool usePassphrase = false; 124 bool usePassphrase = false;
81 args.GetBoolean("usePassphrase", &usePassphrase); 125 args.GetBoolean("usePassphrase", &usePassphrase);
82 126
83 if (usePassphrase) { 127 if (usePassphrase) {
84 // If a passphrase is required then we must show the configure pane. 128 // If a passphrase is required then we must show the configure pane.
85 SyncSetupHandler::ShowConfigure(args); 129 SyncSetupHandler::ShowConfigure(args);
86 } else { 130 } else {
87 // If no passphrase is required then skip the configure pane and sync 131 // If no passphrase is required then skip the configure pane and sync
88 // everything by default. This makes the first run experience simpler. 132 // everything by default. This makes the first run experience simpler.
89 // Note, there's an advanced link in the sync promo that takes users 133 // Note, there's an advanced link in the sync promo that takes users
90 // to Settings where the configure pane is not skipped. 134 // to Settings where the configure pane is not skipped.
91 SyncConfiguration configuration; 135 SyncConfiguration configuration;
92 configuration.sync_everything = true; 136 configuration.sync_everything = true;
93 DCHECK(flow()); 137 DCHECK(flow());
94 flow()->OnUserConfigured(configuration); 138 flow()->OnUserConfigured(configuration);
95 } 139 }
96 } 140 }
97 141
98 void SyncPromoHandler::Observe(int type, 142 void SyncPromoHandler::Observe(int type,
99 const content::NotificationSource& source, 143 const content::NotificationSource& source,
100 const content::NotificationDetails& details) { 144 const content::NotificationDetails& details) {
101 switch (type) { 145 switch (type) {
102 case content::NOTIFICATION_TAB_CLOSING: { 146 case content::NOTIFICATION_TAB_CLOSING: {
103 if (!window_already_closed_) 147 if (!window_already_closed_)
104 RecordUserFlowAction(extension_misc::SYNC_PROMO_CLOSED_TAB); 148 RecordUserFlowAction(SYNC_PROMO_CLOSED_TAB);
105 break; 149 break;
106 } 150 }
107 case chrome::NOTIFICATION_BROWSER_CLOSING: { 151 case chrome::NOTIFICATION_BROWSER_CLOSING: {
108 // Make sure we're in the tab strip of the closing window. 152 // Make sure we're in the tab strip of the closing window.
109 Browser* browser = content::Source<Browser>(source).ptr(); 153 Browser* browser = content::Source<Browser>(source).ptr();
110 if (browser->tabstrip_model()->GetWrapperIndex( 154 if (browser->tabstrip_model()->GetWrapperIndex(
111 web_ui_->tab_contents()) != TabStripModel::kNoTab) { 155 web_ui_->tab_contents()) != TabStripModel::kNoTab) {
112 RecordUserFlowAction(extension_misc::SYNC_PROMO_CLOSED_WINDOW); 156 RecordUserFlowAction(SYNC_PROMO_CLOSED_WINDOW);
113 window_already_closed_ = true; 157 window_already_closed_ = true;
114 } 158 }
115 break; 159 break;
116 } 160 }
117 default: { 161 default: {
118 NOTREACHED(); 162 NOTREACHED();
119 } 163 }
120 } 164 }
121 } 165 }
122 166
(...skipping 19 matching lines...) Expand all
142 } 186 }
143 187
144 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) { 188 void SyncPromoHandler::HandleInitializeSyncPromo(const base::ListValue* args) {
145 base::FundamentalValue visible(SyncPromoUI::GetShowTitleForSyncPromoURL( 189 base::FundamentalValue visible(SyncPromoUI::GetShowTitleForSyncPromoURL(
146 web_ui_->tab_contents()->GetURL())); 190 web_ui_->tab_contents()->GetURL()));
147 web_ui_->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible", 191 web_ui_->CallJavascriptFunction("SyncSetupOverlay.setPromoTitleVisible",
148 visible); 192 visible);
149 193
150 OpenSyncSetup(); 194 OpenSyncSetup();
151 // We don't need to compute anything for this, just do this every time. 195 // We don't need to compute anything for this, just do this every time.
152 RecordUserFlowAction(extension_misc::SYNC_PROMO_VIEWED); 196 RecordUserFlowAction(SYNC_PROMO_VIEWED);
153 // Increment view count first and show natural numbers in stats rather than 0 197 // Increment view count first and show natural numbers in stats rather than 0
154 // based starting point (if it happened to be our first time showing this). 198 // based starting point (if it happened to be our first time showing this).
155 IncrementViewCountBy(1); 199 IncrementViewCountBy(1);
156 // Record +1 for every view. This is the only thing we record that's not part 200 // Record +1 for every view. This is the only thing we record that's not part
157 // of the user flow histogram. 201 // of the user flow histogram.
158 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount()); 202 UMA_HISTOGRAM_COUNTS("SyncPromo.NumTimesViewed", GetViewCount());
159 } 203 }
160 204
161 void SyncPromoHandler::HandleShowAdvancedSettings( 205 void SyncPromoHandler::HandleShowAdvancedSettings(
162 const base::ListValue* args) { 206 const base::ListValue* args) {
163 CloseSyncSetup(); 207 CloseSyncSetup();
164 std::string url(chrome::kChromeUISettingsURL); 208 std::string url(chrome::kChromeUISettingsURL);
165 url += chrome::kSyncSetupSubPage; 209 url += chrome::kSyncSetupSubPage;
166 web_ui_->tab_contents()->OpenURL(GURL(url), GURL(), CURRENT_TAB, 210 web_ui_->tab_contents()->OpenURL(GURL(url), GURL(), CURRENT_TAB,
167 content::PAGE_TRANSITION_LINK); 211 content::PAGE_TRANSITION_LINK);
168 RecordUserFlowAction(extension_misc::SYNC_PROMO_ADVANCED_CLICKED); 212 RecordUserFlowAction(SYNC_PROMO_ADVANCED_CLICKED);
213 }
214
215 // TODO(dbeam): Replace with metricsHandler:recordHistogramTime when it exists.
216 void SyncPromoHandler::HandleRecordThrobberTime(const base::ListValue* args) {
217 double time_double;
218 CHECK(args->GetDouble(0, &time_double));
219 UMA_HISTOGRAM_TIMES("SyncPromo.ThrobberTime",
220 base::TimeDelta::FromMilliseconds(time_double));
221 }
222
223 // TODO(dbeam): Replace with metricsHandler:recordHistogramCount when it exists.
224 void SyncPromoHandler::HandleRecordSignInAttempts(const base::ListValue* args) {
225 double count_double;
226 CHECK(args->GetDouble(0, &count_double));
227 UMA_HISTOGRAM_COUNTS("SyncPromo.SignInAttempts", count_double);
169 } 228 }
170 229
171 void SyncPromoHandler::HandleUserFlowAction(const base::ListValue* args) { 230 void SyncPromoHandler::HandleUserFlowAction(const base::ListValue* args) {
172 double action_double; 231 double action_double;
173 CHECK(args->GetDouble(0, &action_double)); 232 CHECK(args->GetDouble(0, &action_double));
174 int action = static_cast<int>(action_double); 233 int action = static_cast<int>(action_double);
175 if (action >= extension_misc::SYNC_PROMO_FIRST_VALID_JS_ACTION && 234
176 action <= extension_misc::SYNC_PROMO_LAST_VALID_JS_ACTION) { 235 if (IsValidUserFlowAction(action))
177 RecordUserFlowAction(action); 236 RecordUserFlowAction(action);
178 } else { 237 else
179 NOTREACHED() << "Attempt to record invalid user flow action on sync promo."; 238 NOTREACHED() << "Attempt to record invalid user flow action on sync promo.";
180 } 239 }
181 240
182 if (action == extension_misc::SYNC_PROMO_SKIP_CLICKED) 241 void SyncPromoHandler::HandleUserSkipped(const base::ListValue* args) {
183 SyncPromoUI::SetUserSkippedSyncPromo(Profile::FromWebUI(web_ui_)); 242 SyncPromoUI::SetUserSkippedSyncPromo(Profile::FromWebUI(web_ui_));
243 RecordUserFlowAction(SYNC_PROMO_SKIP_CLICKED);
184 } 244 }
185 245
186 int SyncPromoHandler::GetViewCount() const { 246 int SyncPromoHandler::GetViewCount() const {
187 // The locally persistent number of times the user has seen the sync promo. 247 // The locally persistent number of times the user has seen the sync promo.
188 return prefs_->GetInteger(prefs::kSyncPromoViewCount); 248 return prefs_->GetInteger(prefs::kSyncPromoViewCount);
189 } 249 }
190 250
191 int SyncPromoHandler::IncrementViewCountBy(unsigned int amount) { 251 int SyncPromoHandler::IncrementViewCountBy(unsigned int amount) {
192 // Let the user increment by 0 if they really want. It might be useful for a 252 // Let the user increment by 0 if they really want. It might be useful for a
193 // weird way of sending preference change notifications... 253 // weird way of sending preference change notifications...
194 int adjusted = GetViewCount() + amount; 254 int adjusted = GetViewCount() + amount;
195 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted); 255 prefs_->SetInteger(prefs::kSyncPromoViewCount, adjusted);
196 return adjusted; 256 return adjusted;
197 } 257 }
198 258
199 void SyncPromoHandler::RecordUserFlowAction(int action) { 259 void SyncPromoHandler::RecordUserFlowAction(int action) {
200 // Send an enumeration to our single user flow histogram. 260 // Send an enumeration to our single user flow histogram.
201 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action, 261 UMA_HISTOGRAM_ENUMERATION("SyncPromo.UserFlow", action,
202 extension_misc::SYNC_PROMO_BUCKET_BOUNDARY); 262 SYNC_PROMO_BUCKET_BOUNDARY);
203 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_promo_handler.h ('k') | chrome/common/extensions/extension_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698