Chromium Code Reviews| 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_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" | 12 #include "chrome/browser/policy/cloud/user_policy_signin_service.h" |
| 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" | 13 #include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
| 15 #include "chrome/browser/profiles/profile_attributes_storage.h" | 16 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 16 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 17 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 17 #include "chrome/browser/profiles/profile_io_data.h" | 18 #include "chrome/browser/profiles/profile_io_data.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/profiles/profile_window.h" | 20 #include "chrome/browser/profiles/profile_window.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/signin/signin_tracker_factory.h" | 22 #include "chrome/browser/signin/signin_tracker_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 // 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 |
| 135 // syncing until the user has finished any configuration. | 136 // syncing until the user has finished any configuration. |
| 136 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 137 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
| 137 if (profile_sync_service) | 138 if (profile_sync_service) |
| 138 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle(); | 139 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle(); |
| 139 | 140 |
| 140 // Make sure the syncing is requested, otherwise the SigninManager | 141 // Make sure the syncing is requested, otherwise the SigninManager |
| 141 // will not be able to complete successfully. | 142 // will not be able to complete successfully. |
| 142 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); | 143 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); |
| 143 sync_prefs.SetSyncRequested(true); | 144 sync_prefs.SetSyncRequested(true); |
| 145 skip_sync_confirm_ = false; | |
| 144 } | 146 } |
| 145 | 147 |
| 146 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { | 148 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { |
| 147 DCHECK(!oauth_token.empty()); | 149 DCHECK(!oauth_token.empty()); |
| 148 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 150 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 149 // If this is a new signin (no account authenticated yet) try loading | 151 // If this is a new signin (no account authenticated yet) try loading |
| 150 // policy for this user now, before any signed in services are initialized. | 152 // policy for this user now, before any signed in services are initialized. |
| 151 if (!signin->IsAuthenticated()) { | 153 if (!signin->IsAuthenticated()) { |
| 152 policy::UserPolicySigninService* policy_service = | 154 policy::UserPolicySigninService* policy_service = |
| 153 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); | 155 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 DCHECK(!new_signin_manager->IsAuthenticated()); | 305 DCHECK(!new_signin_manager->IsAuthenticated()); |
| 304 DCHECK(!dm_token_.empty()); | 306 DCHECK(!dm_token_.empty()); |
| 305 DCHECK(!client_id_.empty()); | 307 DCHECK(!client_id_.empty()); |
| 306 | 308 |
| 307 // Copy credentials from the old profile to the just-created profile, | 309 // Copy credentials from the old profile to the just-created profile, |
| 308 // and switch over to tracking that profile. | 310 // and switch over to tracking that profile. |
| 309 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); | 311 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); |
| 310 FinishProfileSyncServiceSetup(); | 312 FinishProfileSyncServiceSetup(); |
| 311 Initialize(new_profile, nullptr); | 313 Initialize(new_profile, nullptr); |
| 312 DCHECK_EQ(profile_, new_profile); | 314 DCHECK_EQ(profile_, new_profile); |
| 315 skip_sync_confirm_ = true; | |
| 313 | 316 |
| 314 // We've transferred our credentials to the new profile - notify that | 317 // We've transferred our credentials to the new profile - notify that |
| 315 // the signin for the original profile was cancelled (must do this after | 318 // the signin for the original profile was cancelled (must do this after |
| 316 // we have called Initialize() with the new profile, as otherwise this | 319 // we have called Initialize() with the new profile, as otherwise this |
| 317 // object will get freed when the signin on the old profile is cancelled. | 320 // object will get freed when the signin on the old profile is cancelled. |
| 318 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS, | 321 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS, |
| 319 signin_metrics::SignoutDelete::IGNORE_METRIC); | 322 signin_metrics::SignoutDelete::IGNORE_METRIC); |
| 320 | 323 |
| 321 // Load policy for the just-created profile - once policy has finished | 324 // Load policy for the just-created profile - once policy has finished |
| 322 // loading the signin process will complete. | 325 // loading the signin process will complete. |
| 323 LoadPolicyWithCachedCredentials(); | 326 LoadPolicyWithCachedCredentials(); |
| 324 | 327 |
| 328 // Unlock the new profile. | |
| 329 ProfileAttributesEntry* entry; | |
| 330 bool has_entry = | |
| 331 g_browser_process->profile_manager() | |
| 332 ->GetProfileAttributesStorage() | |
| 333 .GetProfileAttributesWithPath(new_profile->GetPath(), &entry); | |
| 334 DCHECK(has_entry); | |
| 335 entry->SetIsSigninRequired(false); | |
|
Roger Tawa OOO till Jul 10th
2016/11/02 13:20:39
Could we try to reuse the LockProfile() method you
zmin
2016/11/02 20:30:22
In the next CL(coming soon). The way of lock/unloc
| |
| 336 | |
| 325 // Open the profile's first window, after all initialization. | 337 // Open the profile's first window, after all initialization. |
| 326 profiles::FindOrCreateNewWindowForProfile( | 338 profiles::FindOrCreateNewWindowForProfile( |
| 327 new_profile, | 339 new_profile, |
| 328 chrome::startup::IS_PROCESS_STARTUP, | 340 chrome::startup::IS_PROCESS_STARTUP, |
| 329 chrome::startup::IS_FIRST_RUN, | 341 chrome::startup::IS_FIRST_RUN, |
| 330 false); | 342 false); |
| 331 break; | 343 break; |
| 332 } | 344 } |
| 333 case Profile::CREATE_STATUS_REMOTE_FAIL: | 345 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 334 case Profile::CREATE_STATUS_CANCELED: | 346 case Profile::CREATE_STATUS_CANCELED: |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 void OneClickSigninSyncStarter::AccountAddedToCookie( | 471 void OneClickSigninSyncStarter::AccountAddedToCookie( |
| 460 const GoogleServiceAuthError& error) { | 472 const GoogleServiceAuthError& error) { |
| 461 if (first_account_added_to_cookie_) | 473 if (first_account_added_to_cookie_) |
| 462 return; | 474 return; |
| 463 | 475 |
| 464 first_account_added_to_cookie_ = true; | 476 first_account_added_to_cookie_ = true; |
| 465 | 477 |
| 466 // Regardless of whether the account was successfully added or not, | 478 // Regardless of whether the account was successfully added or not, |
| 467 // continue with sync starting. | 479 // continue with sync starting. |
| 468 | 480 |
| 481 // TODO(zmin): Remove this hack once the https://crbug.com/657924 fixed. | |
| 482 // Skip the Sync confirmation dialog if user choose to create a new profile | |
| 483 // for the corp signin. This is because the dialog doesn't work properly | |
| 484 // after the corp signin. | |
| 485 if (skip_sync_confirm_) { | |
| 486 OnSyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN); | |
| 487 return; | |
| 488 } | |
| 489 | |
| 469 if (switches::UsePasswordSeparatedSigninFlow()) { | 490 if (switches::UsePasswordSeparatedSigninFlow()) { |
| 470 // Under the new signin flow, the sync confirmation dialog should always be | 491 // Under the new signin flow, the sync confirmation dialog should always be |
| 471 // shown regardless of |start_mode_|. |sync_setup_completed_callback_| will | 492 // shown regardless of |start_mode_|. |sync_setup_completed_callback_| will |
| 472 // be run after the modal is closed. | 493 // be run after the modal is closed. |
| 473 DisplayModalSyncConfirmationWindow(); | 494 DisplayModalSyncConfirmationWindow(); |
| 474 return; | 495 return; |
| 475 } | 496 } |
| 476 | 497 |
| 477 if (!sync_setup_completed_callback_.is_null()) | 498 if (!sync_setup_completed_callback_.is_null()) |
| 478 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); | 499 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 false /* user_gesture */); | 663 false /* user_gesture */); |
| 643 } | 664 } |
| 644 | 665 |
| 645 void OneClickSigninSyncStarter::LoadContinueUrl() { | 666 void OneClickSigninSyncStarter::LoadContinueUrl() { |
| 646 web_contents()->GetController().LoadURL( | 667 web_contents()->GetController().LoadURL( |
| 647 continue_url_, | 668 continue_url_, |
| 648 content::Referrer(), | 669 content::Referrer(), |
| 649 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 670 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 650 std::string()); | 671 std::string()); |
| 651 } | 672 } |
| OLD | NEW |