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