| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const std::string& refresh_token, | 83 const std::string& refresh_token, |
| 84 StartSyncMode start_mode, | 84 StartSyncMode start_mode, |
| 85 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
| 86 ConfirmationRequired confirmation_required, | 86 ConfirmationRequired confirmation_required, |
| 87 const GURL& current_url, | 87 const GURL& current_url, |
| 88 const GURL& continue_url, | 88 const GURL& continue_url, |
| 89 Callback sync_setup_completed_callback) | 89 Callback sync_setup_completed_callback) |
| 90 : content::WebContentsObserver(web_contents), | 90 : content::WebContentsObserver(web_contents), |
| 91 profile_(NULL), | 91 profile_(NULL), |
| 92 start_mode_(start_mode), | 92 start_mode_(start_mode), |
| 93 desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | |
| 94 confirmation_required_(confirmation_required), | 93 confirmation_required_(confirmation_required), |
| 95 current_url_(current_url), | 94 current_url_(current_url), |
| 96 continue_url_(continue_url), | 95 continue_url_(continue_url), |
| 97 sync_setup_completed_callback_(sync_setup_completed_callback), | 96 sync_setup_completed_callback_(sync_setup_completed_callback), |
| 98 weak_pointer_factory_(this) { | 97 weak_pointer_factory_(this) { |
| 99 DCHECK(profile); | 98 DCHECK(profile); |
| 100 DCHECK(web_contents || continue_url.is_empty()); | 99 DCHECK(web_contents || continue_url.is_empty()); |
| 101 BrowserList::AddObserver(this); | 100 BrowserList::AddObserver(this); |
| 102 Initialize(profile, browser); | 101 Initialize(profile, browser); |
| 103 | 102 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 124 DCHECK(profile); | 123 DCHECK(profile); |
| 125 | 124 |
| 126 if (profile_) | 125 if (profile_) |
| 127 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); | 126 LoginUIServiceFactory::GetForProfile(profile_)->RemoveObserver(this); |
| 128 | 127 |
| 129 profile_ = profile; | 128 profile_ = profile; |
| 130 browser_ = browser; | 129 browser_ = browser; |
| 131 | 130 |
| 132 LoginUIServiceFactory::GetForProfile(profile_)->AddObserver(this); | 131 LoginUIServiceFactory::GetForProfile(profile_)->AddObserver(this); |
| 133 | 132 |
| 134 // Cache the parent desktop for the browser, so we can reuse that same | |
| 135 // desktop for any UI we want to display. | |
| 136 if (browser) { | |
| 137 desktop_type_ = browser->host_desktop_type(); | |
| 138 } else { | |
| 139 desktop_type_ = chrome::GetActiveDesktop(); | |
| 140 } | |
| 141 | |
| 142 signin_tracker_ = SigninTrackerFactory::CreateForProfile(profile_, this); | 133 signin_tracker_ = SigninTrackerFactory::CreateForProfile(profile_, this); |
| 143 | 134 |
| 144 // Let the sync service know that setup is in progress so it doesn't start | 135 // Let the sync service know that setup is in progress so it doesn't start |
| 145 // syncing until the user has finished any configuration. | 136 // syncing until the user has finished any configuration. |
| 146 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 137 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 147 if (profile_sync_service) | 138 if (profile_sync_service) |
| 148 profile_sync_service->SetSetupInProgress(true); | 139 profile_sync_service->SetSetupInProgress(true); |
| 149 | 140 |
| 150 // Make sure the syncing is requested, otherwise the SigninManager | 141 // Make sure the syncing is requested, otherwise the SigninManager |
| 151 // will not be able to complete successfully. | 142 // will not be able to complete successfully. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 217 |
| 227 DVLOG(1) << "Policy registration succeeded: dm_token=" << dm_token; | 218 DVLOG(1) << "Policy registration succeeded: dm_token=" << dm_token; |
| 228 | 219 |
| 229 // Stash away a copy of our CloudPolicyClient (should not already have one). | 220 // Stash away a copy of our CloudPolicyClient (should not already have one). |
| 230 DCHECK(dm_token_.empty()); | 221 DCHECK(dm_token_.empty()); |
| 231 DCHECK(client_id_.empty()); | 222 DCHECK(client_id_.empty()); |
| 232 dm_token_ = dm_token; | 223 dm_token_ = dm_token; |
| 233 client_id_ = client_id; | 224 client_id_ = client_id; |
| 234 | 225 |
| 235 // Allow user to create a new profile before continuing with sign-in. | 226 // Allow user to create a new profile before continuing with sign-in. |
| 236 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 227 browser_ = EnsureBrowser(browser_, profile_); |
| 237 content::WebContents* web_contents = | 228 content::WebContents* web_contents = |
| 238 browser_->tab_strip_model()->GetActiveWebContents(); | 229 browser_->tab_strip_model()->GetActiveWebContents(); |
| 239 if (!web_contents) { | 230 if (!web_contents) { |
| 240 CancelSigninAndDelete(); | 231 CancelSigninAndDelete(); |
| 241 return; | 232 return; |
| 242 } | 233 } |
| 243 | 234 |
| 244 content::RecordAction( | 235 content::RecordAction( |
| 245 base::UserMetricsAction("Signin_Show_EnterpriseAccountPrompt")); | 236 base::UserMetricsAction("Signin_Show_EnterpriseAccountPrompt")); |
| 246 TabDialogs::FromWebContents(web_contents)->ShowProfileSigninConfirmation( | 237 TabDialogs::FromWebContents(web_contents)->ShowProfileSigninConfirmation( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 DCHECK(!dm_token_.empty()); | 271 DCHECK(!dm_token_.empty()); |
| 281 DCHECK(!client_id_.empty()); | 272 DCHECK(!client_id_.empty()); |
| 282 // Create a new profile and have it call back when done so we can inject our | 273 // Create a new profile and have it call back when done so we can inject our |
| 283 // signin credentials. | 274 // signin credentials. |
| 284 size_t icon_index = g_browser_process->profile_manager()-> | 275 size_t icon_index = g_browser_process->profile_manager()-> |
| 285 GetProfileInfoCache().ChooseAvatarIconIndexForNewProfile(); | 276 GetProfileInfoCache().ChooseAvatarIconIndexForNewProfile(); |
| 286 ProfileManager::CreateMultiProfileAsync( | 277 ProfileManager::CreateMultiProfileAsync( |
| 287 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), | 278 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), |
| 288 profiles::GetDefaultAvatarIconUrl(icon_index), | 279 profiles::GetDefaultAvatarIconUrl(icon_index), |
| 289 base::Bind(&OneClickSigninSyncStarter::CompleteInitForNewProfile, | 280 base::Bind(&OneClickSigninSyncStarter::CompleteInitForNewProfile, |
| 290 weak_pointer_factory_.GetWeakPtr(), desktop_type_), | 281 weak_pointer_factory_.GetWeakPtr()), |
| 291 std::string()); | 282 std::string()); |
| 292 } | 283 } |
| 293 | 284 |
| 294 void OneClickSigninSyncStarter::CompleteInitForNewProfile( | 285 void OneClickSigninSyncStarter::CompleteInitForNewProfile( |
| 295 chrome::HostDesktopType desktop_type, | |
| 296 Profile* new_profile, | 286 Profile* new_profile, |
| 297 Profile::CreateStatus status) { | 287 Profile::CreateStatus status) { |
| 298 DCHECK_NE(profile_, new_profile); | 288 DCHECK_NE(profile_, new_profile); |
| 299 | 289 |
| 300 // TODO(atwilson): On error, unregister the client to release the DMToken | 290 // TODO(atwilson): On error, unregister the client to release the DMToken |
| 301 // and surface a better error for the user. | 291 // and surface a better error for the user. |
| 302 switch (status) { | 292 switch (status) { |
| 303 case Profile::CREATE_STATUS_LOCAL_FAIL: { | 293 case Profile::CREATE_STATUS_LOCAL_FAIL: { |
| 304 NOTREACHED() << "Error creating new profile"; | 294 NOTREACHED() << "Error creating new profile"; |
| 305 CancelSigninAndDelete(); | 295 CancelSigninAndDelete(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 336 | 326 |
| 337 // Load policy for the just-created profile - once policy has finished | 327 // Load policy for the just-created profile - once policy has finished |
| 338 // loading the signin process will complete. | 328 // loading the signin process will complete. |
| 339 LoadPolicyWithCachedCredentials(); | 329 LoadPolicyWithCachedCredentials(); |
| 340 | 330 |
| 341 // Open the profile's first window, after all initialization. | 331 // Open the profile's first window, after all initialization. |
| 342 profiles::FindOrCreateNewWindowForProfile( | 332 profiles::FindOrCreateNewWindowForProfile( |
| 343 new_profile, | 333 new_profile, |
| 344 chrome::startup::IS_PROCESS_STARTUP, | 334 chrome::startup::IS_PROCESS_STARTUP, |
| 345 chrome::startup::IS_FIRST_RUN, | 335 chrome::startup::IS_FIRST_RUN, |
| 346 desktop_type, | |
| 347 false); | 336 false); |
| 348 break; | 337 break; |
| 349 } | 338 } |
| 350 case Profile::CREATE_STATUS_REMOTE_FAIL: | 339 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 351 case Profile::CREATE_STATUS_CANCELED: | 340 case Profile::CREATE_STATUS_CANCELED: |
| 352 case Profile::MAX_CREATE_STATUS: { | 341 case Profile::MAX_CREATE_STATUS: { |
| 353 NOTREACHED() << "Invalid profile creation status"; | 342 NOTREACHED() << "Invalid profile creation status"; |
| 354 CancelSigninAndDelete(); | 343 CancelSigninAndDelete(); |
| 355 return; | 344 return; |
| 356 } | 345 } |
| 357 } | 346 } |
| 358 } | 347 } |
| 359 #endif | 348 #endif |
| 360 | 349 |
| 361 void OneClickSigninSyncStarter::CancelSigninAndDelete() { | 350 void OneClickSigninSyncStarter::CancelSigninAndDelete() { |
| 362 SigninManagerFactory::GetForProfile(profile_) | 351 SigninManagerFactory::GetForProfile(profile_) |
| 363 ->SignOut(signin_metrics::ABORT_SIGNIN, | 352 ->SignOut(signin_metrics::ABORT_SIGNIN, |
| 364 signin_metrics::SignoutDelete::IGNORE_METRIC); | 353 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 365 // The statement above results in a call to SigninFailed() which will free | 354 // The statement above results in a call to SigninFailed() which will free |
| 366 // this object, so do not refer to the OneClickSigninSyncStarter object | 355 // this object, so do not refer to the OneClickSigninSyncStarter object |
| 367 // after this point. | 356 // after this point. |
| 368 } | 357 } |
| 369 | 358 |
| 370 void OneClickSigninSyncStarter::ConfirmAndSignin() { | 359 void OneClickSigninSyncStarter::ConfirmAndSignin() { |
| 371 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 360 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 372 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { | 361 if (confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { |
| 373 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 362 browser_ = EnsureBrowser(browser_, profile_); |
| 374 content::RecordAction( | 363 content::RecordAction( |
| 375 base::UserMetricsAction("Signin_Show_UntrustedSigninPrompt")); | 364 base::UserMetricsAction("Signin_Show_UntrustedSigninPrompt")); |
| 376 // Display a confirmation dialog to the user. | 365 // Display a confirmation dialog to the user. |
| 377 browser_->window()->ShowOneClickSigninBubble( | 366 browser_->window()->ShowOneClickSigninBubble( |
| 378 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, | 367 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG, |
| 379 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), | 368 base::UTF8ToUTF16(signin->GetUsernameForAuthInProgress()), |
| 380 base::string16(), // No error message to display. | 369 base::string16(), // No error message to display. |
| 381 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, | 370 base::Bind(&OneClickSigninSyncStarter::UntrustedSigninConfirmed, |
| 382 weak_pointer_factory_.GetWeakPtr())); | 371 weak_pointer_factory_.GetWeakPtr())); |
| 383 LoginUIServiceFactory::GetForProfile(profile_)->UntrustedLoginUIShown(); | 372 LoginUIServiceFactory::GetForProfile(profile_)->UntrustedLoginUIShown(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 if (web_contents() && !continue_url_.is_empty() && | 508 if (web_contents() && !continue_url_.is_empty() && |
| 520 start_mode_ != CONFIGURE_SYNC_FIRST) { | 509 start_mode_ != CONFIGURE_SYNC_FIRST) { |
| 521 LoadContinueUrl(); | 510 LoadContinueUrl(); |
| 522 } | 511 } |
| 523 | 512 |
| 524 delete this; | 513 delete this; |
| 525 } | 514 } |
| 526 | 515 |
| 527 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( | 516 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
| 528 const base::string16& custom_message) { | 517 const base::string16& custom_message) { |
| 529 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 518 browser_ = EnsureBrowser(browser_, profile_); |
| 530 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 519 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
| 531 DisplayLoginResult(browser_, custom_message); | 520 DisplayLoginResult(browser_, custom_message); |
| 532 } | 521 } |
| 533 | 522 |
| 534 void OneClickSigninSyncStarter::DisplayModalSyncConfirmationWindow() { | 523 void OneClickSigninSyncStarter::DisplayModalSyncConfirmationWindow() { |
| 535 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 524 browser_ = EnsureBrowser(browser_, profile_); |
| 536 browser_->ShowModalSyncConfirmationWindow(); | 525 browser_->ShowModalSyncConfirmationWindow(); |
| 537 } | 526 } |
| 538 | 527 |
| 539 // static | 528 // static |
| 540 Browser* OneClickSigninSyncStarter::EnsureBrowser( | 529 Browser* OneClickSigninSyncStarter::EnsureBrowser(Browser* browser, |
| 541 Browser* browser, | 530 Profile* profile) { |
| 542 Profile* profile, | |
| 543 chrome::HostDesktopType desktop_type) { | |
| 544 if (!browser) { | 531 if (!browser) { |
| 545 // The user just created a new profile or has closed the browser that | 532 // The user just created a new profile or has closed the browser that |
| 546 // we used previously. Grab the most recently active browser or else | 533 // we used previously. Grab the most recently active browser or else |
| 547 // create a new one. | 534 // create a new one. |
| 548 browser = chrome::FindLastActiveWithProfile(profile); | 535 browser = chrome::FindLastActiveWithProfile(profile); |
| 549 if (!browser) { | 536 if (!browser) { |
| 550 browser = new Browser(Browser::CreateParams(profile)); | 537 browser = new Browser(Browser::CreateParams(profile)); |
| 551 chrome::AddTabAt(browser, GURL(), -1, true); | 538 chrome::AddTabAt(browser, GURL(), -1, true); |
| 552 } | 539 } |
| 553 browser->window()->Show(); | 540 browser->window()->Show(); |
| 554 } | 541 } |
| 555 return browser; | 542 return browser; |
| 556 } | 543 } |
| 557 | 544 |
| 558 void OneClickSigninSyncStarter::ShowSettingsPage(bool configure_sync) { | 545 void OneClickSigninSyncStarter::ShowSettingsPage(bool configure_sync) { |
| 559 // Give the user a chance to configure things. We don't clear the | 546 // Give the user a chance to configure things. We don't clear the |
| 560 // ProfileSyncService::setup_in_progress flag because we don't want sync | 547 // ProfileSyncService::setup_in_progress flag because we don't want sync |
| 561 // to start up until after the configure UI is displayed (the configure UI | 548 // to start up until after the configure UI is displayed (the configure UI |
| 562 // will clear the flag when the user is done setting up sync). | 549 // will clear the flag when the user is done setting up sync). |
| 563 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 550 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 564 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); | 551 LoginUIService* login_ui = LoginUIServiceFactory::GetForProfile(profile_); |
| 565 if (login_ui->current_login_ui()) { | 552 if (login_ui->current_login_ui()) { |
| 566 login_ui->current_login_ui()->FocusUI(); | 553 login_ui->current_login_ui()->FocusUI(); |
| 567 } else { | 554 } else { |
| 568 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 555 browser_ = EnsureBrowser(browser_, profile_); |
| 569 | 556 |
| 570 // If the sign in tab is showing the native signin page or the blank page | 557 // If the sign in tab is showing the native signin page or the blank page |
| 571 // for web-based flow, and is not about to be closed, use it to show the | 558 // for web-based flow, and is not about to be closed, use it to show the |
| 572 // settings UI. | 559 // settings UI. |
| 573 bool use_same_tab = false; | 560 bool use_same_tab = false; |
| 574 if (web_contents()) { | 561 if (web_contents()) { |
| 575 GURL current_url = web_contents()->GetLastCommittedURL(); | 562 GURL current_url = web_contents()->GetLastCommittedURL(); |
| 576 std::string constrained_key; | 563 std::string constrained_key; |
| 577 net::GetValueForKeyInQuery(current_url, "constrained", &constrained_key); | 564 net::GetValueForKeyInQuery(current_url, "constrained", &constrained_key); |
| 578 bool is_constrained = (constrained_key == "1"); | 565 bool is_constrained = (constrained_key == "1"); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 false /* user_gesture */); | 641 false /* user_gesture */); |
| 655 } | 642 } |
| 656 | 643 |
| 657 void OneClickSigninSyncStarter::LoadContinueUrl() { | 644 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 658 web_contents()->GetController().LoadURL( | 645 web_contents()->GetController().LoadURL( |
| 659 continue_url_, | 646 continue_url_, |
| 660 content::Referrer(), | 647 content::Referrer(), |
| 661 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 648 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 662 std::string()); | 649 std::string()); |
| 663 } | 650 } |
| OLD | NEW |