| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 // Arguments used with StartSync function. base::Bind() cannot support too | 93 // Arguments used with StartSync function. base::Bind() cannot support too |
| 94 // many args for performance reasons, so they are packaged up into a struct. | 94 // many args for performance reasons, so they are packaged up into a struct. |
| 95 struct StartSyncArgs { | 95 struct StartSyncArgs { |
| 96 StartSyncArgs(Profile* profile, | 96 StartSyncArgs(Profile* profile, |
| 97 Browser* browser, | 97 Browser* browser, |
| 98 OneClickSigninHelper::AutoAccept auto_accept, | 98 OneClickSigninHelper::AutoAccept auto_accept, |
| 99 const std::string& session_index, | 99 const std::string& session_index, |
| 100 const std::string& email, | 100 const std::string& email, |
| 101 const std::string& password, | 101 const std::string& password, |
| 102 bool last_minute_source_change) | 102 bool force_same_tab_navigation) |
| 103 : profile(profile), | 103 : profile(profile), |
| 104 browser(browser), | 104 browser(browser), |
| 105 auto_accept(auto_accept), | 105 auto_accept(auto_accept), |
| 106 session_index(session_index), | 106 session_index(session_index), |
| 107 email(email), | 107 email(email), |
| 108 password(password), | 108 password(password), |
| 109 last_minute_source_change(last_minute_source_change) { | 109 force_same_tab_navigation(force_same_tab_navigation) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 Profile* profile; | 112 Profile* profile; |
| 113 Browser* browser; | 113 Browser* browser; |
| 114 OneClickSigninHelper::AutoAccept auto_accept; | 114 OneClickSigninHelper::AutoAccept auto_accept; |
| 115 std::string session_index; | 115 std::string session_index; |
| 116 std::string email; | 116 std::string email; |
| 117 std::string password; | 117 std::string password; |
| 118 bool last_minute_source_change; | 118 bool force_same_tab_navigation; |
| 119 }; | 119 }; |
| 120 | 120 |
| 121 // Start syncing with the given user information. | 121 // Start syncing with the given user information. |
| 122 void StartSync(const StartSyncArgs& args, | 122 void StartSync(const StartSyncArgs& args, |
| 123 OneClickSigninSyncStarter::StartSyncMode start_mode) { | 123 OneClickSigninSyncStarter::StartSyncMode start_mode) { |
| 124 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { | 124 if (start_mode == OneClickSigninSyncStarter::UNDO_SYNC) { |
| 125 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", | 125 UMA_HISTOGRAM_ENUMERATION("AutoLogin.Reverse", |
| 126 one_click_signin::HISTOGRAM_UNDO, | 126 one_click_signin::HISTOGRAM_UNDO, |
| 127 one_click_signin::HISTOGRAM_MAX); | 127 one_click_signin::HISTOGRAM_MAX); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 // The starter deletes itself once its done. | 130 // The starter deletes itself once its done. |
| 131 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, | 131 new OneClickSigninSyncStarter(args.profile, args.browser, args.session_index, |
| 132 args.email, args.password, start_mode, | 132 args.email, args.password, start_mode, |
| 133 /* force_same_tab_navigation */ | 133 args.force_same_tab_navigation); |
| 134 args.last_minute_source_change); | |
| 135 | 134 |
| 136 int action = one_click_signin::HISTOGRAM_MAX; | 135 int action = one_click_signin::HISTOGRAM_MAX; |
| 137 switch (args.auto_accept) { | 136 switch (args.auto_accept) { |
| 138 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: | 137 case OneClickSigninHelper::AUTO_ACCEPT_EXPLICIT: |
| 139 action = one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS; | |
| 140 break; | |
| 141 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: | |
| 142 action = | 138 action = |
| 143 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? | 139 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? |
| 144 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : | 140 one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS : |
| 145 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 141 one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
| 146 break; | 142 break; |
| 143 case OneClickSigninHelper::AUTO_ACCEPT_ACCEPTED: |
| 144 action = one_click_signin::HISTOGRAM_AUTO_WITH_DEFAULTS; |
| 145 break; |
| 147 case OneClickSigninHelper::AUTO_ACCEPT_NONE: | 146 case OneClickSigninHelper::AUTO_ACCEPT_NONE: |
| 148 action = | 147 action = |
| 149 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? | 148 start_mode == OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS ? |
| 150 one_click_signin::HISTOGRAM_WITH_DEFAULTS : | 149 one_click_signin::HISTOGRAM_WITH_DEFAULTS : |
| 151 one_click_signin::HISTOGRAM_WITH_ADVANCED; | 150 one_click_signin::HISTOGRAM_WITH_ADVANCED; |
| 152 break; | 151 break; |
| 153 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: | 152 case OneClickSigninHelper::AUTO_ACCEPT_CONFIGURE: |
| 154 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 153 DCHECK(start_mode == OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 155 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; | 154 action = one_click_signin::HISTOGRAM_AUTO_WITH_ADVANCED; |
| 156 break; | 155 break; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // this profile. | 445 // this profile. |
| 447 SigninManager::DisableOneClickSignIn(profile); | 446 SigninManager::DisableOneClickSignIn(profile); |
| 448 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 447 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
| 449 chrome::FindBrowserWithWebContents(web_contents)->window()-> | 448 chrome::FindBrowserWithWebContents(web_contents)->window()-> |
| 450 ShowOneClickSigninBubble( | 449 ShowOneClickSigninBubble( |
| 451 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 450 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 452 base::Bind(&StartSync, | 451 base::Bind(&StartSync, |
| 453 StartSyncArgs(profile, browser, | 452 StartSyncArgs(profile, browser, |
| 454 OneClickSigninHelper::AUTO_ACCEPT_NONE, | 453 OneClickSigninHelper::AUTO_ACCEPT_NONE, |
| 455 session_index_, email_, password_, | 454 session_index_, email_, password_, |
| 456 false /* last_minute_source_change */))); | 455 false /* force_same_tab_navigation */))); |
| 457 button_pressed_ = true; | 456 button_pressed_ = true; |
| 458 return true; | 457 return true; |
| 459 } | 458 } |
| 460 | 459 |
| 461 bool OneClickInfoBarDelegateImpl::Cancel() { | 460 bool OneClickInfoBarDelegateImpl::Cancel() { |
| 462 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( | 461 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( |
| 463 owner()->GetWebContents()->GetBrowserContext()), email_); | 462 owner()->GetWebContents()->GetBrowserContext()), email_); |
| 464 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 463 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
| 465 button_pressed_ = true; | 464 button_pressed_ = true; |
| 466 return true; | 465 return true; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 945 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
| 947 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 946 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
| 948 RedirectToNTP(); | 947 RedirectToNTP(); |
| 949 return; | 948 return; |
| 950 } | 949 } |
| 951 | 950 |
| 952 // If there is no valid email or password yet, there is nothing to do. | 951 // If there is no valid email or password yet, there is nothing to do. |
| 953 if (email_.empty() || password_.empty()) | 952 if (email_.empty() || password_.empty()) |
| 954 return; | 953 return; |
| 955 | 954 |
| 956 // When the user use the firt-run, ntp, or hotdog menu to sign in, then have | 955 // When the user uses the first-run, ntp, or hotdog menu to sign in, then have |
| 957 // the option of checking the the box "Let me choose what to sync". When the | 956 // the option of checking the the box "Let me choose what to sync". When the |
| 958 // sign in process started, the source parameter in the continue URL may have | 957 // sign in process started, the source parameter in the continue URL may have |
| 959 // indicated one of the three options above. However, once this box is | 958 // indicated one of the three options above. However, once this box is |
| 960 // checked, the source parameter will indicate settings. This will only be | 959 // checked, the source parameter will indicate settings. This will only be |
| 961 // comminucated back to chrome when Gaia redirects to the continue URL, and | 960 // communicated back to chrome when Gaia redirects to the continue URL, and |
| 962 // this is considered here a last minute change to the source. See a little | 961 // this is considered here a last minute change to the source. See a little |
| 963 // further below for when this variable is set to true. | 962 // further below for when this variable is set to true. |
| 964 bool last_minute_source_change = false; | 963 bool force_same_tab_navigation = false; |
| 965 | 964 |
| 966 if (SyncPromoUI::UseWebBasedSigninFlow()) { | 965 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
| 967 if (IsValidGaiaSigninRedirectOrResponseURL(url)) | 966 if (IsValidGaiaSigninRedirectOrResponseURL(url)) |
| 968 return; | 967 return; |
| 969 | 968 |
| 970 // During an explicit sign in, if the user has not yet reached the final | 969 // During an explicit sign in, if the user has not yet reached the final |
| 971 // continue URL, wait for it to arrive. Note that Gaia will add some extra | 970 // continue URL, wait for it to arrive. Note that Gaia will add some extra |
| 972 // query parameters to the continue URL. Ignore them when checking to | 971 // query parameters to the continue URL. Ignore them when checking to |
| 973 // see if the user has continued. | 972 // see if the user has continued. |
| 974 // | 973 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 987 const bool continue_url_match = (url.ReplaceComponents(replacements) == | 986 const bool continue_url_match = (url.ReplaceComponents(replacements) == |
| 988 continue_url_.ReplaceComponents(replacements)); | 987 continue_url_.ReplaceComponents(replacements)); |
| 989 if (!continue_url_match) { | 988 if (!continue_url_match) { |
| 990 VLOG(1) << "OneClickSigninHelper::DidStopLoading: invalid url='" | 989 VLOG(1) << "OneClickSigninHelper::DidStopLoading: invalid url='" |
| 991 << url.spec() | 990 << url.spec() |
| 992 << "' expected continue url=" << continue_url_; | 991 << "' expected continue url=" << continue_url_; |
| 993 CleanTransientState(); | 992 CleanTransientState(); |
| 994 return; | 993 return; |
| 995 } | 994 } |
| 996 | 995 |
| 997 // In explicit sign ins, the user may have checked the box | 996 // In explicit sign ins, the user may have changed the box |
| 998 // "Let me choose what to sync". This is reflected as a change in the | 997 // "Let me choose what to sync". This is reflected as a change in the |
| 999 // source of the continue URL. Make one last check of the current URL | 998 // source of the continue URL. Make one last check of the current URL |
| 1000 // to see if there is a valid source and its set to settings. If so, | 999 // to see if there is a valid source. If so, it overrides the |
| 1001 // it overrides the current source. | 1000 // current source. |
| 1001 // |
| 1002 // If the source was changed to SOURCE_SETTINGS, we want |
| 1003 // OneClickSigninSyncStarter to reuse the current tab to display the |
| 1004 // advanced configuration. |
| 1002 SyncPromoUI::Source source = | 1005 SyncPromoUI::Source source = |
| 1003 SyncPromoUI::GetSourceForSyncPromoURL(url); | 1006 SyncPromoUI::GetSourceForSyncPromoURL(url); |
| 1004 if (source == SyncPromoUI::SOURCE_SETTINGS && | 1007 if (source != source_) { |
| 1005 source_ != SyncPromoUI::SOURCE_SETTINGS) { | 1008 source_ = source; |
| 1006 source_ = SyncPromoUI::SOURCE_SETTINGS; | 1009 force_same_tab_navigation = source_ == SyncPromoUI::SOURCE_SETTINGS; |
| 1007 last_minute_source_change = true; | |
| 1008 } | 1010 } |
| 1009 } | 1011 } |
| 1010 } | 1012 } |
| 1011 | 1013 |
| 1012 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1014 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 1013 Profile* profile = | 1015 Profile* profile = |
| 1014 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1016 Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 1015 | 1017 |
| 1016 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." | 1018 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
| 1017 << " auto_accept=" << auto_accept_ | 1019 << " auto_accept=" << auto_accept_ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1036 password_); | 1038 password_); |
| 1037 } | 1039 } |
| 1038 break; | 1040 break; |
| 1039 case AUTO_ACCEPT_ACCEPTED: | 1041 case AUTO_ACCEPT_ACCEPTED: |
| 1040 SigninManager::DisableOneClickSignIn(profile); | 1042 SigninManager::DisableOneClickSignIn(profile); |
| 1041 browser->window()->ShowOneClickSigninBubble( | 1043 browser->window()->ShowOneClickSigninBubble( |
| 1042 bubble_type, | 1044 bubble_type, |
| 1043 base::Bind(&StartSync, | 1045 base::Bind(&StartSync, |
| 1044 StartSyncArgs(profile, browser, auto_accept_, | 1046 StartSyncArgs(profile, browser, auto_accept_, |
| 1045 session_index_, email_, password_, | 1047 session_index_, email_, password_, |
| 1046 false /* last_minute_source_change */))); | 1048 false /* force_same_tab_navigation */))); |
| 1047 break; | 1049 break; |
| 1048 case AUTO_ACCEPT_CONFIGURE: | 1050 case AUTO_ACCEPT_CONFIGURE: |
| 1049 SigninManager::DisableOneClickSignIn(profile); | 1051 SigninManager::DisableOneClickSignIn(profile); |
| 1050 StartSync( | 1052 StartSync( |
| 1051 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1053 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, |
| 1052 password_, false /* last_minute_source_change */), | 1054 password_, false /* force_same_tab_navigation */), |
| 1053 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1055 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 1054 break; | 1056 break; |
| 1055 case AUTO_ACCEPT_EXPLICIT: { | 1057 case AUTO_ACCEPT_EXPLICIT: { |
| 1056 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1058 OneClickSigninSyncStarter::StartSyncMode start_mode = |
| 1057 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 1059 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
| 1058 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1060 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
| 1059 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1061 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
| 1060 | 1062 |
| 1061 // If the new email address is different from the email address that | 1063 // If the new email address is different from the email address that |
| 1062 // just signed in, show a confirmation dialog. | 1064 // just signed in, show a confirmation dialog. |
| 1063 std::string last_email = | 1065 std::string last_email = |
| 1064 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1066 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 1065 if (!last_email.empty() && last_email != email_) { | 1067 if (!last_email.empty() && last_email != email_) { |
| 1066 ConfirmEmailDialogDelegate::AskForConfirmation( | 1068 ConfirmEmailDialogDelegate::AskForConfirmation( |
| 1067 contents, | 1069 contents, |
| 1068 last_email, | 1070 last_email, |
| 1069 email_, | 1071 email_, |
| 1070 base::Bind( | 1072 base::Bind( |
| 1071 &StartExplicitSync, | 1073 &StartExplicitSync, |
| 1072 StartSyncArgs(profile, browser, auto_accept_, | 1074 StartSyncArgs(profile, browser, auto_accept_, |
| 1073 session_index_, email_, password_, | 1075 session_index_, email_, password_, |
| 1074 last_minute_source_change), | 1076 force_same_tab_navigation), |
| 1075 contents, | 1077 contents, |
| 1076 start_mode)); | 1078 start_mode)); |
| 1077 } else { | 1079 } else { |
| 1078 StartExplicitSync( | 1080 StartExplicitSync( |
| 1079 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1081 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
| 1080 email_, password_, last_minute_source_change), | 1082 email_, password_, force_same_tab_navigation), |
| 1081 contents, | 1083 contents, |
| 1082 start_mode, | 1084 start_mode, |
| 1083 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | 1085 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); |
| 1084 } | 1086 } |
| 1085 | 1087 |
| 1086 if (last_minute_source_change && | 1088 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
| 1087 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1089 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
| 1088 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1090 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
| 1089 redirect_url_ = continue_url_; | 1091 redirect_url_ = continue_url_; |
| 1090 ProfileSyncService* sync_service = | 1092 ProfileSyncService* sync_service = |
| 1091 ProfileSyncServiceFactory::GetForProfile(profile); | 1093 ProfileSyncServiceFactory::GetForProfile(profile); |
| 1092 if (sync_service) | 1094 if (sync_service) |
| 1093 sync_service->AddObserver(this); | 1095 sync_service->AddObserver(this); |
| 1094 } | 1096 } |
| 1095 | 1097 |
| 1096 // If this explicit sign in is not from settings page/webstore, show the | 1098 // If this explicit sign in is not from settings page/webstore, show the |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 break; | 1167 break; |
| 1166 } | 1168 } |
| 1167 } | 1169 } |
| 1168 | 1170 |
| 1169 RedirectToNTP(); | 1171 RedirectToNTP(); |
| 1170 } | 1172 } |
| 1171 | 1173 |
| 1172 void OneClickSigninHelper::SigninSuccess() { | 1174 void OneClickSigninHelper::SigninSuccess() { |
| 1173 RedirectToNTP(); | 1175 RedirectToNTP(); |
| 1174 } | 1176 } |
| OLD | NEW |