| 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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" | 34 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" |
| 35 #include "chrome/browser/ui/tab_dialogs.h" | 35 #include "chrome/browser/ui/tab_dialogs.h" |
| 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 37 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "chrome/grit/chromium_strings.h" | 39 #include "chrome/grit/chromium_strings.h" |
| 40 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
| 41 #include "components/browser_sync/browser/profile_sync_service.h" | 41 #include "components/browser_sync/browser/profile_sync_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 42 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/signin/core/browser/signin_metrics.h" | 43 #include "components/signin/core/browser/signin_metrics.h" |
| 44 #include "components/signin/core/common/profile_management_switches.h" |
| 44 #include "components/sync_driver/sync_prefs.h" | 45 #include "components/sync_driver/sync_prefs.h" |
| 45 #include "content/public/browser/user_metrics.h" | 46 #include "content/public/browser/user_metrics.h" |
| 46 #include "net/base/url_util.h" | 47 #include "net/base/url_util.h" |
| 47 #include "net/url_request/url_request_context_getter.h" | 48 #include "net/url_request/url_request_context_getter.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 // UMA histogram for tracking what users do when presented with the signin | 53 // UMA histogram for tracking what users do when presented with the signin |
| 53 // screen. | 54 // screen. |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 start_mode_ = response; | 403 start_mode_ = response; |
| 403 else if (start_mode_ == CONFIRM_SYNC_SETTINGS_FIRST) | 404 else if (start_mode_ == CONFIRM_SYNC_SETTINGS_FIRST) |
| 404 start_mode_ = SYNC_WITH_DEFAULT_SETTINGS; | 405 start_mode_ = SYNC_WITH_DEFAULT_SETTINGS; |
| 405 | 406 |
| 406 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 407 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 407 signin->CompletePendingSignin(); | 408 signin->CompletePendingSignin(); |
| 408 } | 409 } |
| 409 } | 410 } |
| 410 | 411 |
| 411 void OneClickSigninSyncStarter::OnSyncConfirmationUIClosed( | 412 void OneClickSigninSyncStarter::OnSyncConfirmationUIClosed( |
| 412 bool configure_sync_first) { | 413 LoginUIService::SyncConfirmationUIClosedResults results) { |
| 413 if (configure_sync_first) { | 414 switch (results) { |
| 414 content::RecordAction( | 415 case LoginUIService::CONFIGURE_SYNC_FIRST: |
| 415 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); | 416 content::RecordAction( |
| 416 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 417 base::UserMetricsAction("Signin_Signin_WithAdvancedSyncSettings")); |
| 417 } else { | 418 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
| 418 content::RecordAction( | 419 break; |
| 419 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); | 420 case LoginUIService::SYNC_WITH_DEFAULT_SETTINGS: { |
| 420 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 421 content::RecordAction( |
| 421 if (profile_sync_service) | 422 base::UserMetricsAction("Signin_Signin_WithDefaultSyncSettings")); |
| 422 profile_sync_service->SetFirstSetupComplete(); | 423 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 423 FinishProfileSyncServiceSetup(); | 424 if (profile_sync_service) |
| 425 profile_sync_service->SetFirstSetupComplete(); |
| 426 FinishProfileSyncServiceSetup(); |
| 427 break; |
| 428 } |
| 429 case LoginUIService::ABORT_SIGNIN: |
| 430 FinishProfileSyncServiceSetup(); |
| 431 break; |
| 424 } | 432 } |
| 425 | 433 |
| 426 delete this; | 434 delete this; |
| 427 } | 435 } |
| 428 | 436 |
| 429 void OneClickSigninSyncStarter::SigninFailed( | 437 void OneClickSigninSyncStarter::SigninFailed( |
| 430 const GoogleServiceAuthError& error) { | 438 const GoogleServiceAuthError& error) { |
| 431 if (!sync_setup_completed_callback_.is_null()) | 439 if (!sync_setup_completed_callback_.is_null()) |
| 432 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); | 440 sync_setup_completed_callback_.Run(SYNC_SETUP_FAILURE); |
| 433 | 441 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (!profile_sync_service) { | 488 if (!profile_sync_service) { |
| 481 // Sync is disabled by policy. | 489 // Sync is disabled by policy. |
| 482 message = l10n_util::GetStringUTF16( | 490 message = l10n_util::GetStringUTF16( |
| 483 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); | 491 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
| 484 } | 492 } |
| 485 DisplayFinalConfirmationBubble(message); | 493 DisplayFinalConfirmationBubble(message); |
| 486 } | 494 } |
| 487 break; | 495 break; |
| 488 } | 496 } |
| 489 case CONFIRM_SYNC_SETTINGS_FIRST: | 497 case CONFIRM_SYNC_SETTINGS_FIRST: |
| 490 // Blocks sync until the sync settings confirmation UI is closed. | 498 if (switches::UsePasswordSeparatedSigninFlow()) { |
| 491 DisplayFinalConfirmationBubble(base::string16()); | 499 DisplayModalSyncConfirmationWindow(); |
| 500 } else { |
| 501 // Blocks sync until the sync settings confirmation UI is closed. |
| 502 DisplayFinalConfirmationBubble(base::string16()); |
| 503 } |
| 492 return; | 504 return; |
| 493 case CONFIGURE_SYNC_FIRST: | 505 case CONFIGURE_SYNC_FIRST: |
| 494 ShowSettingsPage(true); // Show sync config UI. | 506 ShowSettingsPage(true); // Show sync config UI. |
| 495 break; | 507 break; |
| 496 case SHOW_SETTINGS_WITHOUT_CONFIGURE: | 508 case SHOW_SETTINGS_WITHOUT_CONFIGURE: |
| 497 ShowSettingsPage(false); // Don't show sync config UI. | 509 ShowSettingsPage(false); // Don't show sync config UI. |
| 498 break; | 510 break; |
| 499 case UNDO_SYNC: | 511 case UNDO_SYNC: |
| 500 NOTREACHED(); | 512 NOTREACHED(); |
| 501 } | 513 } |
| 502 | 514 |
| 503 // Navigate to the |continue_url_| if one is set, unless the user first needs | 515 // Navigate to the |continue_url_| if one is set, unless the user first needs |
| 504 // to configure Sync. | 516 // to configure Sync. |
| 505 if (web_contents() && !continue_url_.is_empty() && | 517 if (web_contents() && !continue_url_.is_empty() && |
| 506 start_mode_ != CONFIGURE_SYNC_FIRST) { | 518 start_mode_ != CONFIGURE_SYNC_FIRST) { |
| 507 LoadContinueUrl(); | 519 LoadContinueUrl(); |
| 508 } | 520 } |
| 509 | 521 |
| 510 delete this; | 522 delete this; |
| 511 } | 523 } |
| 512 | 524 |
| 513 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( | 525 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
| 514 const base::string16& custom_message) { | 526 const base::string16& custom_message) { |
| 515 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 527 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); |
| 516 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 528 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
| 517 DisplayLoginResult(browser_, custom_message); | 529 DisplayLoginResult(browser_, custom_message); |
| 518 } | 530 } |
| 519 | 531 |
| 532 void OneClickSigninSyncStarter::DisplayModalSyncConfirmationWindow() { |
| 533 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); |
| 534 browser_->window()->ShowModalSyncConfirmationWindow(); |
| 535 } |
| 536 |
| 520 // static | 537 // static |
| 521 Browser* OneClickSigninSyncStarter::EnsureBrowser( | 538 Browser* OneClickSigninSyncStarter::EnsureBrowser( |
| 522 Browser* browser, | 539 Browser* browser, |
| 523 Profile* profile, | 540 Profile* profile, |
| 524 chrome::HostDesktopType desktop_type) { | 541 chrome::HostDesktopType desktop_type) { |
| 525 if (!browser) { | 542 if (!browser) { |
| 526 // The user just created a new profile or has closed the browser that | 543 // The user just created a new profile or has closed the browser that |
| 527 // we used previously. Grab the most recently active browser or else | 544 // we used previously. Grab the most recently active browser or else |
| 528 // create a new one. | 545 // create a new one. |
| 529 browser = chrome::FindLastActiveWithProfile(profile, desktop_type); | 546 browser = chrome::FindLastActiveWithProfile(profile, desktop_type); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 false /* user_gesture */); | 653 false /* user_gesture */); |
| 637 } | 654 } |
| 638 | 655 |
| 639 void OneClickSigninSyncStarter::LoadContinueUrl() { | 656 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 640 web_contents()->GetController().LoadURL( | 657 web_contents()->GetController().LoadURL( |
| 641 continue_url_, | 658 continue_url_, |
| 642 content::Referrer(), | 659 content::Referrer(), |
| 643 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 660 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 644 std::string()); | 661 std::string()); |
| 645 } | 662 } |
| OLD | NEW |