OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/sync/one_click_signin_helper.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 break; | 102 break; |
103 default: | 103 default: |
104 NOTREACHED() << "Invalid auto_accept: " << auto_accept; | 104 NOTREACHED() << "Invalid auto_accept: " << auto_accept; |
105 break; | 105 break; |
106 } | 106 } |
107 | 107 |
108 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 108 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
109 one_click_signin::HISTOGRAM_MAX); | 109 one_click_signin::HISTOGRAM_MAX); |
110 } | 110 } |
111 | 111 |
112 bool UseWebBasedSigninFlow() { | |
113 return CommandLine::ForCurrentProcess()->HasSwitch( | |
114 switches::kUseWebBasedSigninFlow); | |
115 } | |
116 | |
117 // Determines the source of the sign in. Its either one of the known sign in | 112 // Determines the source of the sign in. Its either one of the known sign in |
118 // access point (first run, NTP, menu, settings) or its an implicit sign in | 113 // access point (first run, NTP, menu, settings) or its an implicit sign in |
119 // via another Google property. In the former case, "service" is also | 114 // via another Google property. In the former case, "service" is also |
120 // checked to make sure its "chromiumsync". | 115 // checked to make sure its "chromiumsync". |
121 SyncPromoUI::Source GetSigninSource(const GURL& url) { | 116 SyncPromoUI::Source GetSigninSource(const GURL& url) { |
122 std::string value; | 117 std::string value; |
123 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); | 118 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); |
124 bool is_explicit_signin = value == "chromiumsync"; | 119 bool is_explicit_signin = value == "chromiumsync"; |
125 | 120 |
126 chrome_common_net::GetValueForKeyInQuery(url, "continue", &value); | 121 chrome_common_net::GetValueForKeyInQuery(url, "continue", &value); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 const ListValue* rejected_emails = profile->GetPrefs()->GetList( | 433 const ListValue* rejected_emails = profile->GetPrefs()->GetList( |
439 prefs::kReverseAutologinRejectedEmailList); | 434 prefs::kReverseAutologinRejectedEmailList); |
440 if (!rejected_emails->empty()) { | 435 if (!rejected_emails->empty()) { |
441 base::ListValue::const_iterator iter = rejected_emails->Find( | 436 base::ListValue::const_iterator iter = rejected_emails->Find( |
442 base::StringValue(email)); | 437 base::StringValue(email)); |
443 if (iter != rejected_emails->end()) | 438 if (iter != rejected_emails->end()) |
444 return false; | 439 return false; |
445 } | 440 } |
446 } | 441 } |
447 | 442 |
448 if (!UseWebBasedSigninFlow()) { | 443 if (!SyncPromoUI::UseWebBasedSigninFlow()) { |
449 // If we're about to show a one-click infobar but the user has started | 444 // If we're about to show a one-click infobar but the user has started |
450 // a concurrent signin flow (perhaps via the promo), we may not have yet | 445 // a concurrent signin flow (perhaps via the promo), we may not have yet |
451 // established an authenticated username but we still shouldn't move | 446 // established an authenticated username but we still shouldn't move |
452 // forward with two simultaneous signin processes. This is a bit | 447 // forward with two simultaneous signin processes. This is a bit |
453 // contentious as the one-click flow is a much smoother flow from the user | 448 // contentious as the one-click flow is a much smoother flow from the user |
454 // perspective, but it's much more difficult to hijack the other flow from | 449 // perspective, but it's much more difficult to hijack the other flow from |
455 // here as it is to bail. | 450 // here as it is to bail. |
456 ProfileSyncService* service = | 451 ProfileSyncService* service = |
457 ProfileSyncServiceFactory::GetForProfile(profile); | 452 ProfileSyncServiceFactory::GetForProfile(profile); |
458 if (!service) | 453 if (!service) |
(...skipping 20 matching lines...) Expand all Loading... |
479 const GURL& url, | 474 const GURL& url, |
480 const std::string& referrer, | 475 const std::string& referrer, |
481 base::SupportsUserData* request, | 476 base::SupportsUserData* request, |
482 ProfileIOData* io_data) { | 477 ProfileIOData* io_data) { |
483 if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) | 478 if (!gaia::IsGaiaSignonRealm(url.GetOrigin())) |
484 return IGNORE_REQUEST; | 479 return IGNORE_REQUEST; |
485 | 480 |
486 if (!io_data) | 481 if (!io_data) |
487 return DONT_OFFER; | 482 return DONT_OFFER; |
488 | 483 |
489 if (!UseWebBasedSigninFlow()) | 484 if (!SyncPromoUI::UseWebBasedSigninFlow()) |
490 return DONT_OFFER; | 485 return DONT_OFFER; |
491 | 486 |
492 // Don't offer if the source is known, as that means it's an explicit sign | 487 // Don't offer if the source is known, as that means it's an explicit sign |
493 // in request. | 488 // in request. |
494 if (GetSigninSource(url) != SyncPromoUI::SOURCE_UNKNOWN || | 489 if (GetSigninSource(url) != SyncPromoUI::SOURCE_UNKNOWN || |
495 GetSigninSource(GURL(referrer)) != SyncPromoUI::SOURCE_UNKNOWN) { | 490 GetSigninSource(GURL(referrer)) != SyncPromoUI::SOURCE_UNKNOWN) { |
496 return DONT_OFFER; | 491 return DONT_OFFER; |
497 } | 492 } |
498 | 493 |
499 if (!ProfileSyncService::IsSyncEnabled()) | 494 if (!ProfileSyncService::IsSyncEnabled()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 std::string google_accounts_signin_value; | 565 std::string google_accounts_signin_value; |
571 request->GetResponseHeaderByName("Google-Chrome-SignIn", | 566 request->GetResponseHeaderByName("Google-Chrome-SignIn", |
572 &google_chrome_signin_value); | 567 &google_chrome_signin_value); |
573 request->GetResponseHeaderByName("Google-Accounts-SignIn", | 568 request->GetResponseHeaderByName("Google-Accounts-SignIn", |
574 &google_accounts_signin_value); | 569 &google_accounts_signin_value); |
575 | 570 |
576 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 571 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
577 << " g-a-s='" << google_accounts_signin_value << "'" | 572 << " g-a-s='" << google_accounts_signin_value << "'" |
578 << " g-c-s='" << google_chrome_signin_value << "'"; | 573 << " g-c-s='" << google_chrome_signin_value << "'"; |
579 | 574 |
580 if (!UseWebBasedSigninFlow() && google_accounts_signin_value.empty()) | 575 if (!SyncPromoUI::UseWebBasedSigninFlow() && |
| 576 google_accounts_signin_value.empty()) { |
581 return; | 577 return; |
| 578 } |
582 | 579 |
583 if (!gaia::IsGaiaSignonRealm(request->original_url().GetOrigin())) | 580 if (!gaia::IsGaiaSignonRealm(request->original_url().GetOrigin())) |
584 return; | 581 return; |
585 | 582 |
586 // Parse Google-Accounts-SignIn. | 583 // Parse Google-Accounts-SignIn. |
587 std::vector<std::pair<std::string, std::string> > pairs; | 584 std::vector<std::pair<std::string, std::string> > pairs; |
588 base::SplitStringIntoKeyValuePairs(google_accounts_signin_value, '=', ',', | 585 base::SplitStringIntoKeyValuePairs(google_accounts_signin_value, '=', ',', |
589 &pairs); | 586 &pairs); |
590 std::string session_index; | 587 std::string session_index; |
591 std::string email; | 588 std::string email; |
592 for (size_t i = 0; i < pairs.size(); ++i) { | 589 for (size_t i = 0; i < pairs.size(); ++i) { |
593 const std::pair<std::string, std::string>& pair = pairs[i]; | 590 const std::pair<std::string, std::string>& pair = pairs[i]; |
594 const std::string& key = pair.first; | 591 const std::string& key = pair.first; |
595 const std::string& value = pair.second; | 592 const std::string& value = pair.second; |
596 if (key == "email") { | 593 if (key == "email") { |
597 TrimString(value, "\"", &email); | 594 TrimString(value, "\"", &email); |
598 } else if (key == "sessionindex") { | 595 } else if (key == "sessionindex") { |
599 session_index = value; | 596 session_index = value; |
600 } | 597 } |
601 } | 598 } |
602 | 599 |
603 // Later in the chain of this request, we'll need to check the email address | 600 // Later in the chain of this request, we'll need to check the email address |
604 // in the IO thread (see CanOfferOnIOThread). So save the email address as | 601 // in the IO thread (see CanOfferOnIOThread). So save the email address as |
605 // user data on the request (only for web-based flow). | 602 // user data on the request (only for web-based flow). |
606 if (UseWebBasedSigninFlow() && !email.empty()) | 603 if (SyncPromoUI::UseWebBasedSigninFlow() && !email.empty()) |
607 OneClickSigninRequestUserData::AssociateWithRequest(request, email); | 604 OneClickSigninRequestUserData::AssociateWithRequest(request, email); |
608 | 605 |
609 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" | 606 VLOG(1) << "OneClickSigninHelper::ShowInfoBarIfPossible:" |
610 << " email=" << email | 607 << " email=" << email |
611 << " sessionindex=" << session_index; | 608 << " sessionindex=" << session_index; |
612 | 609 |
613 // Parse Google-Chrome-SignIn. | 610 // Parse Google-Chrome-SignIn. |
614 AutoAccept auto_accept = NO_AUTO_ACCEPT; | 611 AutoAccept auto_accept = NO_AUTO_ACCEPT; |
615 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; | 612 SyncPromoUI::Source source = SyncPromoUI::SOURCE_UNKNOWN; |
616 if (UseWebBasedSigninFlow()) { | 613 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
617 std::vector<std::string> tokens; | 614 std::vector<std::string> tokens; |
618 base::SplitString(google_chrome_signin_value, ',', &tokens); | 615 base::SplitString(google_chrome_signin_value, ',', &tokens); |
619 for (size_t i = 0; i < tokens.size(); ++i) { | 616 for (size_t i = 0; i < tokens.size(); ++i) { |
620 const std::string& token = tokens[i]; | 617 const std::string& token = tokens[i]; |
621 if (token == "accepted") { | 618 if (token == "accepted") { |
622 auto_accept = AUTO_ACCEPT; | 619 auto_accept = AUTO_ACCEPT; |
623 } else if (token == "configure") { | 620 } else if (token == "configure") { |
624 auto_accept = AUTO_ACCEPT_CONFIGURE; | 621 auto_accept = AUTO_ACCEPT_CONFIGURE; |
625 } else if (token == "rejected-for-profile") { | 622 } else if (token == "rejected-for-profile") { |
626 auto_accept = REJECTED_FOR_PROFILE; | 623 auto_accept = REJECTED_FOR_PROFILE; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 break; | 827 break; |
831 } | 828 } |
832 } | 829 } |
833 | 830 |
834 RedirectToNTP(); | 831 RedirectToNTP(); |
835 } | 832 } |
836 | 833 |
837 void OneClickSigninHelper::SigninSuccess() { | 834 void OneClickSigninHelper::SigninSuccess() { |
838 RedirectToNTP(); | 835 RedirectToNTP(); |
839 } | 836 } |
OLD | NEW |