| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 const std::string& locale = g_browser_process->GetApplicationLocale(); | 166 const std::string& locale = g_browser_process->GetApplicationLocale(); |
| 167 url = base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str()); | 167 url = base::StringPrintf(kSignInLandingUrlPrefix, locale.c_str()); |
| 168 } else { | 168 } else { |
| 169 url = base::StringPrintf( | 169 url = base::StringPrintf( |
| 170 "%s/success.html", extensions::kGaiaAuthExtensionOrigin); | 170 "%s/success.html", extensions::kGaiaAuthExtensionOrigin); |
| 171 } | 171 } |
| 172 base::StringAppendF(&url, "?%s=%d", option, value); | 172 base::StringAppendF(&url, "?%s=%d", option, value); |
| 173 return GURL(url); | 173 return GURL(url); |
| 174 } | 174 } |
| 175 | 175 |
| 176 GURL GetPromoURL(Source source, bool auto_close) { | 176 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { |
| 177 return GetPromoURL(source, auto_close, false /* is_constrained */); | 177 return GetPromoURL(source, auto_close, false /* is_constrained */); |
| 178 } | 178 } |
| 179 | 179 |
| 180 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained) { | 180 GURL GetPromoURL(signin_metrics::Source source, |
| 181 DCHECK_NE(SOURCE_UNKNOWN, source); | 181 bool auto_close, |
| 182 bool is_constrained) { |
| 183 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); |
| 182 | 184 |
| 183 if (!switches::IsEnableWebBasedSignin()) { | 185 if (!switches::IsEnableWebBasedSignin()) { |
| 184 std::string url(chrome::kChromeUIChromeSigninURL); | 186 std::string url(chrome::kChromeUIChromeSigninURL); |
| 185 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); | 187 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); |
| 186 if (auto_close) | 188 if (auto_close) |
| 187 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); | 189 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); |
| 188 if (is_constrained) | 190 if (is_constrained) |
| 189 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); | 191 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); |
| 190 return GURL(url); | 192 return GURL(url); |
| 191 } | 193 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 220 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string); | 222 return GaiaUrls::GetInstance()->service_login_url().Resolve(query_string); |
| 221 } | 223 } |
| 222 | 224 |
| 223 GURL GetReauthURL(Profile* profile, const std::string& account_id) { | 225 GURL GetReauthURL(Profile* profile, const std::string& account_id) { |
| 224 AccountTrackerService::AccountInfo info = | 226 AccountTrackerService::AccountInfo info = |
| 225 AccountTrackerServiceFactory::GetForProfile(profile)-> | 227 AccountTrackerServiceFactory::GetForProfile(profile)-> |
| 226 GetAccountInfo(account_id); | 228 GetAccountInfo(account_id); |
| 227 | 229 |
| 228 if (switches::IsEnableWebBasedSignin()) { | 230 if (switches::IsEnableWebBasedSignin()) { |
| 229 return net::AppendQueryParameter( | 231 return net::AppendQueryParameter( |
| 230 signin::GetPromoURL(signin::SOURCE_SETTINGS, true), | 232 signin::GetPromoURL(signin_metrics::SOURCE_SETTINGS, true), |
| 231 "Email", | 233 "Email", |
| 232 account_id); | 234 account_id); |
| 233 } | 235 } |
| 234 | 236 |
| 235 signin::Source source = switches::IsNewAvatarMenu() ? | 237 signin_metrics::Source source = switches::IsNewAvatarMenu() ? |
| 236 signin::SOURCE_REAUTH : signin::SOURCE_SETTINGS; | 238 signin_metrics::SOURCE_REAUTH : signin_metrics::SOURCE_SETTINGS; |
| 237 | 239 |
| 238 GURL url = signin::GetPromoURL( | 240 GURL url = signin::GetPromoURL( |
| 239 source, true /* auto_close */, | 241 source, true /* auto_close */, |
| 240 switches::IsNewAvatarMenu() /* is_constrained */); | 242 switches::IsNewAvatarMenu() /* is_constrained */); |
| 241 url = net::AppendQueryParameter(url, "email", info.email); | 243 url = net::AppendQueryParameter(url, "email", info.email); |
| 242 url = net::AppendQueryParameter(url, "validateEmail", "1"); | 244 url = net::AppendQueryParameter(url, "validateEmail", "1"); |
| 243 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); | 245 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); |
| 244 } | 246 } |
| 245 | 247 |
| 246 GURL GetNextPageURLForPromoURL(const GURL& url) { | 248 GURL GetNextPageURLForPromoURL(const GURL& url) { |
| 247 std::string value; | 249 std::string value; |
| 248 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { | 250 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { |
| 249 GURL continue_url = GURL(value); | 251 GURL continue_url = GURL(value); |
| 250 if (continue_url.is_valid()) | 252 if (continue_url.is_valid()) |
| 251 return continue_url; | 253 return continue_url; |
| 252 } | 254 } |
| 253 | 255 |
| 254 return GURL(); | 256 return GURL(); |
| 255 } | 257 } |
| 256 | 258 |
| 257 GURL GetSigninPartitionURL() { | 259 GURL GetSigninPartitionURL() { |
| 258 return GURL(switches::IsEnableWebviewBasedSignin() ? | 260 return GURL(switches::IsEnableWebviewBasedSignin() ? |
| 259 "chrome-guest://chrome-signin/?" : | 261 "chrome-guest://chrome-signin/?" : |
| 260 chrome::kChromeUIChromeSigninURL); | 262 chrome::kChromeUIChromeSigninURL); |
| 261 } | 263 } |
| 262 | 264 |
| 263 Source GetSourceForPromoURL(const GURL& url) { | 265 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { |
| 264 std::string value; | 266 std::string value; |
| 265 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { | 267 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { |
| 266 int source = 0; | 268 int source = 0; |
| 267 if (base::StringToInt(value, &source) && source >= SOURCE_START_PAGE && | 269 if (base::StringToInt(value, &source) && |
| 268 source < SOURCE_UNKNOWN) { | 270 source >= signin_metrics::SOURCE_START_PAGE && |
| 269 return static_cast<Source>(source); | 271 source < signin_metrics::SOURCE_UNKNOWN) { |
| 272 return static_cast<signin_metrics::Source>(source); |
| 270 } | 273 } |
| 271 } | 274 } |
| 272 return SOURCE_UNKNOWN; | 275 return signin_metrics::SOURCE_UNKNOWN; |
| 273 } | 276 } |
| 274 | 277 |
| 275 bool IsAutoCloseEnabledInURL(const GURL& url) { | 278 bool IsAutoCloseEnabledInURL(const GURL& url) { |
| 276 std::string value; | 279 std::string value; |
| 277 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { | 280 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { |
| 278 int enabled = 0; | 281 int enabled = 0; |
| 279 if (base::StringToInt(value, &enabled) && enabled == 1) | 282 if (base::StringToInt(value, &enabled) && enabled == 1) |
| 280 return true; | 283 return true; |
| 281 } | 284 } |
| 282 return false; | 285 return false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 prefs::kSignInPromoShowOnFirstRunAllowed, | 329 prefs::kSignInPromoShowOnFirstRunAllowed, |
| 327 true, | 330 true, |
| 328 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 331 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 329 registry->RegisterBooleanPref( | 332 registry->RegisterBooleanPref( |
| 330 prefs::kSignInPromoShowNTPBubble, | 333 prefs::kSignInPromoShowNTPBubble, |
| 331 false, | 334 false, |
| 332 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 335 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 333 } | 336 } |
| 334 | 337 |
| 335 } // namespace signin | 338 } // namespace signin |
| OLD | NEW |