| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); | 188 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); |
| 189 if (is_constrained) | 189 if (is_constrained) |
| 190 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); | 190 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); |
| 191 return GURL(url); | 191 return GURL(url); |
| 192 } | 192 } |
| 193 | 193 |
| 194 GURL GetReauthURL(Profile* profile, const std::string& account_id) { | 194 GURL GetReauthURL(Profile* profile, const std::string& account_id) { |
| 195 AccountTrackerService::AccountInfo info = | 195 AccountTrackerService::AccountInfo info = |
| 196 AccountTrackerServiceFactory::GetForProfile(profile)-> | 196 AccountTrackerServiceFactory::GetForProfile(profile)-> |
| 197 GetAccountInfo(account_id); | 197 GetAccountInfo(account_id); |
| 198 return GetReauthURL(std::string::npos, info.email); |
| 199 } |
| 198 | 200 |
| 201 GURL GetReauthURL(size_t profile_index, const std::string& email) { |
| 199 signin_metrics::Source source = switches::IsNewAvatarMenu() ? | 202 signin_metrics::Source source = switches::IsNewAvatarMenu() ? |
| 200 signin_metrics::SOURCE_REAUTH : signin_metrics::SOURCE_SETTINGS; | 203 signin_metrics::SOURCE_REAUTH : signin_metrics::SOURCE_SETTINGS; |
| 201 | 204 |
| 202 GURL url = signin::GetPromoURL( | 205 GURL url = signin::GetPromoURL( |
| 203 source, true /* auto_close */, | 206 source, true /* auto_close */, |
| 204 switches::IsNewAvatarMenu() /* is_constrained */); | 207 switches::IsNewAvatarMenu() /* is_constrained */); |
| 205 url = net::AppendQueryParameter(url, "email", info.email); | 208 |
| 209 if (profile_index != std::string::npos) |
| 210 url = net::AppendQueryParameter(url, kSignInPromoQueryKeyProfileIndex, |
| 211 base::SizeTToString(profile_index)); |
| 212 |
| 213 url = net::AppendQueryParameter(url, "email", email); |
| 206 url = net::AppendQueryParameter(url, "validateEmail", "1"); | 214 url = net::AppendQueryParameter(url, "validateEmail", "1"); |
| 207 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); | 215 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); |
| 208 } | 216 } |
| 209 | 217 |
| 210 GURL GetNextPageURLForPromoURL(const GURL& url) { | 218 GURL GetNextPageURLForPromoURL(const GURL& url) { |
| 211 std::string value; | 219 std::string value; |
| 212 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { | 220 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { |
| 213 GURL continue_url = GURL(value); | 221 GURL continue_url = GURL(value); |
| 214 if (continue_url.is_valid()) | 222 if (continue_url.is_valid()) |
| 215 return continue_url; | 223 return continue_url; |
| 216 } | 224 } |
| 217 | 225 |
| 218 return GURL(); | 226 return GURL(); |
| 219 } | 227 } |
| 220 | 228 |
| 229 size_t GetProfileIndexForPromoURL(const GURL& url) { |
| 230 size_t index = std::string::npos; |
| 231 std::string value; |
| 232 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyProfileIndex, |
| 233 &value) && |
| 234 base::StringToSizeT(value, &index)) { |
| 235 return index; |
| 236 } |
| 237 |
| 238 return std::string::npos; |
| 239 } |
| 240 |
| 221 GURL GetSigninPartitionURL() { | 241 GURL GetSigninPartitionURL() { |
| 222 return GURL("chrome-guest://chrome-signin/?"); | 242 return GURL("chrome-guest://chrome-signin/?"); |
| 223 } | 243 } |
| 224 | 244 |
| 225 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { | 245 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { |
| 226 std::string value; | 246 std::string value; |
| 227 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { | 247 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { |
| 228 int source = 0; | 248 int source = 0; |
| 229 if (base::StringToInt(value, &source) && | 249 if (base::StringToInt(value, &source) && |
| 230 source >= signin_metrics::SOURCE_START_PAGE && | 250 source >= signin_metrics::SOURCE_START_PAGE && |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 282 |
| 263 void RegisterProfilePrefs( | 283 void RegisterProfilePrefs( |
| 264 user_prefs::PrefRegistrySyncable* registry) { | 284 user_prefs::PrefRegistrySyncable* registry) { |
| 265 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); | 285 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); |
| 266 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); | 286 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); |
| 267 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); | 287 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); |
| 268 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); | 288 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); |
| 269 } | 289 } |
| 270 | 290 |
| 271 } // namespace signin | 291 } // namespace signin |
| OLD | NEW |