| 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 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 base::string16(), /* no SAML email */ | 1155 base::string16(), /* no SAML email */ |
| 1156 base::UTF8ToUTF16(error), | 1156 base::UTF8ToUTF16(error), |
| 1157 // This callback is never invoked. | 1157 // This callback is never invoked. |
| 1158 // TODO(rogerta): Separate out the bubble API so we don't have to pass | 1158 // TODO(rogerta): Separate out the bubble API so we don't have to pass |
| 1159 // ignored |email| and |callback| params. | 1159 // ignored |email| and |callback| params. |
| 1160 BrowserWindow::StartSyncCallback()); | 1160 BrowserWindow::StartSyncCallback()); |
| 1161 } | 1161 } |
| 1162 | 1162 |
| 1163 // static | 1163 // static |
| 1164 bool OneClickSigninHelper::HandleCrossAccountError( | 1164 bool OneClickSigninHelper::HandleCrossAccountError( |
| 1165 content::WebContents* contents, | 1165 Profile* profile, |
| 1166 const std::string& session_index, | 1166 const std::string& session_index, |
| 1167 const std::string& email, | 1167 const std::string& email, |
| 1168 const std::string& password, | 1168 const std::string& password, |
| 1169 const std::string& refresh_token, | 1169 const std::string& refresh_token, |
| 1170 OneClickSigninHelper::AutoAccept auto_accept, | 1170 OneClickSigninHelper::AutoAccept auto_accept, |
| 1171 signin::Source source, | 1171 signin::Source source, |
| 1172 OneClickSigninSyncStarter::StartSyncMode start_mode, | 1172 OneClickSigninSyncStarter::StartSyncMode start_mode, |
| 1173 OneClickSigninSyncStarter::Callback sync_callback) { | 1173 OneClickSigninSyncStarter::Callback sync_callback) { |
| 1174 Profile* profile = | |
| 1175 Profile::FromBrowserContext(contents->GetBrowserContext()); | |
| 1176 std::string last_email = | 1174 std::string last_email = |
| 1177 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); | 1175 profile->GetPrefs()->GetString(prefs::kGoogleServicesLastUsername); |
| 1178 | 1176 |
| 1179 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) { | 1177 if (!last_email.empty() && !gaia::AreEmailsSame(last_email, email)) { |
| 1180 // If the new email address is different from the email address that | 1178 // If the new email address is different from the email address that |
| 1181 // just signed in, show a confirmation dialog. | 1179 // just signed in, show a confirmation dialog on top of the current active |
| 1180 // tab. |
| 1182 | 1181 |
| 1183 // No need to display a second confirmation so pass false below. | 1182 // No need to display a second confirmation so pass false below. |
| 1184 // TODO(atwilson): Move this into OneClickSigninSyncStarter. | 1183 // TODO(atwilson): Move this into OneClickSigninSyncStarter. |
| 1185 // The tab modal dialog always executes its callback before |contents| | 1184 // The tab modal dialog always executes its callback before |contents| |
| 1186 // is deleted. | 1185 // is deleted. |
| 1187 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 1186 Browser* browser = chrome::FindLastActiveWithProfile( |
| 1187 profile, chrome::GetActiveDesktop()); |
| 1188 content::WebContents* contents = |
| 1189 browser->tab_strip_model()->GetActiveWebContents(); |
| 1188 ConfirmEmailDialogDelegate::AskForConfirmation( | 1190 ConfirmEmailDialogDelegate::AskForConfirmation( |
| 1189 contents, | 1191 contents, |
| 1190 last_email, | 1192 last_email, |
| 1191 email, | 1193 email, |
| 1192 base::Bind( | 1194 base::Bind( |
| 1193 &StartExplicitSync, | 1195 &StartExplicitSync, |
| 1194 StartSyncArgs(profile, browser, auto_accept, | 1196 StartSyncArgs(profile, browser, auto_accept, |
| 1195 session_index, email, password, | 1197 session_index, email, password, |
| 1196 refresh_token, | 1198 refresh_token, |
| 1197 contents, false /* confirmation_required */, source, | 1199 contents, false /* confirmation_required */, source, |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 signin_error_controller(); | 1545 signin_error_controller(); |
| 1544 | 1546 |
| 1545 OneClickSigninSyncStarter::StartSyncMode start_mode = | 1547 OneClickSigninSyncStarter::StartSyncMode start_mode = |
| 1546 source_ == signin::SOURCE_SETTINGS ? | 1548 source_ == signin::SOURCE_SETTINGS ? |
| 1547 (error_controller->HasError() && | 1549 (error_controller->HasError() && |
| 1548 sync_service && sync_service->HasSyncSetupCompleted()) ? | 1550 sync_service && sync_service->HasSyncSetupCompleted()) ? |
| 1549 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : | 1551 OneClickSigninSyncStarter::SHOW_SETTINGS_WITHOUT_CONFIGURE : |
| 1550 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : | 1552 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST : |
| 1551 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; | 1553 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS; |
| 1552 | 1554 |
| 1553 if (!HandleCrossAccountError(contents, session_index_, email_, password_, | 1555 if (!HandleCrossAccountError(profile, session_index_, email_, password_, |
| 1554 "", auto_accept_, source_, start_mode, | 1556 "", auto_accept_, source_, start_mode, |
| 1555 CreateSyncStarterCallback())) { | 1557 CreateSyncStarterCallback())) { |
| 1556 if (!do_not_start_sync_for_testing_) { | 1558 if (!do_not_start_sync_for_testing_) { |
| 1557 StartSync( | 1559 StartSync( |
| 1558 StartSyncArgs(profile, browser, auto_accept_, | 1560 StartSyncArgs(profile, browser, auto_accept_, |
| 1559 session_index_, email_, password_, "", | 1561 session_index_, email_, password_, "", |
| 1560 contents, | 1562 contents, |
| 1561 untrusted_confirmation_required_, source_, | 1563 untrusted_confirmation_required_, source_, |
| 1562 CreateSyncStarterCallback()), | 1564 CreateSyncStarterCallback()), |
| 1563 start_mode); | 1565 start_mode); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 // If the web contents is showing a blank page and not about to be closed, | 1614 // If the web contents is showing a blank page and not about to be closed, |
| 1613 // redirect to the NTP or apps page. | 1615 // redirect to the NTP or apps page. |
| 1614 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && | 1616 if (signin::IsContinueUrlForWebBasedSigninFlow(current_url) && |
| 1615 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { | 1617 !signin::IsAutoCloseEnabledInURL(original_continue_url_)) { |
| 1616 RedirectToNtpOrAppsPage( | 1618 RedirectToNtpOrAppsPage( |
| 1617 web_contents(), | 1619 web_contents(), |
| 1618 signin::GetSourceForPromoURL(original_continue_url_)); | 1620 signin::GetSourceForPromoURL(original_continue_url_)); |
| 1619 } | 1621 } |
| 1620 } | 1622 } |
| 1621 } | 1623 } |
| OLD | NEW |