Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: chrome/browser/ui/sync/one_click_signin_sync_starter.cc

Issue 2442843002: Override SigninManager::SignOut if force-signin is enabled. (Closed)
Patch Set: tommycli's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
21 #include "chrome/browser/signin/force_signin_manager.h"
20 #include "chrome/browser/signin/signin_manager_factory.h" 22 #include "chrome/browser/signin/signin_manager_factory.h"
21 #include "chrome/browser/signin/signin_tracker_factory.h" 23 #include "chrome/browser/signin/signin_tracker_factory.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
23 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
25 #include "chrome/browser/ui/browser_list.h" 27 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 28 #include "chrome/browser/ui/browser_tabstrip.h"
27 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/chrome_pages.h" 30 #include "chrome/browser/ui/chrome_pages.h"
29 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h" 31 #include "chrome/browser/ui/sync/one_click_signin_sync_observer.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Let the sync service know that setup is in progress so it doesn't start 136 // Let the sync service know that setup is in progress so it doesn't start
135 // syncing until the user has finished any configuration. 137 // syncing until the user has finished any configuration.
136 ProfileSyncService* profile_sync_service = GetProfileSyncService(); 138 ProfileSyncService* profile_sync_service = GetProfileSyncService();
137 if (profile_sync_service) 139 if (profile_sync_service)
138 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle(); 140 sync_blocker_ = profile_sync_service->GetSetupInProgressHandle();
139 141
140 // Make sure the syncing is requested, otherwise the SigninManager 142 // Make sure the syncing is requested, otherwise the SigninManager
141 // will not be able to complete successfully. 143 // will not be able to complete successfully.
142 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); 144 syncer::SyncPrefs sync_prefs(profile_->GetPrefs());
143 sync_prefs.SetSyncRequested(true); 145 sync_prefs.SetSyncRequested(true);
146 skip_sync_confirm_ = false;
144 } 147 }
145 148
146 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) { 149 void OneClickSigninSyncStarter::ConfirmSignin(const std::string& oauth_token) {
147 DCHECK(!oauth_token.empty()); 150 DCHECK(!oauth_token.empty());
148 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); 151 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_);
149 // If this is a new signin (no account authenticated yet) try loading 152 // 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. 153 // policy for this user now, before any signed in services are initialized.
151 if (!signin->IsAuthenticated()) { 154 if (!signin->IsAuthenticated()) {
152 policy::UserPolicySigninService* policy_service = 155 policy::UserPolicySigninService* policy_service =
153 policy::UserPolicySigninServiceFactory::GetForProfile(profile_); 156 policy::UserPolicySigninServiceFactory::GetForProfile(profile_);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 DCHECK(!new_signin_manager->IsAuthenticated()); 306 DCHECK(!new_signin_manager->IsAuthenticated());
304 DCHECK(!dm_token_.empty()); 307 DCHECK(!dm_token_.empty());
305 DCHECK(!client_id_.empty()); 308 DCHECK(!client_id_.empty());
306 309
307 // Copy credentials from the old profile to the just-created profile, 310 // Copy credentials from the old profile to the just-created profile,
308 // and switch over to tracking that profile. 311 // and switch over to tracking that profile.
309 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); 312 new_signin_manager->CopyCredentialsFrom(*old_signin_manager);
310 FinishProfileSyncServiceSetup(); 313 FinishProfileSyncServiceSetup();
311 Initialize(new_profile, nullptr); 314 Initialize(new_profile, nullptr);
312 DCHECK_EQ(profile_, new_profile); 315 DCHECK_EQ(profile_, new_profile);
316 skip_sync_confirm_ = true;
313 317
318 // When force signin enabled, all browser window will be closed and
319 // UserManager will be shown during signout. However, the UserManager
320 // doesn't need to be shown here because we will create a new window for
321 // the new profile soon.
322 ForceSigninManager::DisableUserManagerDisplayForNextSignOut(
323 old_signin_manager);
Roger Tawa OOO till Jul 10th 2016/10/26 18:25:32 Instead of calling this here, seems like it would
314 // We've transferred our credentials to the new profile - notify that 324 // We've transferred our credentials to the new profile - notify that
315 // the signin for the original profile was cancelled (must do this after 325 // the signin for the original profile was cancelled (must do this after
316 // we have called Initialize() with the new profile, as otherwise this 326 // 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. 327 // object will get freed when the signin on the old profile is cancelled.
318 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS, 328 old_signin_manager->SignOut(signin_metrics::TRANSFER_CREDENTIALS,
319 signin_metrics::SignoutDelete::IGNORE_METRIC); 329 signin_metrics::SignoutDelete::IGNORE_METRIC);
320 330
321 // Load policy for the just-created profile - once policy has finished 331 // Load policy for the just-created profile - once policy has finished
322 // loading the signin process will complete. 332 // loading the signin process will complete.
323 LoadPolicyWithCachedCredentials(); 333 LoadPolicyWithCachedCredentials();
324 334
335 // Unlock the new profile.
336 ProfileAttributesEntry* entry;
337 bool has_entry =
338 g_browser_process->profile_manager()
339 ->GetProfileAttributesStorage()
340 .GetProfileAttributesWithPath(new_profile->GetPath(), &entry);
341 DCHECK(has_entry);
342 entry->SetIsSigninRequired(false);
343
325 // Open the profile's first window, after all initialization. 344 // Open the profile's first window, after all initialization.
326 profiles::FindOrCreateNewWindowForProfile( 345 profiles::FindOrCreateNewWindowForProfile(
327 new_profile, 346 new_profile,
328 chrome::startup::IS_PROCESS_STARTUP, 347 chrome::startup::IS_PROCESS_STARTUP,
329 chrome::startup::IS_FIRST_RUN, 348 chrome::startup::IS_FIRST_RUN,
330 false); 349 false);
331 break; 350 break;
332 } 351 }
333 case Profile::CREATE_STATUS_REMOTE_FAIL: 352 case Profile::CREATE_STATUS_REMOTE_FAIL:
334 case Profile::CREATE_STATUS_CANCELED: 353 case Profile::CREATE_STATUS_CANCELED:
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 void OneClickSigninSyncStarter::AccountAddedToCookie( 478 void OneClickSigninSyncStarter::AccountAddedToCookie(
460 const GoogleServiceAuthError& error) { 479 const GoogleServiceAuthError& error) {
461 if (first_account_added_to_cookie_) 480 if (first_account_added_to_cookie_)
462 return; 481 return;
463 482
464 first_account_added_to_cookie_ = true; 483 first_account_added_to_cookie_ = true;
465 484
466 // Regardless of whether the account was successfully added or not, 485 // Regardless of whether the account was successfully added or not,
467 // continue with sync starting. 486 // continue with sync starting.
468 487
488 // TODO(zmin): Remove this hack once the https://crbug.com/657924 fixed.
489 // Skip the Sync confirmation dialog if user choose to create a new profile
490 // for the corp signin. This is because the dialog doesn't work properly
491 // after the corp signin.
492 if (skip_sync_confirm_) {
493 OnSyncConfirmationUIClosed(LoginUIService::ABORT_SIGNIN);
494 return;
495 }
496
469 if (switches::UsePasswordSeparatedSigninFlow()) { 497 if (switches::UsePasswordSeparatedSigninFlow()) {
470 // Under the new signin flow, the sync confirmation dialog should always be 498 // Under the new signin flow, the sync confirmation dialog should always be
471 // shown regardless of |start_mode_|. |sync_setup_completed_callback_| will 499 // shown regardless of |start_mode_|. |sync_setup_completed_callback_| will
472 // be run after the modal is closed. 500 // be run after the modal is closed.
473 DisplayModalSyncConfirmationWindow(); 501 DisplayModalSyncConfirmationWindow();
474 return; 502 return;
475 } 503 }
476 504
477 if (!sync_setup_completed_callback_.is_null()) 505 if (!sync_setup_completed_callback_.is_null())
478 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS); 506 sync_setup_completed_callback_.Run(SYNC_SETUP_SUCCESS);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 false /* user_gesture */); 670 false /* user_gesture */);
643 } 671 }
644 672
645 void OneClickSigninSyncStarter::LoadContinueUrl() { 673 void OneClickSigninSyncStarter::LoadContinueUrl() {
646 web_contents()->GetController().LoadURL( 674 web_contents()->GetController().LoadURL(
647 continue_url_, 675 continue_url_,
648 content::Referrer(), 676 content::Referrer(),
649 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 677 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
650 std::string()); 678 std::string());
651 } 679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698