| 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_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/sync/sync_prefs.h" | 24 #include "chrome/browser/sync/sync_prefs.h" |
| 25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_navigator.h" | 27 #include "chrome/browser/ui/browser_navigator.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/browser/ui/chrome_pages.h" | 29 #include "chrome/browser/ui/chrome_pages.h" |
| 30 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 30 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 31 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 31 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 32 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" | 32 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_dialog.h" |
| 33 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "grit/chromium_strings.h" |
| 35 #include "grit/generated_resources.h" |
| 36 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/resource/resource_bundle.h" |
| 34 | 38 |
| 35 OneClickSigninSyncStarter::OneClickSigninSyncStarter( | 39 OneClickSigninSyncStarter::OneClickSigninSyncStarter( |
| 36 Profile* profile, | 40 Profile* profile, |
| 37 Browser* browser, | 41 Browser* browser, |
| 38 const std::string& session_index, | 42 const std::string& session_index, |
| 39 const std::string& email, | 43 const std::string& email, |
| 40 const std::string& password, | 44 const std::string& password, |
| 41 StartSyncMode start_mode, | 45 StartSyncMode start_mode, |
| 42 bool force_same_tab_navigation, | 46 bool force_same_tab_navigation, |
| 43 bool confirmation_required) | 47 ConfirmationRequired confirmation_required) |
| 44 : start_mode_(start_mode), | 48 : start_mode_(start_mode), |
| 45 force_same_tab_navigation_(force_same_tab_navigation), | 49 force_same_tab_navigation_(force_same_tab_navigation), |
| 46 confirmation_required_(confirmation_required), | 50 confirmation_required_(confirmation_required), |
| 47 weak_pointer_factory_(this) { | 51 weak_pointer_factory_(this) { |
| 48 DCHECK(profile); | 52 DCHECK(profile); |
| 49 Initialize(profile, browser); | 53 Initialize(profile, browser); |
| 50 | 54 |
| 51 // Start the signin process using the cookies in the cookie jar. | 55 // Start the signin process using the cookies in the cookie jar. |
| 52 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_); | 56 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_); |
| 53 SigninManager::OAuthTokenFetchedCallback callback; | 57 SigninManager::OAuthTokenFetchedCallback callback; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 #if defined(ENABLE_CONFIGURATION_POLICY) | 104 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 101 policy::UserPolicySigninService* policy_service = | 105 policy::UserPolicySigninService* policy_service = |
| 102 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 106 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
| 103 policy_service->RegisterPolicyClient( | 107 policy_service->RegisterPolicyClient( |
| 104 signin->GetUsernameForAuthInProgress(), | 108 signin->GetUsernameForAuthInProgress(), |
| 105 oauth_token, | 109 oauth_token, |
| 106 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, | 110 base::Bind(&OneClickSigninSyncStarter::OnRegisteredForPolicy, |
| 107 weak_pointer_factory_.GetWeakPtr())); | 111 weak_pointer_factory_.GetWeakPtr())); |
| 108 return; | 112 return; |
| 109 #else | 113 #else |
| 110 SigninAfterSAMLConfirmation(); | 114 ConfirmAndSignin(); |
| 111 #endif | 115 #endif |
| 112 } else { | 116 } else { |
| 113 // The user is already signed in - just tell SigninManager to continue | 117 // The user is already signed in - just tell SigninManager to continue |
| 114 // with its re-auth flow. | 118 // with its re-auth flow. |
| 115 signin->CompletePendingSignin(); | 119 signin->CompletePendingSignin(); |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 | 122 |
| 119 #if defined(ENABLE_CONFIGURATION_POLICY) | 123 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 120 void OneClickSigninSyncStarter::OnRegisteredForPolicy( | 124 void OneClickSigninSyncStarter::OnRegisteredForPolicy( |
| 121 scoped_ptr<policy::CloudPolicyClient> client) { | 125 scoped_ptr<policy::CloudPolicyClient> client) { |
| 122 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 126 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 123 // If there's no token for the user (policy registration did not succeed) just | 127 // If there's no token for the user (policy registration did not succeed) just |
| 124 // finish signing in. | 128 // finish signing in. |
| 125 if (!client.get()) { | 129 if (!client.get()) { |
| 126 DVLOG(1) << "Policy registration failed"; | 130 DVLOG(1) << "Policy registration failed"; |
| 127 SigninAfterSAMLConfirmation(); | 131 ConfirmAndSignin(); |
| 128 return; | 132 return; |
| 129 } | 133 } |
| 130 | 134 |
| 131 DCHECK(client->is_registered()); | 135 DCHECK(client->is_registered()); |
| 132 DVLOG(1) << "Policy registration succeeded: dm_token=" << client->dm_token(); | 136 DVLOG(1) << "Policy registration succeeded: dm_token=" << client->dm_token(); |
| 133 | 137 |
| 134 // Stash away a copy of our CloudPolicyClient (should not already have one). | 138 // Stash away a copy of our CloudPolicyClient (should not already have one). |
| 135 DCHECK(!policy_client_); | 139 DCHECK(!policy_client_); |
| 136 policy_client_.swap(client); | 140 policy_client_.swap(client); |
| 137 | 141 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // object will get freed when the signin on the old profile is cancelled. | 232 // object will get freed when the signin on the old profile is cancelled. |
| 229 old_signin_manager->SignOut(); | 233 old_signin_manager->SignOut(); |
| 230 | 234 |
| 231 // Load policy for the just-created profile - once policy has finished | 235 // Load policy for the just-created profile - once policy has finished |
| 232 // loading the signin process will complete. | 236 // loading the signin process will complete. |
| 233 LoadPolicyWithCachedClient(); | 237 LoadPolicyWithCachedClient(); |
| 234 } | 238 } |
| 235 } | 239 } |
| 236 #endif | 240 #endif |
| 237 | 241 |
| 238 void OneClickSigninSyncStarter::SigninAfterSAMLConfirmation() { | 242 void OneClickSigninSyncStarter::ConfirmAndSignin() { |
| 239 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 243 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 240 // browser_ can be null for unit tests. | 244 // browser_ can be null for unit tests. |
| 241 if (!browser_ || !confirmation_required_) { | 245 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { |
| 242 // No confirmation required - just sign in the user. | |
| 243 signin->CompletePendingSignin(); | |
| 244 } else { | |
| 245 // Display a confirmation dialog to the user. | 246 // Display a confirmation dialog to the user. |
| 246 browser_->window()->ShowOneClickSigninBubble( | 247 browser_->window()->ShowOneClickSigninBubble( |
| 247 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, | 248 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, |
| 248 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), | 249 UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), |
| 249 string16(), // No error message to display. | 250 string16(), // No error message to display. |
| 250 base::Bind(&OneClickSigninSyncStarter::SigninConfirmationComplete, | 251 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, |
| 251 weak_pointer_factory_.GetWeakPtr())); | 252 weak_pointer_factory_.GetWeakPtr())); |
| 253 } else { |
| 254 // No confirmation required - just sign in the user. |
| 255 signin->CompletePendingSignin(); |
| 252 } | 256 } |
| 253 } | 257 } |
| 254 | 258 |
| 255 void OneClickSigninSyncStarter::SigninConfirmationComplete( | 259 void OneClickSigninSyncStarter::UntrustedSigninConfirmed( |
| 256 StartSyncMode response) { | 260 StartSyncMode response) { |
| 257 if (response == UNDO_SYNC) { | 261 if (response == UNDO_SYNC) { |
| 258 CancelSigninAndDelete(); | 262 CancelSigninAndDelete(); |
| 259 } else { | 263 } else { |
| 260 // If the user clicked the "Advanced" link in the confirmation dialog, then | 264 // If the user clicked the "Advanced" link in the confirmation dialog, then |
| 261 // override the current start_mode_ to bring up the advanced sync settings. | 265 // override the current start_mode_ to bring up the advanced sync settings. |
| 262 if (response == CONFIGURE_SYNC_FIRST) | 266 if (response == CONFIGURE_SYNC_FIRST) |
| 263 start_mode_ = response; | 267 start_mode_ = response; |
| 264 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 268 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 265 signin->CompletePendingSignin(); | 269 signin->CompletePendingSignin(); |
| 266 } | 270 } |
| 267 } | 271 } |
| 268 | 272 |
| 269 | 273 |
| 270 void OneClickSigninSyncStarter::SigninFailed( | 274 void OneClickSigninSyncStarter::SigninFailed( |
| 271 const GoogleServiceAuthError& error) { | 275 const GoogleServiceAuthError& error) { |
| 272 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 276 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 273 if (profile_sync_service) | 277 if (profile_sync_service) |
| 274 profile_sync_service->SetSetupInProgress(false); | 278 profile_sync_service->SetSetupInProgress(false); |
| 279 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
| 280 switch (error.state()) { |
| 281 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
| 282 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( |
| 283 IDS_SYNC_UNRECOVERABLE_ERROR)); |
| 284 break; |
| 285 case GoogleServiceAuthError::REQUEST_CANCELED: |
| 286 // No error notification needed if the user manually cancelled signin. |
| 287 break; |
| 288 default: |
| 289 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( |
| 290 IDS_SYNC_ERROR_SIGNING_IN)); |
| 291 break; |
| 292 } |
| 293 } |
| 275 delete this; | 294 delete this; |
| 276 } | 295 } |
| 277 | 296 |
| 278 void OneClickSigninSyncStarter::SigninSuccess() { | 297 void OneClickSigninSyncStarter::SigninSuccess() { |
| 279 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 298 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 280 switch (start_mode_) { | 299 switch (start_mode_) { |
| 281 case SYNC_WITH_DEFAULT_SETTINGS: | 300 case SYNC_WITH_DEFAULT_SETTINGS: |
| 282 if (profile_sync_service) { | 301 if (profile_sync_service) { |
| 283 // Just kick off the sync machine, no need to configure it first. | 302 // Just kick off the sync machine, no need to configure it first. |
| 284 profile_sync_service->OnUserChoseDatatypes(true, | 303 profile_sync_service->OnUserChoseDatatypes(true, |
| 285 syncer::ModelTypeSet()); | 304 syncer::ModelTypeSet()); |
| 286 profile_sync_service->SetSyncSetupCompleted(); | 305 profile_sync_service->SetSyncSetupCompleted(); |
| 287 profile_sync_service->SetSetupInProgress(false); | 306 profile_sync_service->SetSetupInProgress(false); |
| 288 } | 307 } |
| 308 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
| 309 string16 message; |
| 310 if (!profile_sync_service) { |
| 311 // Sync is disabled by policy. |
| 312 message = l10n_util::GetStringUTF16( |
| 313 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
| 314 } |
| 315 DisplayFinalConfirmationBubble(message); |
| 316 } |
| 289 break; | 317 break; |
| 290 case CONFIGURE_SYNC_FIRST: | 318 case CONFIGURE_SYNC_FIRST: |
| 291 ConfigureSync(); | 319 ConfigureSync(); |
| 292 break; | 320 break; |
| 293 default: | 321 default: |
| 294 NOTREACHED() << "Invalid start_mode=" << start_mode_; | 322 NOTREACHED() << "Invalid start_mode=" << start_mode_; |
| 295 } | 323 } |
| 324 delete this; |
| 325 } |
| 296 | 326 |
| 297 delete this; | 327 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
| 328 const string16& custom_message) { |
| 329 EnsureBrowser(); |
| 330 browser_->window()->ShowOneClickSigninBubble( |
| 331 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 332 string16(), // No email required - this is not a SAML confirmation. |
| 333 custom_message, |
| 334 // Callback is ignored. |
| 335 BrowserWindow::StartSyncCallback()); |
| 336 } |
| 337 |
| 338 void OneClickSigninSyncStarter::EnsureBrowser() { |
| 339 if (!browser_) { |
| 340 // The user just created a new profile so we need to figure out what |
| 341 // browser to use to display settings. Grab the most recently active |
| 342 // browser or else create a new one. |
| 343 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); |
| 344 if (!browser_) { |
| 345 browser_ = new Browser(Browser::CreateParams(profile_, |
| 346 desktop_type_)); |
| 347 } |
| 348 browser_->window()->Show(); |
| 349 } |
| 298 } | 350 } |
| 299 | 351 |
| 300 void OneClickSigninSyncStarter::ConfigureSync() { | 352 void OneClickSigninSyncStarter::ConfigureSync() { |
| 301 // Give the user a chance to configure things. We don't clear the | 353 // Give the user a chance to configure things. We don't clear the |
| 302 // ProfileSyncService::setup_in_progress flag because we don't want sync | 354 // ProfileSyncService::setup_in_progress flag because we don't want sync |
| 303 // to start up until after the configure UI is displayed (the configure UI | 355 // to start up until after the configure UI is displayed (the configure UI |
| 304 // will clear the flag when the user is done setting up sync). | 356 // will clear the flag when the user is done setting up sync). |
| 305 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 357 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 306 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); | 358 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); |
| 307 if (login_ui->current_login_ui()) { | 359 if (login_ui->current_login_ui()) { |
| 308 login_ui->current_login_ui()->FocusUI(); | 360 login_ui->current_login_ui()->FocusUI(); |
| 309 } else { | 361 } else { |
| 310 if (!browser_) { | 362 EnsureBrowser(); |
| 311 // The user just created a new profile so we need to figure out what | |
| 312 // browser to use to display settings. Grab the most recently active | |
| 313 // browser or else create a new one. | |
| 314 browser_ = chrome::FindLastActiveWithProfile(profile_, desktop_type_); | |
| 315 if (!browser_) { | |
| 316 browser_ = new Browser(Browser::CreateParams(profile_, | |
| 317 desktop_type_)); | |
| 318 } | |
| 319 browser_->window()->Show(); | |
| 320 } | |
| 321 if (profile_sync_service) { | 363 if (profile_sync_service) { |
| 322 // Need to navigate to the settings page and display the sync UI. | 364 // Need to navigate to the settings page and display the sync UI. |
| 323 if (force_same_tab_navigation_) { | 365 if (force_same_tab_navigation_) { |
| 324 ShowSyncSettingsPageOnSameTab(); | 366 ShowSyncSettingsPageOnSameTab(); |
| 325 } else { | 367 } else { |
| 326 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 368 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
| 327 } | 369 } |
| 328 } else { | 370 } else { |
| 329 // Sync is disabled - just display the settings page. | 371 // Sync is disabled - just display the settings page. |
| 330 chrome::ShowSettings(browser_); | 372 chrome::ShowSettings(browser_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 341 | 383 |
| 342 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { | 384 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { |
| 343 std::string url = std::string(chrome::kChromeUISettingsURL) + | 385 std::string url = std::string(chrome::kChromeUISettingsURL) + |
| 344 chrome::kSyncSetupSubPage; | 386 chrome::kSyncSetupSubPage; |
| 345 chrome::NavigateParams params( | 387 chrome::NavigateParams params( |
| 346 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 388 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 347 params.disposition = CURRENT_TAB; | 389 params.disposition = CURRENT_TAB; |
| 348 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 390 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 349 chrome::Navigate(¶ms); | 391 chrome::Navigate(¶ms); |
| 350 } | 392 } |
| OLD | NEW |