| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 default: | 101 default: |
| 102 NOTREACHED() << "Invalid auto_accept: " << auto_accept; | 102 NOTREACHED() << "Invalid auto_accept: " << auto_accept; |
| 103 break; | 103 break; |
| 104 } | 104 } |
| 105 | 105 |
| 106 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, | 106 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", action, |
| 107 one_click_signin::HISTOGRAM_MAX); | 107 one_click_signin::HISTOGRAM_MAX); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool UseWebBasedSigninFlow() { | 110 bool UseWebBasedSigninFlow() { |
| 111 static const bool use_web_based_singin_flow = | 111 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 CommandLine::ForCurrentProcess()->HasSwitch( | 112 switches::kUseWebBasedSigninFlow); |
| 113 switches::kUseWebBasedSigninFlow); | |
| 114 return use_web_based_singin_flow; | |
| 115 } | 113 } |
| 116 | 114 |
| 117 // Determines the source of the sign in. Its either one of the known sign in | 115 // 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 | 116 // 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 | 117 // via another Google property. In the former case, "service" is also |
| 120 // checked to make sure its "chromiumsync". | 118 // checked to make sure its "chromiumsync". |
| 121 SyncPromoUI::Source GetSigninSource(const GURL& url) { | 119 SyncPromoUI::Source GetSigninSource(const GURL& url) { |
| 122 std::string value; | 120 std::string value; |
| 123 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); | 121 chrome_common_net::GetValueForKeyInQuery(url, "service", &value); |
| 124 bool is_explicit_signin = value == "chromiumsync"; | 122 bool is_explicit_signin = value == "chromiumsync"; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 const ListValue* rejected_emails = profile->GetPrefs()->GetList( | 430 const ListValue* rejected_emails = profile->GetPrefs()->GetList( |
| 433 prefs::kReverseAutologinRejectedEmailList); | 431 prefs::kReverseAutologinRejectedEmailList); |
| 434 if (!rejected_emails->empty()) { | 432 if (!rejected_emails->empty()) { |
| 435 base::ListValue::const_iterator iter = rejected_emails->Find( | 433 base::ListValue::const_iterator iter = rejected_emails->Find( |
| 436 base::StringValue(email)); | 434 base::StringValue(email)); |
| 437 if (iter != rejected_emails->end()) | 435 if (iter != rejected_emails->end()) |
| 438 return false; | 436 return false; |
| 439 } | 437 } |
| 440 } | 438 } |
| 441 | 439 |
| 442 // If we're about to show a one-click infobar but the user has started | 440 if (!UseWebBasedSigninFlow()) { |
| 443 // a concurrent signin flow (perhaps via the promo), we may not have yet | 441 // If we're about to show a one-click infobar but the user has started |
| 444 // established an authenticated username but we still shouldn't move | 442 // a concurrent signin flow (perhaps via the promo), we may not have yet |
| 445 // forward with two simultaneous signin processes. This is a bit | 443 // established an authenticated username but we still shouldn't move |
| 446 // contentious as the one-click flow is a much smoother flow from the user | 444 // forward with two simultaneous signin processes. This is a bit |
| 447 // perspective, but it's much more difficult to hijack the other flow from | 445 // contentious as the one-click flow is a much smoother flow from the user |
| 448 // here as it is to bail. | 446 // perspective, but it's much more difficult to hijack the other flow from |
| 449 ProfileSyncService* service = | 447 // here as it is to bail. |
| 450 ProfileSyncServiceFactory::GetForProfile(profile); | 448 ProfileSyncService* service = |
| 451 if (!service) | 449 ProfileSyncServiceFactory::GetForProfile(profile); |
| 452 return false; | 450 if (!service) |
| 451 return false; |
| 453 | 452 |
| 454 if (service->FirstSetupInProgress()) | 453 if (service->FirstSetupInProgress()) |
| 455 return false; | 454 return false; |
| 455 } |
| 456 } | 456 } |
| 457 | 457 |
| 458 return true; | 458 return true; |
| 459 } | 459 } |
| 460 | 460 |
| 461 // static | 461 // static |
| 462 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThread( | 462 OneClickSigninHelper::Offer OneClickSigninHelper::CanOfferOnIOThread( |
| 463 net::URLRequest* request, | 463 net::URLRequest* request, |
| 464 ProfileIOData* io_data) { | 464 ProfileIOData* io_data) { |
| 465 return CanOfferOnIOThreadImpl(request->url(), request->referrer(), | 465 return CanOfferOnIOThreadImpl(request->url(), request->referrer(), |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 infobar_tab_helper->AddInfoBar( | 717 infobar_tab_helper->AddInfoBar( |
| 718 new OneClickInfoBarDelegateImpl(infobar_tab_helper, session_index_, | 718 new OneClickInfoBarDelegateImpl(infobar_tab_helper, session_index_, |
| 719 email_, password_)); | 719 email_, password_)); |
| 720 break; | 720 break; |
| 721 case AUTO_ACCEPT_CONFIGURE: | 721 case AUTO_ACCEPT_CONFIGURE: |
| 722 StartSync(browser, auto_accept_, session_index_, email_, password_, | 722 StartSync(browser, auto_accept_, session_index_, email_, password_, |
| 723 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 723 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 724 break; | 724 break; |
| 725 case AUTO_ACCEPT_EXPLICIT: | 725 case AUTO_ACCEPT_EXPLICIT: |
| 726 StartSync(browser, auto_accept_, session_index_, email_, password_, | 726 StartSync(browser, auto_accept_, session_index_, email_, password_, |
| 727 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 727 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
| 728 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
| 729 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 728 break; | 730 break; |
| 729 case REJECTED_FOR_PROFILE: | 731 case REJECTED_FOR_PROFILE: |
| 730 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 732 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", |
| 731 one_click_signin::HISTOGRAM_REJECTED, | 733 one_click_signin::HISTOGRAM_REJECTED, |
| 732 one_click_signin::HISTOGRAM_MAX); | 734 one_click_signin::HISTOGRAM_MAX); |
| 733 break; | 735 break; |
| 734 default: | 736 default: |
| 735 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; | 737 NOTREACHED() << "Invalid auto_accept=" << auto_accept_; |
| 736 break; | 738 break; |
| 737 } | 739 } |
| 738 | 740 |
| 739 AutoAccept local_auto_accept = auto_accept_; | 741 // If this explicit sign in is not from settings page, show the NTP after |
| 740 SyncPromoUI::Source local_source = source_; | 742 // sign in completes. In the case of the settings page, it will get closed |
| 743 // by SyncSetupHandler. |
| 744 if (auto_accept_ == AUTO_ACCEPT_EXPLICIT && |
| 745 source_ != SyncPromoUI::SOURCE_SETTINGS) { |
| 746 Profile* profile = |
| 747 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 748 signin_tracker_.reset(new SigninTracker(profile, this)); |
| 749 } |
| 741 | 750 |
| 742 email_.clear(); | 751 email_.clear(); |
| 743 password_.clear(); | 752 password_.clear(); |
| 744 auto_accept_ = NO_AUTO_ACCEPT; | 753 auto_accept_ = NO_AUTO_ACCEPT; |
| 745 source_ = SyncPromoUI::SOURCE_UNKNOWN; | 754 source_ = SyncPromoUI::SOURCE_UNKNOWN; |
| 746 | |
| 747 // If this is an explicit sign in by the user, then redirect them to the | |
| 748 // NTP. | |
| 749 if (local_auto_accept == AUTO_ACCEPT_EXPLICIT) { | |
| 750 // If this is an explicit sign in from settings page, then close the | |
| 751 // tab. Otherwise show the NTP after sign in completes. | |
| 752 if (local_source == SyncPromoUI::SOURCE_SETTINGS) { | |
| 753 contents->Close(); | |
| 754 } else { | |
| 755 Profile* profile = | |
| 756 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
| 757 signin_tracker_.reset(new SigninTracker(profile, this)); | |
| 758 } | |
| 759 } | |
| 760 | |
| 761 // |this| may have been deleted due to the contents->Close() call above. | |
| 762 // No members should be accessed at this point. | |
| 763 } | 755 } |
| 764 | 756 |
| 765 void OneClickSigninHelper::GaiaCredentialsValid() { | 757 void OneClickSigninHelper::GaiaCredentialsValid() { |
| 766 // Redirect to NTP with sign in bubble visible. | 758 // Redirect to NTP with sign in bubble visible. |
| 767 content::WebContents* contents = web_contents(); | 759 content::WebContents* contents = web_contents(); |
| 768 Profile* profile = | 760 Profile* profile = |
| 769 Profile::FromBrowserContext(contents->GetBrowserContext()); | 761 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 770 PrefService* pref_service = profile->GetPrefs(); | 762 PrefService* pref_service = profile->GetPrefs(); |
| 771 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); | 763 pref_service->SetBoolean(prefs::kSyncPromoShowNTPBubble, true); |
| 772 | 764 |
| 773 contents->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), | 765 contents->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), |
| 774 content::Referrer(), | 766 content::Referrer(), |
| 775 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 767 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 776 std::string()); | 768 std::string()); |
| 777 } | 769 } |
| 778 | 770 |
| 779 void OneClickSigninHelper::SigninFailed(const GoogleServiceAuthError& error) { | 771 void OneClickSigninHelper::SigninFailed(const GoogleServiceAuthError& error) { |
| 780 signin_tracker_.reset(); | 772 signin_tracker_.reset(); |
| 781 } | 773 } |
| 782 | 774 |
| 783 void OneClickSigninHelper::SigninSuccess() { | 775 void OneClickSigninHelper::SigninSuccess() { |
| 784 signin_tracker_.reset(); | 776 signin_tracker_.reset(); |
| 785 } | 777 } |
| OLD | NEW |