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