Chromium Code Reviews| 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 void PostPostCloseBrowsersAborted(const base::FilePath& profile_path) {} | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 ForceSigninManager::ForceSigninManager( | |
| 34 Profile* profile, | |
| 35 SigninClient* client, | |
| 36 ProfileOAuth2TokenService* token_service, | |
| 37 AccountTrackerService* account_tracker_service, | |
| 38 GaiaCookieManagerService* cookie_manager_service) | |
| 39 : SigninManager(client, | |
| 40 token_service, | |
| 41 account_tracker_service, | |
| 42 cookie_manager_service), | |
| 43 profile_(profile) {} | |
| 44 | |
| 45 ForceSigninManager::~ForceSigninManager() {} | |
| 46 | |
| 47 void ForceSigninManager::SignOut( | |
| 48 signin_metrics::ProfileSignout signout_source_metric, | |
| 49 signin_metrics::SignoutDelete signout_delete_metric) { | |
| 50 if (profile_->IsSystemProfile() || profile_->IsGuestSession()) { | |
| 51 SigninManager::SignOut(signout_source_metric, signout_delete_metric); | |
| 52 } else { | |
| 53 BrowserList::CloseAllBrowsersWithProfile( | |
| 54 profile_, base::Bind(&ForceSigninManager::PostCloseBrowsers, | |
| 55 base::Unretained(this), signout_source_metric, | |
| 56 signout_delete_metric), | |
| 57 base::Bind(&PostPostCloseBrowsersAborted)); | |
| 58 } | |
|
Roger Tawa OOO till Jul 10th
2016/10/26 18:25:31
I wonder if it is better to always call BrowserLis
| |
| 59 } | |
| 60 | |
| 61 // static | |
| 62 bool ForceSigninManager::IsForceSigninEnabled() { | |
| 63 PrefService* prefs = g_browser_process->local_state(); | |
| 64 return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin); | |
| 65 } | |
| 66 | |
| 67 // static | |
| 68 void ForceSigninManager::DisableUserManagerDisplayForNextSignOut( | |
| 69 SigninManager* signin_manager) { | |
| 70 if (IsForceSigninEnabled()) { | |
| 71 static_cast<ForceSigninManager*>(signin_manager) | |
| 72 ->SetIsUserManagerDisplayed(false); | |
| 73 } | |
|
Roger Tawa OOO till Jul 10th
2016/10/26 18:25:31
This static cast seems dangerous. How are we guar
| |
| 74 } | |
| 75 | |
| 76 void ForceSigninManager::DoSignOut( | |
| 77 signin_metrics::ProfileSignout signout_source_metric, | |
| 78 signin_metrics::SignoutDelete signout_delete_metric, | |
| 79 const base::FilePath& profile_path) { | |
| 80 SigninManager::SignOut(signout_source_metric, signout_delete_metric); | |
| 81 LockProfile(profile_path); | |
| 82 } | |
| 83 | |
| 84 void ForceSigninManager::ShowUserManager(const base::FilePath& profile_path) { | |
| 85 UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, | |
| 86 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | |
| 87 } | |
| 88 | |
| 89 void ForceSigninManager::PostCloseBrowsers( | |
| 90 signin_metrics::ProfileSignout signout_source_metric, | |
| 91 signin_metrics::SignoutDelete signout_delete_metric, | |
| 92 const base::FilePath& profile_path) { | |
| 93 DoSignOut(signout_source_metric, signout_delete_metric, profile_path); | |
| 94 if (is_user_manager_displayed) { | |
| 95 ShowUserManager(profile_path); | |
| 96 } else { | |
| 97 is_user_manager_displayed = true; | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 void ForceSigninManager::SetIsUserManagerDisplayed(bool displayed) { | |
| 102 is_user_manager_displayed = displayed; | |
| 103 } | |
| OLD | NEW |