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

Side by Side Diff: chrome/browser/signin/signin_promo.cc

Issue 1473543002: Implement newly designed sign-in related histograms for desktop platorms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/signin/signin_promo.h" 5 #include "chrome/browser/signin/signin_promo.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 int show_count = profile->GetPrefs()->GetInteger( 158 int show_count = profile->GetPrefs()->GetInteger(
159 prefs::kSignInPromoStartupCount); 159 prefs::kSignInPromoStartupCount);
160 show_count++; 160 show_count++;
161 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count); 161 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count);
162 } 162 }
163 163
164 void SetUserSkippedPromo(Profile* profile) { 164 void SetUserSkippedPromo(Profile* profile) {
165 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true); 165 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true);
166 } 166 }
167 167
168 GURL GetLandingURL(const char* option, int value) { 168 GURL GetLandingURL(signin_metrics::AccessPoint access_point) {
169 std::string url = base::StringPrintf("%s/success.html?%s=%d", 169 std::string url = base::StringPrintf(
170 extensions::kGaiaAuthExtensionOrigin, 170 "%s/success.html?%s=%d", extensions::kGaiaAuthExtensionOrigin,
171 option, 171 kSignInPromoQueryKeyAccessPoint, access_point);
172 value); 172
173 // TODO(gogerald): right now, gaia server needs to distinguish the source from
174 // signin_metrics::SOURCE_START_PAGE, signin_metrics::SOURCE_SETTINGS and
175 // the others to show advanced sync settings, remove them after
176 // switching to Minute Maid sign in flow.
177 if (access_point == signin_metrics::ACCESS_POINT_START_PAGE) {
178 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource,
179 signin_metrics::SOURCE_START_PAGE);
180 } else if (access_point == signin_metrics::ACCESS_POINT_SETTINGS) {
181 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource,
182 signin_metrics::SOURCE_SETTINGS);
183 } else {
184 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource,
185 signin_metrics::SOURCE_OTHERS);
186 }
187
173 return GURL(url); 188 return GURL(url);
174 } 189 }
175 190
176 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { 191 GURL GetPromoURL(signin_metrics::AccessPoint access_point,
177 return GetPromoURL(source, auto_close, false /* is_constrained */); 192 signin_metrics::Reason reason,
193 bool auto_close) {
194 return GetPromoURL(access_point, reason, auto_close,
195 false /* is_constrained */);
178 } 196 }
179 197
180 GURL GetPromoURL(signin_metrics::Source source, 198 GURL GetPromoURL(signin_metrics::AccessPoint access_point,
199 signin_metrics::Reason reason,
181 bool auto_close, 200 bool auto_close,
182 bool is_constrained) { 201 bool is_constrained) {
183 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); 202 CHECK(access_point < signin_metrics::ACCESS_POINT_MAX);
Bernhard Bauer 2015/12/04 11:06:24 CHECK_LT for slightly nicer error messages.
gogerald1 2015/12/04 20:49:09 Done.
203 CHECK(reason < signin_metrics::REASON_MAX);
184 204
185 std::string url(chrome::kChromeUIChromeSigninURL); 205 std::string url(chrome::kChromeUIChromeSigninURL);
186 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); 206 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeyAccessPoint,
207 access_point);
208 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeyReason, reason);
187 if (auto_close) 209 if (auto_close)
188 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); 210 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose);
189 if (is_constrained) 211 if (is_constrained)
190 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); 212 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained);
191 return GURL(url); 213 return GURL(url);
192 } 214 }
193 215
194 GURL GetReauthURL(Profile* profile, const std::string& account_id) { 216 GURL GetReauthURL(signin_metrics::AccessPoint access_point,
217 signin_metrics::Reason reason,
218 Profile* profile,
219 const std::string& account_id) {
195 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile) 220 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile)
196 ->GetAccountInfo(account_id); 221 ->GetAccountInfo(account_id);
197 return GetReauthURLWithEmail(info.email); 222 return GetReauthURLWithEmail(access_point, reason, info.email);
198 } 223 }
199 224
200 GURL GetReauthURLWithEmail(const std::string& email) { 225 GURL GetReauthURLWithEmail(signin_metrics::AccessPoint access_point,
201 GURL url = signin::GetPromoURL( 226 signin_metrics::Reason reason,
202 signin_metrics::SOURCE_REAUTH, true /* auto_close */, 227 const std::string& email) {
203 true /* is_constrained */); 228 GURL url = signin::GetPromoURL(access_point, reason, true /* auto_close */,
229 true /* is_constrained */);
204 230
205 url = net::AppendQueryParameter(url, "email", email); 231 url = net::AppendQueryParameter(url, "email", email);
206 url = net::AppendQueryParameter(url, "validateEmail", "1"); 232 url = net::AppendQueryParameter(url, "validateEmail", "1");
207 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); 233 return net::AppendQueryParameter(url, "readOnlyEmail", "1");
208 } 234 }
209 235
210 GURL GetNextPageURLForPromoURL(const GURL& url) { 236 GURL GetNextPageURLForPromoURL(const GURL& url) {
211 std::string value; 237 std::string value;
212 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { 238 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) {
213 GURL continue_url = GURL(value); 239 GURL continue_url = GURL(value);
214 if (continue_url.is_valid()) 240 if (continue_url.is_valid())
215 return continue_url; 241 return continue_url;
216 } 242 }
217 243
218 return GURL(); 244 return GURL();
219 } 245 }
220 246
221 GURL GetSigninPartitionURL() { 247 GURL GetSigninPartitionURL() {
222 return GURL("chrome-guest://chrome-signin/?"); 248 return GURL("chrome-guest://chrome-signin/?");
223 } 249 }
224 250
225 GURL GetSigninURLFromBubbleViewMode(Profile* profile, 251 GURL GetSigninURLFromBubbleViewMode(Profile* profile,
226 profiles::BubbleViewMode mode) { 252 profiles::BubbleViewMode mode,
253 signin_metrics::AccessPoint access_point) {
227 switch (mode) { 254 switch (mode) {
228 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: 255 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN:
229 return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, 256 return GetPromoURL(access_point,
230 false /* auto_close */, 257 signin_metrics::REASON_SIGNIN_PRIMARY_ACCOUNT,
231 true /* is_constrained */); 258 false /* auto_close */, true /* is_constrained */);
232 break; 259 break;
233 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: 260 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT:
234 return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, 261 return GetPromoURL(access_point,
235 false /* auto_close */, 262 signin_metrics::REASON_ADD_SECONDARY_ACCOUNT,
236 true /* is_constrained */); 263 false /* auto_close */, true /* is_constrained */);
237 break; 264 break;
238 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { 265 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: {
239 const SigninErrorController* error_controller = 266 const SigninErrorController* error_controller =
240 SigninErrorControllerFactory::GetForProfile(profile); 267 SigninErrorControllerFactory::GetForProfile(profile);
241 CHECK(error_controller); 268 CHECK(error_controller);
242 DCHECK(error_controller->HasError()); 269 DCHECK(error_controller->HasError());
243 return GetReauthURL(profile, error_controller->error_account_id()); 270 return GetReauthURL(access_point, signin_metrics::REASON_REAUTHENTICATION,
271 profile, error_controller->error_account_id());
244 break; 272 break;
245 } 273 }
246 default: 274 default:
247 NOTREACHED() << "Called with invalid mode=" << mode; 275 NOTREACHED() << "Called with invalid mode=" << mode;
248 return GURL(); 276 return GURL();
249 } 277 }
250 } 278 }
251 279
252 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { 280 signin_metrics::AccessPoint GetAccessPointForPromoURL(const GURL& url) {
253 std::string value; 281 std::string value;
254 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { 282 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAccessPoint,
255 int source = 0; 283 &value)) {
256 if (base::StringToInt(value, &source) && 284 int access_point = 0;
257 source >= signin_metrics::SOURCE_START_PAGE && 285 if (base::StringToInt(value, &access_point) &&
258 source < signin_metrics::SOURCE_UNKNOWN) { 286 access_point >= signin_metrics::ACCESS_POINT_START_PAGE &&
259 return static_cast<signin_metrics::Source>(source); 287 access_point < signin_metrics::ACCESS_POINT_MAX) {
288 return static_cast<signin_metrics::AccessPoint>(access_point);
260 } 289 }
290 CHECK(false);
261 } 291 }
262 return signin_metrics::SOURCE_UNKNOWN; 292 return signin_metrics::ACCESS_POINT_MAX;
293 }
294
295 signin_metrics::Reason GetSigninReasonForPromoURL(const GURL& url) {
296 std::string value;
297 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyReason, &value)) {
298 int reason = 0;
299 if (base::StringToInt(value, &reason) &&
300 reason >= signin_metrics::REASON_SIGNIN_PRIMARY_ACCOUNT &&
301 reason < signin_metrics::REASON_MAX) {
302 return static_cast<signin_metrics::Reason>(reason);
303 }
304 CHECK(false);
Bernhard Bauer 2015/12/04 11:06:24 Move the condition into the CHECK? Also, seeing as
gogerald1 2015/12/04 20:49:09 Done.
305 }
306 return signin_metrics::REASON_MAX;
263 } 307 }
264 308
265 bool IsAutoCloseEnabledInURL(const GURL& url) { 309 bool IsAutoCloseEnabledInURL(const GURL& url) {
266 std::string value; 310 std::string value;
267 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { 311 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) {
268 int enabled = 0; 312 int enabled = 0;
269 if (base::StringToInt(value, &enabled) && enabled == 1) 313 if (base::StringToInt(value, &enabled) && enabled == 1)
270 return true; 314 return true;
271 } 315 }
272 return false; 316 return false;
(...skipping 16 matching lines...) Expand all
289 333
290 void RegisterProfilePrefs( 334 void RegisterProfilePrefs(
291 user_prefs::PrefRegistrySyncable* registry) { 335 user_prefs::PrefRegistrySyncable* registry) {
292 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); 336 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0);
293 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); 337 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false);
294 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); 338 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true);
295 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); 339 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false);
296 } 340 }
297 341
298 } // namespace signin 342 } // namespace signin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698