| OLD | NEW |
| 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 Loading... |
| 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, static_cast<int>(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::AccessPoint::ACCESS_POINT_START_PAGE) { |
| 178 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 179 signin_metrics::SOURCE_START_PAGE); |
| 180 } else if (access_point == |
| 181 signin_metrics::AccessPoint::ACCESS_POINT_SETTINGS) { |
| 182 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 183 signin_metrics::SOURCE_SETTINGS); |
| 184 } else { |
| 185 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 186 signin_metrics::SOURCE_OTHERS); |
| 187 } |
| 188 |
| 173 return GURL(url); | 189 return GURL(url); |
| 174 } | 190 } |
| 175 | 191 |
| 176 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { | 192 GURL GetPromoURL(signin_metrics::AccessPoint access_point, |
| 177 return GetPromoURL(source, auto_close, false /* is_constrained */); | 193 signin_metrics::Reason reason, |
| 194 bool auto_close) { |
| 195 return GetPromoURL(access_point, reason, auto_close, |
| 196 false /* is_constrained */); |
| 178 } | 197 } |
| 179 | 198 |
| 180 GURL GetPromoURL(signin_metrics::Source source, | 199 GURL GetPromoURL(signin_metrics::AccessPoint access_point, |
| 200 signin_metrics::Reason reason, |
| 181 bool auto_close, | 201 bool auto_close, |
| 182 bool is_constrained) { | 202 bool is_constrained) { |
| 183 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); | 203 CHECK_LT(static_cast<int>(access_point), |
| 204 static_cast<int>(signin_metrics::AccessPoint::ACCESS_POINT_MAX)); |
| 205 CHECK_LT(static_cast<int>(reason), |
| 206 static_cast<int>(signin_metrics::Reason::REASON_MAX)); |
| 184 | 207 |
| 185 std::string url(chrome::kChromeUIChromeSigninURL); | 208 std::string url(chrome::kChromeUIChromeSigninURL); |
| 186 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); | 209 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeyAccessPoint, |
| 210 static_cast<int>(access_point)); |
| 211 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeyReason, |
| 212 static_cast<int>(reason)); |
| 187 if (auto_close) | 213 if (auto_close) |
| 188 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); | 214 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); |
| 189 if (is_constrained) | 215 if (is_constrained) |
| 190 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); | 216 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); |
| 191 return GURL(url); | 217 return GURL(url); |
| 192 } | 218 } |
| 193 | 219 |
| 194 GURL GetReauthURL(Profile* profile, const std::string& account_id) { | 220 GURL GetReauthURL(signin_metrics::AccessPoint access_point, |
| 221 signin_metrics::Reason reason, |
| 222 Profile* profile, |
| 223 const std::string& account_id) { |
| 195 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile) | 224 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile) |
| 196 ->GetAccountInfo(account_id); | 225 ->GetAccountInfo(account_id); |
| 197 return GetReauthURLWithEmail(info.email); | 226 return GetReauthURLWithEmail(access_point, reason, info.email); |
| 198 } | 227 } |
| 199 | 228 |
| 200 GURL GetReauthURLWithEmail(const std::string& email) { | 229 GURL GetReauthURLWithEmail(signin_metrics::AccessPoint access_point, |
| 201 GURL url = signin::GetPromoURL( | 230 signin_metrics::Reason reason, |
| 202 signin_metrics::SOURCE_REAUTH, true /* auto_close */, | 231 const std::string& email) { |
| 203 true /* is_constrained */); | 232 GURL url = signin::GetPromoURL(access_point, reason, true /* auto_close */, |
| 233 true /* is_constrained */); |
| 204 | 234 |
| 205 url = net::AppendQueryParameter(url, "email", email); | 235 url = net::AppendQueryParameter(url, "email", email); |
| 206 url = net::AppendQueryParameter(url, "validateEmail", "1"); | 236 url = net::AppendQueryParameter(url, "validateEmail", "1"); |
| 207 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); | 237 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); |
| 208 } | 238 } |
| 209 | 239 |
| 210 GURL GetNextPageURLForPromoURL(const GURL& url) { | 240 GURL GetNextPageURLForPromoURL(const GURL& url) { |
| 211 std::string value; | 241 std::string value; |
| 212 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { | 242 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { |
| 213 GURL continue_url = GURL(value); | 243 GURL continue_url = GURL(value); |
| 214 if (continue_url.is_valid()) | 244 if (continue_url.is_valid()) |
| 215 return continue_url; | 245 return continue_url; |
| 216 } | 246 } |
| 217 | 247 |
| 218 return GURL(); | 248 return GURL(); |
| 219 } | 249 } |
| 220 | 250 |
| 221 GURL GetSigninPartitionURL() { | 251 GURL GetSigninPartitionURL() { |
| 222 return GURL("chrome-guest://chrome-signin/?"); | 252 return GURL("chrome-guest://chrome-signin/?"); |
| 223 } | 253 } |
| 224 | 254 |
| 225 GURL GetSigninURLFromBubbleViewMode(Profile* profile, | 255 GURL GetSigninURLFromBubbleViewMode(Profile* profile, |
| 226 profiles::BubbleViewMode mode) { | 256 profiles::BubbleViewMode mode, |
| 257 signin_metrics::AccessPoint access_point) { |
| 227 switch (mode) { | 258 switch (mode) { |
| 228 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: | 259 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: |
| 229 return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, | 260 return GetPromoURL(access_point, |
| 230 false /* auto_close */, | 261 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT, |
| 231 true /* is_constrained */); | 262 false /* auto_close */, true /* is_constrained */); |
| 232 break; | 263 break; |
| 233 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: | 264 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: |
| 234 return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, | 265 return GetPromoURL(access_point, |
| 235 false /* auto_close */, | 266 signin_metrics::Reason::REASON_ADD_SECONDARY_ACCOUNT, |
| 236 true /* is_constrained */); | 267 false /* auto_close */, true /* is_constrained */); |
| 237 break; | 268 break; |
| 238 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { | 269 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { |
| 239 const SigninErrorController* error_controller = | 270 const SigninErrorController* error_controller = |
| 240 SigninErrorControllerFactory::GetForProfile(profile); | 271 SigninErrorControllerFactory::GetForProfile(profile); |
| 241 CHECK(error_controller); | 272 CHECK(error_controller); |
| 242 DCHECK(error_controller->HasError()); | 273 DCHECK(error_controller->HasError()); |
| 243 return GetReauthURL(profile, error_controller->error_account_id()); | 274 return GetReauthURL(access_point, |
| 275 signin_metrics::Reason::REASON_REAUTHENTICATION, |
| 276 profile, error_controller->error_account_id()); |
| 244 break; | 277 break; |
| 245 } | 278 } |
| 246 default: | 279 default: |
| 247 NOTREACHED() << "Called with invalid mode=" << mode; | 280 NOTREACHED() << "Called with invalid mode=" << mode; |
| 248 return GURL(); | 281 return GURL(); |
| 249 } | 282 } |
| 250 } | 283 } |
| 251 | 284 |
| 252 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { | 285 signin_metrics::AccessPoint GetAccessPointForPromoURL(const GURL& url) { |
| 253 std::string value; | 286 std::string value; |
| 254 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { | 287 if (!net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAccessPoint, |
| 255 int source = 0; | 288 &value)) { |
| 256 if (base::StringToInt(value, &source) && | 289 return signin_metrics::AccessPoint::ACCESS_POINT_MAX; |
| 257 source >= signin_metrics::SOURCE_START_PAGE && | |
| 258 source < signin_metrics::SOURCE_UNKNOWN) { | |
| 259 return static_cast<signin_metrics::Source>(source); | |
| 260 } | |
| 261 } | 290 } |
| 262 return signin_metrics::SOURCE_UNKNOWN; | 291 |
| 292 int access_point = 0; |
| 293 CHECK(base::StringToInt(value, &access_point) && |
| 294 static_cast<signin_metrics::AccessPoint>(access_point) >= |
| 295 signin_metrics::AccessPoint::ACCESS_POINT_START_PAGE && |
| 296 static_cast<signin_metrics::AccessPoint>(access_point) < |
| 297 signin_metrics::AccessPoint::ACCESS_POINT_MAX); |
| 298 return static_cast<signin_metrics::AccessPoint>(access_point); |
| 299 } |
| 300 |
| 301 signin_metrics::Reason GetSigninReasonForPromoURL(const GURL& url) { |
| 302 std::string value; |
| 303 if (!net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyReason, &value)) |
| 304 return signin_metrics::Reason::REASON_MAX; |
| 305 |
| 306 int reason = 0; |
| 307 CHECK(base::StringToInt(value, &reason) && |
| 308 static_cast<signin_metrics::Reason>(reason) >= |
| 309 signin_metrics::Reason::REASON_SIGNIN_PRIMARY_ACCOUNT && |
| 310 static_cast<signin_metrics::Reason>(reason) < |
| 311 signin_metrics::Reason::REASON_MAX); |
| 312 return static_cast<signin_metrics::Reason>(reason); |
| 263 } | 313 } |
| 264 | 314 |
| 265 bool IsAutoCloseEnabledInURL(const GURL& url) { | 315 bool IsAutoCloseEnabledInURL(const GURL& url) { |
| 266 std::string value; | 316 std::string value; |
| 267 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { | 317 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { |
| 268 int enabled = 0; | 318 int enabled = 0; |
| 269 if (base::StringToInt(value, &enabled) && enabled == 1) | 319 if (base::StringToInt(value, &enabled) && enabled == 1) |
| 270 return true; | 320 return true; |
| 271 } | 321 } |
| 272 return false; | 322 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 | 339 |
| 290 void RegisterProfilePrefs( | 340 void RegisterProfilePrefs( |
| 291 user_prefs::PrefRegistrySyncable* registry) { | 341 user_prefs::PrefRegistrySyncable* registry) { |
| 292 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); | 342 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); |
| 293 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); | 343 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); |
| 294 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); | 344 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); |
| 295 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); | 345 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); |
| 296 } | 346 } |
| 297 | 347 |
| 298 } // namespace signin | 348 } // namespace signin |
| OLD | NEW |