| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 start_mode_ = response; | 384 start_mode_ = response; |
| 385 else if (start_mode_ == CONFIRM_SYNC_SETTINGS_FIRST) | 385 else if (start_mode_ == CONFIRM_SYNC_SETTINGS_FIRST) |
| 386 start_mode_ = SYNC_WITH_DEFAULT_SETTINGS; | 386 start_mode_ = SYNC_WITH_DEFAULT_SETTINGS; |
| 387 | 387 |
| 388 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 388 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 389 signin->CompletePendingSignin(); | 389 signin->CompletePendingSignin(); |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 void OneClickSigninSyncStarter::OnSyncConfirmationUIClosed( | 393 void OneClickSigninSyncStarter::OnSyncConfirmationUIClosed( |
| 394 LoginUIService::SyncConfirmationUIClosedResults results) { | 394 LoginUIService::SyncConfirmationUIClosedResults results, |
| 395 bool open_activity_controls_url) { |
| 395 | 396 |
| 396 if (switches::UsePasswordSeparatedSigninFlow()) { | 397 if (switches::UsePasswordSeparatedSigninFlow()) { |
| 397 // We didn't run this callback in AccountAddedToCookie so do it now. | 398 // We didn't run this callback in AccountAddedToCookie so do it now. |
| 398 if (!sync_setup_completed_callback_.is_null()) | 399 if (!sync_setup_completed_callback_.is_null()) |
| 399 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); | 400 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); |
| 400 } | 401 } |
| 401 | 402 |
| 402 switch (results) { | 403 switch (results) { |
| 403 case LoginUIService::CONFIGURE_SYNC_FIRST: | 404 case LoginUIService::CONFIGURE_SYNC_FIRST: |
| 404 content::RecordAction( | 405 content::RecordAction( |
| 405 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); | 406 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); |
| 406 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 407 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
| 408 |
| 409 if (open_activity_controls_url) { |
| 410 // Observer will delete itself |
| 411 new OneClickSigninSyncObserver( |
| 412 web_contents(), |
| 413 profile_, |
| 414 browser_, |
| 415 GURL(chrome::kGoogleAccountActivityControlsURL), |
| 416 continue_url_); |
| 417 } |
| 407 break; | 418 break; |
| 408 case LoginUIService::SYNC_WITH_DEFAULT_SETTINGS: { | 419 case LoginUIService::SYNC_WITH_DEFAULT_SETTINGS: { |
| 409 content::RecordAction( | 420 content::RecordAction( |
| 410 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); | 421 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); |
| 411 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 422 SetFirstSetupComplete(); |
| 412 if (profile_sync_service) | |
| 413 profile_sync_service->SetFirstSetupComplete(); | |
| 414 FinishProfileSyncServiceSetup(); | 423 FinishProfileSyncServiceSetup(); |
| 424 if (open_activity_controls_url) { |
| 425 // Open the 'Activity controls' section of the privacy settings page. |
| 426 GURL url = GURL(chrome::kGoogleAccountActivityControlsURL); |
| 427 content::OpenURLParams params(url, |
| 428 content::Referrer(), |
| 429 NEW_FOREGROUND_TAB, |
| 430 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 431 false); |
| 432 browser_->OpenURL(params); |
| 433 } |
| 415 break; | 434 break; |
| 416 } | 435 } |
| 417 case LoginUIService::ABORT_SIGNIN: | 436 case LoginUIService::ABORT_SIGNIN: |
| 418 FinishProfileSyncServiceSetup(); | 437 FinishProfileSyncServiceSetup(); |
| 419 break; | 438 break; |
| 420 } | 439 } |
| 421 | 440 |
| 441 if (open_activity_controls_url) { |
| 442 content::RecordAction( |
| 443 base::UserMetricsAction("Signin_Signin_WithActivityControlsCheckbox")); |
| 444 } |
| 445 |
| 422 delete this; | 446 delete this; |
| 423 } | 447 } |
| 424 | 448 |
| 425 void OneClickSigninSyncStarter::SigninFailed( | 449 void OneClickSigninSyncStarter::SigninFailed( |
| 426 const GoogleServiceAuthError& error) { | 450 const GoogleServiceAuthError& error) { |
| 427 if (!sync_setup_completed_callback_.is_null()) | 451 if (!sync_setup_completed_callback_.is_null()) |
| 428 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); | 452 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); |
| 429 | 453 |
| 430 FinishProfileSyncServiceSetup(); | 454 FinishProfileSyncServiceSetup(); |
| 431 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { | 455 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 DisplayModalSyncConfirmationWindow(); | 492 DisplayModalSyncConfirmationWindow(); |
| 469 return; | 493 return; |
| 470 } | 494 } |
| 471 | 495 |
| 472 if (!sync_setup_completed_callback_.is_null()) | 496 if (!sync_setup_completed_callback_.is_null()) |
| 473 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); | 497 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); |
| 474 | 498 |
| 475 switch (start_mode_) { | 499 switch (start_mode_) { |
| 476 case SYNC_WITH_DEFAULT_SETTINGS: { | 500 case SYNC_WITH_DEFAULT_SETTINGS: { |
| 477 // Just kick off the sync machine, no need to configure it first. | 501 // Just kick off the sync machine, no need to configure it first. |
| 478 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 502 SetFirstSetupComplete(); |
| 479 if (profile_sync_service) | |
| 480 profile_sync_service->SetFirstSetupComplete(); | |
| 481 FinishProfileSyncServiceSetup(); | 503 FinishProfileSyncServiceSetup(); |
| 482 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { | 504 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
| 483 base::string16 message; | 505 base::string16 message; |
| 484 if (!profile_sync_service) { | 506 if (!GetProfileSyncService()) { |
| 485 // Sync is disabled by policy. | 507 // Sync is disabled by policy. |
| 486 message = l10n_util::GetStringUTF16( | 508 message = l10n_util::GetStringUTF16( |
| 487 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); | 509 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
| 488 } | 510 } |
| 489 DisplayFinalConfirmationBubble(message); | 511 DisplayFinalConfirmationBubble(message); |
| 490 } | 512 } |
| 491 break; | 513 break; |
| 492 } | 514 } |
| 493 case CONFIRM_SYNC_SETTINGS_FIRST: | 515 case CONFIRM_SYNC_SETTINGS_FIRST: |
| 494 // Blocks sync until the sync settings confirmation UI is closed. | 516 // Blocks sync until the sync settings confirmation UI is closed. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 } | 625 } |
| 604 } | 626 } |
| 605 | 627 |
| 606 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { | 628 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { |
| 607 ProfileSyncService* service = NULL; | 629 ProfileSyncService* service = NULL; |
| 608 if (profile_->IsSyncAllowed()) | 630 if (profile_->IsSyncAllowed()) |
| 609 service = ProfileSyncServiceFactory::GetForProfile(profile_); | 631 service = ProfileSyncServiceFactory::GetForProfile(profile_); |
| 610 return service; | 632 return service; |
| 611 } | 633 } |
| 612 | 634 |
| 635 void OneClickSigninSyncStarter::SetFirstSetupComplete() { |
| 636 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 637 if (profile_sync_service) |
| 638 profile_sync_service->SetFirstSetupComplete(); |
| 639 } |
| 640 |
| 613 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { | 641 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
| 614 ProfileSyncService* service = | 642 ProfileSyncService* service = |
| 615 ProfileSyncServiceFactory::GetForProfile(profile_); | 643 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 616 if (service) | 644 if (service) |
| 617 service->SetSetupInProgress(false); | 645 service->SetSetupInProgress(false); |
| 618 } | 646 } |
| 619 | 647 |
| 620 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( | 648 void OneClickSigninSyncStarter::ShowSettingsPageInWebContents( |
| 621 content::WebContents* contents, | 649 content::WebContents* contents, |
| 622 const std::string& sub_page) { | 650 const std::string& sub_page) { |
| 623 if (!continue_url_.is_empty()) { | 651 if (!continue_url_.is_empty()) { |
| 624 // The observer deletes itself once it's done. | 652 // The observer deletes itself once it's done. |
| 625 DCHECK(!sub_page.empty()); | 653 DCHECK(!sub_page.empty()); |
| 626 new OneClickSigninSyncObserver(contents, continue_url_); | 654 new OneClickSigninSyncObserver(contents, profile_, browser_, |
| 655 GURL::EmptyGURL(), continue_url_); |
| 627 } | 656 } |
| 628 | 657 |
| 629 GURL url = chrome::GetSettingsUrl(sub_page); | 658 GURL url = chrome::GetSettingsUrl(sub_page); |
| 630 content::OpenURLParams params(url, | 659 content::OpenURLParams params(url, |
| 631 content::Referrer(), | 660 content::Referrer(), |
| 632 CURRENT_TAB, | 661 CURRENT_TAB, |
| 633 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 662 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 634 false); | 663 false); |
| 635 contents->OpenURL(params); | 664 contents->OpenURL(params); |
| 636 | 665 |
| 637 // Activate the tab. | 666 // Activate the tab. |
| 638 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 667 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 639 int content_index = | 668 int content_index = |
| 640 browser->tab_strip_model()->GetIndexOfWebContents(contents); | 669 browser->tab_strip_model()->GetIndexOfWebContents(contents); |
| 641 browser->tab_strip_model()->ActivateTabAt(content_index, | 670 browser->tab_strip_model()->ActivateTabAt(content_index, |
| 642 false /* user_gesture */); | 671 false /* user_gesture */); |
| 643 } | 672 } |
| 644 | 673 |
| 645 void OneClickSigninSyncStarter::LoadContinueUrl() { | 674 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 646 web_contents()->GetController().LoadURL( | 675 web_contents()->GetController().LoadURL( |
| 647 continue_url_, | 676 continue_url_, |
| 648 content::Referrer(), | 677 content::Referrer(), |
| 649 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 678 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 650 std::string()); | 679 std::string()); |
| 651 } | 680 } |
| OLD | NEW |