| 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); | 180 SetUserChoiceHistogram(SIGNIN_CHOICE_CANCEL); |
| 181 if (sync_starter_ != NULL) | 181 if (sync_starter_ != NULL) |
| 182 sync_starter_->CancelSigninAndDelete(); | 182 sync_starter_->CancelSigninAndDelete(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { | 185 void OneClickSigninSyncStarter::SigninDialogDelegate::OnContinueSignin() { |
| 186 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); | 186 SetUserChoiceHistogram(SIGNIN_CHOICE_CONTINUE); |
| 187 | 187 |
| 188 if (sync_starter_ != NULL) { | 188 if (sync_starter_ != NULL) { |
| 189 // If the user signs in from the new avatar bubble, the enterprise | 189 // If the user signs in from the new avatar bubble, the enterprise |
| 190 // confirmation dialog would dismiss the avatar bubble, thus it won't show | 190 // confirmation dialog would dismiss the avatar bubble, thus we need to |
| 191 // any confirmation upon sign in completes. This cofirmation dialog already | 191 // manually re-show the avatar bubble to confirm sync settings. |
| 192 // mentions that user data would be synced, thus we just start sync | |
| 193 // immediately. | |
| 194 | |
| 195 // TODO(guohui): add a sync settings link to allow user to configure sync | |
| 196 // settings before sync starts. | |
| 197 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST) | 192 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST) |
| 198 sync_starter_->SetStartSyncMode(SYNC_WITH_DEFAULT_SETTINGS); | 193 sync_starter_->SetConfirmationRequired(CONFIRM_AFTER_SIGNIN); |
| 199 sync_starter_->LoadPolicyWithCachedCredentials(); | 194 sync_starter_->LoadPolicyWithCachedCredentials(); |
| 200 } | 195 } |
| 201 } | 196 } |
| 202 | 197 |
| 203 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { | 198 void OneClickSigninSyncStarter::SigninDialogDelegate::OnSigninWithNewProfile() { |
| 204 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); | 199 SetUserChoiceHistogram(SIGNIN_CHOICE_NEW_PROFILE); |
| 205 | 200 |
| 206 if (sync_starter_ != NULL) { | 201 if (sync_starter_ != NULL) { |
| 207 // TODO(guohui): add a sync settings link to allow user to configure sync | |
| 208 // settings before sync starts. | |
| 209 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST) | 202 if (sync_starter_->GetStartSyncMode() == CONFIRM_SYNC_SETTINGS_FIRST) |
| 210 sync_starter_->SetStartSyncMode(SYNC_WITH_DEFAULT_SETTINGS); | 203 sync_starter_->SetConfirmationRequired(CONFIRM_AFTER_SIGNIN); |
| 211 sync_starter_->CreateNewSignedInProfile(); | 204 sync_starter_->CreateNewSignedInProfile(); |
| 212 } | 205 } |
| 213 } | 206 } |
| 214 | 207 |
| 215 void OneClickSigninSyncStarter::SetStartSyncMode(StartSyncMode start_mode) { | 208 void OneClickSigninSyncStarter::SetConfirmationRequired( |
| 216 start_mode_ = start_mode; | 209 ConfirmationRequired confirmation_required) { |
| 210 confirmation_required_ = confirmation_required; |
| 217 } | 211 } |
| 218 | 212 |
| 219 OneClickSigninSyncStarter::StartSyncMode | 213 OneClickSigninSyncStarter::StartSyncMode |
| 220 OneClickSigninSyncStarter::GetStartSyncMode() { | 214 OneClickSigninSyncStarter::GetStartSyncMode() { |
| 221 return start_mode_; | 215 return start_mode_; |
| 222 } | 216 } |
| 223 | 217 |
| 224 void OneClickSigninSyncStarter::OnRegisteredForPolicy( | 218 void OneClickSigninSyncStarter::OnRegisteredForPolicy( |
| 225 const std::string& dm_token, const std::string& client_id) { | 219 const std::string& dm_token, const std::string& client_id) { |
| 226 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 220 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 // Sync is disabled by policy. | 469 // Sync is disabled by policy. |
| 476 message = l10n_util::GetStringUTF16( | 470 message = l10n_util::GetStringUTF16( |
| 477 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); | 471 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
| 478 } | 472 } |
| 479 DisplayFinalConfirmationBubble(message); | 473 DisplayFinalConfirmationBubble(message); |
| 480 } | 474 } |
| 481 break; | 475 break; |
| 482 } | 476 } |
| 483 case CONFIRM_SYNC_SETTINGS_FIRST: | 477 case CONFIRM_SYNC_SETTINGS_FIRST: |
| 484 // Blocks sync until the sync settings confirmation UI is closed. | 478 // Blocks sync until the sync settings confirmation UI is closed. |
| 479 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) |
| 480 DisplayFinalConfirmationBubble(base::string16()); |
| 485 return; | 481 return; |
| 486 case CONFIGURE_SYNC_FIRST: | 482 case CONFIGURE_SYNC_FIRST: |
| 487 ShowSettingsPage(true); // Show sync config UI. | 483 ShowSettingsPage(true); // Show sync config UI. |
| 488 break; | 484 break; |
| 489 case SHOW_SETTINGS_WITHOUT_CONFIGURE: | 485 case SHOW_SETTINGS_WITHOUT_CONFIGURE: |
| 490 ShowSettingsPage(false); // Don't show sync config UI. | 486 ShowSettingsPage(false); // Don't show sync config UI. |
| 491 break; | 487 break; |
| 492 case UNDO_SYNC: | 488 case UNDO_SYNC: |
| 493 NOTREACHED(); | 489 NOTREACHED(); |
| 494 } | 490 } |
| 495 | 491 |
| 496 // Navigate to the |continue_url_| if one is set, unless the user first needs | 492 // Navigate to the |continue_url_| if one is set, unless the user first needs |
| 497 // to configure Sync. | 493 // to configure Sync. |
| 498 if (web_contents() && !continue_url_.is_empty() && | 494 if (web_contents() && !continue_url_.is_empty() && |
| 499 start_mode_ != CONFIGURE_SYNC_FIRST) { | 495 start_mode_ != CONFIGURE_SYNC_FIRST) { |
| 500 LoadContinueUrl(); | 496 LoadContinueUrl(); |
| 501 } | 497 } |
| 502 | 498 |
| 503 delete this; | 499 delete this; |
| 504 } | 500 } |
| 505 | 501 |
| 506 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( | 502 void OneClickSigninSyncStarter::DisplayFinalConfirmationBubble( |
| 507 const base::string16& custom_message) { | 503 const base::string16& custom_message) { |
| 508 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); | 504 browser_ = EnsureBrowser(browser_, profile_, desktop_type_); |
| 505 // Show the success confirmation message in the new avatar menu if it is |
| 506 // enabled. |
| 507 // TODO(guohui): needs to handle custom messages. |
| 508 if (custom_message.empty() && switches::IsNewAvatarMenu()) { |
| 509 browser_->window()->ShowAvatarBubbleFromAvatarButton( |
| 510 BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN, |
| 511 signin::ManageAccountsParams()); |
| 512 return; |
| 513 } |
| 514 |
| 509 browser_->window()->ShowOneClickSigninBubble( | 515 browser_->window()->ShowOneClickSigninBubble( |
| 510 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, | 516 BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE, |
| 511 base::string16(), // No email required - this is not a SAML confirmation. | 517 base::string16(), // No email required - this is not a SAML confirmation. |
| 512 custom_message, | 518 custom_message, |
| 513 // Callback is ignored. | 519 // Callback is ignored. |
| 514 BrowserWindow::StartSyncCallback()); | 520 BrowserWindow::StartSyncCallback()); |
| 515 } | 521 } |
| 516 | 522 |
| 517 // static | 523 // static |
| 518 Browser* OneClickSigninSyncStarter::EnsureBrowser( | 524 Browser* OneClickSigninSyncStarter::EnsureBrowser( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 false /* user_gesture */); | 638 false /* user_gesture */); |
| 633 } | 639 } |
| 634 | 640 |
| 635 void OneClickSigninSyncStarter::LoadContinueUrl() { | 641 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 636 web_contents()->GetController().LoadURL( | 642 web_contents()->GetController().LoadURL( |
| 637 continue_url_, | 643 continue_url_, |
| 638 content::Referrer(), | 644 content::Referrer(), |
| 639 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 645 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 640 std::string()); | 646 std::string()); |
| 641 } | 647 } |
| OLD | NEW |