| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/signin/force_signin_manager.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 11 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/user_manager.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 #include "components/prefs/pref_service.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 void LockProfile(const base::FilePath& profile_path) { |
| 21 ProfileAttributesEntry* entry; |
| 22 bool has_entry = g_browser_process->profile_manager() |
| 23 ->GetProfileAttributesStorage() |
| 24 .GetProfileAttributesWithPath(profile_path, &entry); |
| 25 DCHECK(has_entry); |
| 26 entry->SetIsSigninRequired(true); |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 ForceSigninManager::ForceSigninManager( |
| 32 Profile* profile, |
| 33 SigninClient* client, |
| 34 ProfileOAuth2TokenService* token_service, |
| 35 AccountTrackerService* account_tracker_service, |
| 36 GaiaCookieManagerService* cookie_manager_service) |
| 37 : SigninManager(client, |
| 38 token_service, |
| 39 account_tracker_service, |
| 40 cookie_manager_service), |
| 41 profile_(profile) {} |
| 42 |
| 43 ForceSigninManager::~ForceSigninManager() {} |
| 44 |
| 45 void ForceSigninManager::SignOut( |
| 46 signin_metrics::ProfileSignout signout_source_metric, |
| 47 signin_metrics::SignoutDelete signout_delete_metric) { |
| 48 if (profile_->IsSystemProfile() || profile_->IsGuestSession()) { |
| 49 SigninManager::SignOut(signout_source_metric, signout_delete_metric); |
| 50 } else { |
| 51 BrowserList::CloseAllBrowsersWithProfile( |
| 52 profile_, base::Bind(&ForceSigninManager::PostCloseBrowsers, |
| 53 base::Unretained(this), signout_source_metric, |
| 54 signout_delete_metric), |
| 55 BrowserList::CloseCallback()); |
| 56 } |
| 57 } |
| 58 |
| 59 // static |
| 60 bool ForceSigninManager::IsForceSigninEnabled() { |
| 61 PrefService* prefs = g_browser_process->local_state(); |
| 62 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin); |
| 63 } |
| 64 |
| 65 // static |
| 66 void ForceSigninManager::DisableUserManagerDisplayForNextSignOut( |
| 67 SigninManager* signin_manager) { |
| 68 if (IsForceSigninEnabled()) { |
| 69 static_cast<ForceSigninManager*>(signin_manager) |
| 70 ->SetIsUserManagerDisplayed(false); |
| 71 } |
| 72 } |
| 73 |
| 74 void ForceSigninManager::DoSignOut( |
| 75 signin_metrics::ProfileSignout signout_source_metric, |
| 76 signin_metrics::SignoutDelete signout_delete_metric, |
| 77 const base::FilePath& profile_path) { |
| 78 SigninManager::SignOut(signout_source_metric, signout_delete_metric); |
| 79 LockProfile(profile_path); |
| 80 } |
| 81 |
| 82 void ForceSigninManager::ShowUserManager(const base::FilePath& profile_path) { |
| 83 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, |
| 84 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 85 } |
| 86 |
| 87 void ForceSigninManager::PostCloseBrowsers( |
| 88 signin_metrics::ProfileSignout signout_source_metric, |
| 89 signin_metrics::SignoutDelete signout_delete_metric, |
| 90 const base::FilePath& profile_path) { |
| 91 DoSignOut(signout_source_metric, signout_delete_metric, profile_path); |
| 92 if (is_user_manager_displayed) { |
| 93 ShowUserManager(profile_path); |
| 94 } else { |
| 95 is_user_manager_displayed = true; |
| 96 } |
| 97 } |
| 98 |
| 99 void ForceSigninManager::SetIsUserManagerDisplayed(bool displayed) { |
| 100 is_user_manager_displayed = displayed; |
| 101 } |
| OLD | NEW |