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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 // this profile. | 444 // this profile. |
446 SigninManager::DisableOneClickSignIn(profile); | 445 SigninManager::DisableOneClickSignIn(profile); |
447 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); | 446 RecordHistogramAction(one_click_signin::HISTOGRAM_ACCEPTED); |
448 chrome::FindBrowserWithWebContents(web_contents)->window()-> | 447 chrome::FindBrowserWithWebContents(web_contents)->window()-> |
449 ShowOneClickSigninBubble( | 448 ShowOneClickSigninBubble( |
450 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 449 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
451 base::Bind(&StartSync, | 450 base::Bind(&StartSync, |
452 StartSyncArgs(profile, browser, | 451 StartSyncArgs(profile, browser, |
453 OneClickSigninHelper::AUTO_ACCEPT_NONE, | 452 OneClickSigninHelper::AUTO_ACCEPT_NONE, |
454 session_index_, email_, password_, | 453 session_index_, email_, password_, |
455 false /* last_minute_source_change */))); | 454 false /* force_same_tab_navigation */))); |
456 button_pressed_ = true; | 455 button_pressed_ = true; |
457 return true; | 456 return true; |
458 } | 457 } |
459 | 458 |
460 bool OneClickInfoBarDelegateImpl::Cancel() { | 459 bool OneClickInfoBarDelegateImpl::Cancel() { |
461 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( | 460 AddEmailToOneClickRejectedList(Profile::FromBrowserContext( |
462 owner()->GetWebContents()->GetBrowserContext()), email_); | 461 owner()->GetWebContents()->GetBrowserContext()), email_); |
463 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); | 462 RecordHistogramAction(one_click_signin::HISTOGRAM_REJECTED); |
464 button_pressed_ = true; | 463 button_pressed_ = true; |
465 return true; | 464 return true; |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
945 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { | 944 if (!error_message_.empty() && auto_accept_ == AUTO_ACCEPT_EXPLICIT) { |
946 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; | 945 VLOG(1) << "OneClickSigninHelper::DidStopLoading: error=" << error_message_; |
947 RedirectToNTP(); | 946 RedirectToNTP(); |
948 return; | 947 return; |
949 } | 948 } |
950 | 949 |
951 // If there is no valid email or password yet, there is nothing to do. | 950 // If there is no valid email or password yet, there is nothing to do. |
952 if (email_.empty() || password_.empty()) | 951 if (email_.empty() || password_.empty()) |
953 return; | 952 return; |
954 | 953 |
955 // When the user use the firt-run, ntp, or hotdog menu to sign in, then have | 954 // When the user use the firt-run, ntp, or hotdog menu to sign in, then have |
Andrew T Wilson (Slow)
2013/02/15 10:11:49
nit: firt->first
Roger Tawa OOO till Jul 10th
2013/02/15 15:19:44
Done.
| |
956 // the option of checking the the box "Let me choose what to sync". When the | 955 // the option of checking the the box "Let me choose what to sync". When the |
957 // sign in process started, the source parameter in the continue URL may have | 956 // sign in process started, the source parameter in the continue URL may have |
958 // indicated one of the three options above. However, once this box is | 957 // indicated one of the three options above. However, once this box is |
959 // checked, the source parameter will indicate settings. This will only be | 958 // checked, the source parameter will indicate settings. This will only be |
960 // comminucated back to chrome when Gaia redirects to the continue URL, and | 959 // comminucated back to chrome when Gaia redirects to the continue URL, and |
Andrew T Wilson (Slow)
2013/02/15 10:11:49
nit:comminucated->communicated
Roger Tawa OOO till Jul 10th
2013/02/15 15:19:44
Done.
| |
961 // this is considered here a last minute change to the source. See a little | 960 // this is considered here a last minute change to the source. See a little |
962 // further below for when this variable is set to true. | 961 // further below for when this variable is set to true. |
963 bool last_minute_source_change = false; | 962 bool force_same_tab_navigation = false; |
964 | 963 |
965 if (SyncPromoUI::UseWebBasedSigninFlow()) { | 964 if (SyncPromoUI::UseWebBasedSigninFlow()) { |
966 if (IsValidGaiaSigninRedirectOrResponseURL(url)) | 965 if (IsValidGaiaSigninRedirectOrResponseURL(url)) |
967 return; | 966 return; |
968 | 967 |
969 // During an explicit sign in, if the user has not yet reached the final | 968 // During an explicit sign in, if the user has not yet reached the final |
970 // continue URL, wait for it to arrive. Note that Gaia will add some extra | 969 // continue URL, wait for it to arrive. Note that Gaia will add some extra |
971 // query parameters to the continue URL. Ignore them when checking to | 970 // query parameters to the continue URL. Ignore them when checking to |
972 // see if the user has continued. | 971 // see if the user has continued. |
973 // | 972 // |
(...skipping 12 matching lines...) Expand all Loading... | |
986 const bool continue_url_match = (url.ReplaceComponents(replacements) == | 985 const bool continue_url_match = (url.ReplaceComponents(replacements) == |
987 continue_url_.ReplaceComponents(replacements)); | 986 continue_url_.ReplaceComponents(replacements)); |
988 if (!continue_url_match) { | 987 if (!continue_url_match) { |
989 VLOG(1) << "OneClickSigninHelper::DidStopLoading: invalid url='" | 988 VLOG(1) << "OneClickSigninHelper::DidStopLoading: invalid url='" |
990 << url.spec() | 989 << url.spec() |
991 << "' expected continue url=" << continue_url_; | 990 << "' expected continue url=" << continue_url_; |
992 CleanTransientState(); | 991 CleanTransientState(); |
993 return; | 992 return; |
994 } | 993 } |
995 | 994 |
996 // In explicit sign ins, the user may have checked the box | 995 // In explicit sign ins, the user may have changed the box |
997 // "Let me choose what to sync". This is reflected as a change in the | 996 // "Let me choose what to sync". This is reflected as a change in the |
998 // source of the continue URL. Make one last check of the current URL | 997 // source of the continue URL. Make one last check of the current URL |
999 // to see if there is a valid source and its set to settings. If so, | 998 // to see if there is a valid source. If so, it overrides the |
1000 // it overrides the current source. | 999 // current source. |
1000 // | |
1001 // If the source was changed to SOURCE_SETTINGS, we want | |
1002 // OneClickSigninSyncStarter to reuse the current tab to display the | |
1003 // advanced configuration. | |
1001 SyncPromoUI::Source source = | 1004 SyncPromoUI::Source source = |
1002 SyncPromoUI::GetSourceForSyncPromoURL(url); | 1005 SyncPromoUI::GetSourceForSyncPromoURL(url); |
1003 if (source == SyncPromoUI::SOURCE_SETTINGS && | 1006 if (source != source_) { |
1004 source_ != SyncPromoUI::SOURCE_SETTINGS) { | 1007 source_ = source; |
1005 source_ = SyncPromoUI::SOURCE_SETTINGS; | 1008 force_same_tab_navigation = source_ == SyncPromoUI::SOURCE_SETTINGS; |
1006 last_minute_source_change = true; | |
1007 } | 1009 } |
1008 } | 1010 } |
1009 } | 1011 } |
1010 | 1012 |
1011 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1013 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
1012 Profile* profile = | 1014 Profile* profile = |
1013 Profile::FromBrowserContext(contents->GetBrowserContext()); | 1015 Profile::FromBrowserContext(contents->GetBrowserContext()); |
1014 | 1016 |
1015 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." | 1017 VLOG(1) << "OneClickSigninHelper::DidStopLoading: signin is go." |
1016 << " auto_accept=" << auto_accept_ | 1018 << " auto_accept=" << auto_accept_ |
(...skipping 18 matching lines...) Expand all Loading... | |
1035 password_); | 1037 password_); |
1036 } | 1038 } |
1037 break; | 1039 break; |
1038 case AUTO_ACCEPT_ACCEPTED: | 1040 case AUTO_ACCEPT_ACCEPTED: |
1039 SigninManager::DisableOneClickSignIn(profile); | 1041 SigninManager::DisableOneClickSignIn(profile); |
1040 browser->window()->ShowOneClickSigninBubble( | 1042 browser->window()->ShowOneClickSigninBubble( |
1041 bubble_type, | 1043 bubble_type, |
1042 base::Bind(&StartSync, | 1044 base::Bind(&StartSync, |
1043 StartSyncArgs(profile, browser, auto_accept_, | 1045 StartSyncArgs(profile, browser, auto_accept_, |
1044 session_index_, email_, password_, | 1046 session_index_, email_, password_, |
1045 false /* last_minute_source_change */))); | 1047 false /* force_same_tab_navigation */))); |
1046 break; | 1048 break; |
1047 case AUTO_ACCEPT_CONFIGURE: | 1049 case AUTO_ACCEPT_CONFIGURE: |
1048 SigninManager::DisableOneClickSignIn(profile); | 1050 SigninManager::DisableOneClickSignIn(profile); |
1049 StartSync( | 1051 StartSync( |
1050 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, | 1052 StartSyncArgs(profile, browser, auto_accept_, session_index_, email_, |
1051 password_, false /* last_minute_source_change */), | 1053 password_, false /* force_same_tab_navigation */), |
1052 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 1054 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
1053 break; | 1055 break; |
1054 case AUTO_ACCEPT_EXPLICIT: { | 1056 case AUTO_ACCEPT_EXPLICIT: { |
1055 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1057 OneClickSigninSyncStarter::StartSyncMode start_mode = |
1056 source_ == SyncPromoUI::SOURCE_SETTINGS ? | 1058 source_ == SyncPromoUI::SOURCE_SETTINGS ? |
1057 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1059 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
1058 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1060 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
1059 | 1061 |
1060 // If the new email address is different from the email address that | 1062 // If the new email address is different from the email address that |
1061 // just signed in, show a confirmation dialog. | 1063 // just signed in, show a confirmation dialog. |
1062 std::string last_email = | 1064 std::string last_email = |
1063 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1065 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
1064 if (!last_email.empty() && last_email != email_) { | 1066 if (!last_email.empty() && last_email != email_) { |
1065 ConfirmEmailDialogDelegate::AskForConfirmation( | 1067 ConfirmEmailDialogDelegate::AskForConfirmation( |
1066 contents, | 1068 contents, |
1067 last_email, | 1069 last_email, |
1068 email_, | 1070 email_, |
1069 base::Bind( | 1071 base::Bind( |
1070 &StartExplicitSync, | 1072 &StartExplicitSync, |
1071 StartSyncArgs(profile, browser, auto_accept_, | 1073 StartSyncArgs(profile, browser, auto_accept_, |
1072 session_index_, email_, password_, | 1074 session_index_, email_, password_, |
1073 last_minute_source_change), | 1075 force_same_tab_navigation), |
1074 contents, | 1076 contents, |
1075 start_mode)); | 1077 start_mode)); |
1076 } else { | 1078 } else { |
1077 StartExplicitSync( | 1079 StartExplicitSync( |
1078 StartSyncArgs(profile, browser, auto_accept_, session_index_, | 1080 StartSyncArgs(profile, browser, auto_accept_, session_index_, |
1079 email_, password_, last_minute_source_change), | 1081 email_, password_, force_same_tab_navigation), |
1080 contents, | 1082 contents, |
1081 start_mode, | 1083 start_mode, |
1082 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); | 1084 IDS_ONE_CLICK_SIGNIN_CONFIRM_EMAIL_DIALOG_CANCEL_BUTTON); |
1083 } | 1085 } |
1084 | 1086 |
1085 if (last_minute_source_change && | 1087 if (source_ == SyncPromoUI::SOURCE_SETTINGS && |
1086 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == | 1088 SyncPromoUI::GetSourceForSyncPromoURL(continue_url_) == |
1087 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { | 1089 SyncPromoUI::SOURCE_WEBSTORE_INSTALL) { |
1088 redirect_url_ = continue_url_; | 1090 redirect_url_ = continue_url_; |
1089 ProfileSyncService* sync_service = | 1091 ProfileSyncService* sync_service = |
1090 ProfileSyncServiceFactory::GetForProfile(profile); | 1092 ProfileSyncServiceFactory::GetForProfile(profile); |
1091 if (sync_service) | 1093 if (sync_service) |
1092 sync_service->AddObserver(this); | 1094 sync_service->AddObserver(this); |
1093 } | 1095 } |
1094 | 1096 |
1095 // If this explicit sign in is not from settings page/webstore, show the | 1097 // 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... | |
1164 break; | 1166 break; |
1165 } | 1167 } |
1166 } | 1168 } |
1167 | 1169 |
1168 RedirectToNTP(); | 1170 RedirectToNTP(); |
1169 } | 1171 } |
1170 | 1172 |
1171 void OneClickSigninHelper::SigninSuccess() { | 1173 void OneClickSigninHelper::SigninSuccess() { |
1172 RedirectToNTP(); | 1174 RedirectToNTP(); |
1173 } | 1175 } |
OLD | NEW |