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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 int show_count = profile->GetPrefs()->GetInteger( | 157 int show_count = profile->GetPrefs()->GetInteger( |
158 prefs::kSignInPromoStartupCount); | 158 prefs::kSignInPromoStartupCount); |
159 show_count++; | 159 show_count++; |
160 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count); | 160 profile->GetPrefs()->SetInteger(prefs::kSignInPromoStartupCount, show_count); |
161 } | 161 } |
162 | 162 |
163 void SetUserSkippedPromo(Profile* profile) { | 163 void SetUserSkippedPromo(Profile* profile) { |
164 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true); | 164 profile->GetPrefs()->SetBoolean(prefs::kSignInPromoUserSkipped, true); |
165 } | 165 } |
166 | 166 |
167 GURL GetLandingURL(const char* option, int value) { | 167 GURL GetLandingURL(signin_metrics::AccessPoint access_point) { |
168 std::string url = base::StringPrintf("%s/success.html?%s=%d", | 168 std::string url = base::StringPrintf( |
169 extensions::kGaiaAuthExtensionOrigin, | 169 "%s/success.html?%s=%d", extensions::kGaiaAuthExtensionOrigin, |
170 option, | 170 kSignInPromoQueryKeyAccessPoint, access_point); |
171 value); | 171 |
| 172 // TODO(gogerald): right now, gaia server needs to distinguish the source from |
| 173 // signin_metrics::SOURCE_START_PAGE, signin_metrics::SOURCE_SETTINGS and |
| 174 // the others to show advanced sync settings, remove them after |
| 175 // switching to Minute Maid sign in flow. |
| 176 if (access_point == signin_metrics::ACCESS_POINT_START_PAGE) { |
| 177 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 178 signin_metrics::SOURCE_START_PAGE); |
| 179 } else if (access_point == signin_metrics::ACCESS_POINT_SETTINGS) { |
| 180 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 181 signin_metrics::SOURCE_SETTINGS); |
| 182 } else { |
| 183 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeySource, |
| 184 signin_metrics::SOURCE_OTHERS); |
| 185 } |
| 186 |
172 return GURL(url); | 187 return GURL(url); |
173 } | 188 } |
174 | 189 |
175 GURL GetPromoURL(signin_metrics::Source source, bool auto_close) { | 190 GURL GetPromoURL(signin_metrics::AccessPoint access_point, |
176 return GetPromoURL(source, auto_close, false /* is_constrained */); | 191 signin_metrics::Reason reason, |
| 192 bool auto_close) { |
| 193 return GetPromoURL(access_point, reason, auto_close, |
| 194 false /* is_constrained */); |
177 } | 195 } |
178 | 196 |
179 GURL GetPromoURL(signin_metrics::Source source, | 197 GURL GetPromoURL(signin_metrics::AccessPoint access_point, |
| 198 signin_metrics::Reason reason, |
180 bool auto_close, | 199 bool auto_close, |
181 bool is_constrained) { | 200 bool is_constrained) { |
182 DCHECK_NE(signin_metrics::SOURCE_UNKNOWN, source); | 201 CHECK(access_point < signin_metrics::ACCESS_POINT_MAX); |
| 202 CHECK(reason < signin_metrics::REASON_MAX); |
183 | 203 |
184 std::string url(chrome::kChromeUIChromeSigninURL); | 204 std::string url(chrome::kChromeUIChromeSigninURL); |
185 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeySource, source); | 205 base::StringAppendF(&url, "?%s=%d", kSignInPromoQueryKeyAccessPoint, |
| 206 access_point); |
| 207 base::StringAppendF(&url, "&%s=%d", kSignInPromoQueryKeyReason, reason); |
186 if (auto_close) | 208 if (auto_close) |
187 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); | 209 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyAutoClose); |
188 if (is_constrained) | 210 if (is_constrained) |
189 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); | 211 base::StringAppendF(&url, "&%s=1", kSignInPromoQueryKeyConstrained); |
190 return GURL(url); | 212 return GURL(url); |
191 } | 213 } |
192 | 214 |
193 GURL GetReauthURL(Profile* profile, const std::string& account_id) { | 215 GURL GetReauthURL(signin_metrics::AccessPoint access_point, |
| 216 signin_metrics::Reason reason, |
| 217 Profile* profile, |
| 218 const std::string& account_id) { |
194 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile) | 219 AccountInfo info = AccountTrackerServiceFactory::GetForProfile(profile) |
195 ->GetAccountInfo(account_id); | 220 ->GetAccountInfo(account_id); |
196 return GetReauthURLWithEmail(info.email); | 221 return GetReauthURLWithEmail(access_point, reason, info.email); |
197 } | 222 } |
198 | 223 |
199 GURL GetReauthURLWithEmail(const std::string& email) { | 224 GURL GetReauthURLWithEmail(signin_metrics::AccessPoint access_point, |
200 GURL url = signin::GetPromoURL( | 225 signin_metrics::Reason reason, |
201 signin_metrics::SOURCE_REAUTH, true /* auto_close */, | 226 const std::string& email) { |
202 true /* is_constrained */); | 227 GURL url = signin::GetPromoURL(access_point, reason, true /* auto_close */, |
| 228 true /* is_constrained */); |
203 | 229 |
204 url = net::AppendQueryParameter(url, "email", email); | 230 url = net::AppendQueryParameter(url, "email", email); |
205 url = net::AppendQueryParameter(url, "validateEmail", "1"); | 231 url = net::AppendQueryParameter(url, "validateEmail", "1"); |
206 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); | 232 return net::AppendQueryParameter(url, "readOnlyEmail", "1"); |
207 } | 233 } |
208 | 234 |
209 GURL GetNextPageURLForPromoURL(const GURL& url) { | 235 GURL GetNextPageURLForPromoURL(const GURL& url) { |
210 std::string value; | 236 std::string value; |
211 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { | 237 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyContinue, &value)) { |
212 GURL continue_url = GURL(value); | 238 GURL continue_url = GURL(value); |
213 if (continue_url.is_valid()) | 239 if (continue_url.is_valid()) |
214 return continue_url; | 240 return continue_url; |
215 } | 241 } |
216 | 242 |
217 return GURL(); | 243 return GURL(); |
218 } | 244 } |
219 | 245 |
220 GURL GetSigninPartitionURL() { | 246 GURL GetSigninPartitionURL() { |
221 return GURL("chrome-guest://chrome-signin/?"); | 247 return GURL("chrome-guest://chrome-signin/?"); |
222 } | 248 } |
223 | 249 |
224 signin_metrics::Source GetSourceForPromoURL(const GURL& url) { | 250 signin_metrics::AccessPoint GetAccessPointForPromoURL(const GURL& url) { |
225 std::string value; | 251 std::string value; |
226 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { | 252 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAccessPoint, |
227 int source = 0; | 253 &value)) { |
228 if (base::StringToInt(value, &source) && | 254 int access_point = 0; |
229 source >= signin_metrics::SOURCE_START_PAGE && | 255 if (base::StringToInt(value, &access_point) && |
230 source < signin_metrics::SOURCE_UNKNOWN) { | 256 access_point >= signin_metrics::ACCESS_POINT_START_PAGE && |
231 return static_cast<signin_metrics::Source>(source); | 257 access_point < signin_metrics::ACCESS_POINT_MAX) { |
| 258 return static_cast<signin_metrics::AccessPoint>(access_point); |
232 } | 259 } |
| 260 CHECK(false); |
233 } | 261 } |
234 return signin_metrics::SOURCE_UNKNOWN; | 262 return signin_metrics::ACCESS_POINT_MAX; |
| 263 } |
| 264 |
| 265 signin_metrics::Reason GetSigninReasonForPromoURL(const GURL& url) { |
| 266 std::string value; |
| 267 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyReason, &value)) { |
| 268 int reason = 0; |
| 269 if (base::StringToInt(value, &reason) && |
| 270 reason >= signin_metrics::REASON_SIGNIN_PRIMARY_ACCOUNT && |
| 271 reason < signin_metrics::REASON_MAX) { |
| 272 return static_cast<signin_metrics::Reason>(reason); |
| 273 } |
| 274 CHECK(false); |
| 275 } |
| 276 return signin_metrics::REASON_MAX; |
235 } | 277 } |
236 | 278 |
237 bool IsAutoCloseEnabledInURL(const GURL& url) { | 279 bool IsAutoCloseEnabledInURL(const GURL& url) { |
238 std::string value; | 280 std::string value; |
239 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { | 281 if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeyAutoClose, &value)) { |
240 int enabled = 0; | 282 int enabled = 0; |
241 if (base::StringToInt(value, &enabled) && enabled == 1) | 283 if (base::StringToInt(value, &enabled) && enabled == 1) |
242 return true; | 284 return true; |
243 } | 285 } |
244 return false; | 286 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
261 | 303 |
262 void RegisterProfilePrefs( | 304 void RegisterProfilePrefs( |
263 user_prefs::PrefRegistrySyncable* registry) { | 305 user_prefs::PrefRegistrySyncable* registry) { |
264 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); | 306 registry->RegisterIntegerPref(prefs::kSignInPromoStartupCount, 0); |
265 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); | 307 registry->RegisterBooleanPref(prefs::kSignInPromoUserSkipped, false); |
266 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); | 308 registry->RegisterBooleanPref(prefs::kSignInPromoShowOnFirstRunAllowed, true); |
267 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); | 309 registry->RegisterBooleanPref(prefs::kSignInPromoShowNTPBubble, false); |
268 } | 310 } |
269 | 311 |
270 } // namespace signin | 312 } // namespace signin |
OLD | NEW |