Chromium Code Reviews| Index: chrome/browser/signin/force_signin_manager.cc |
| diff --git a/chrome/browser/signin/force_signin_manager.cc b/chrome/browser/signin/force_signin_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0f2fa81bc31142e9c613f301abdc1c6cfb4fc578 |
| --- /dev/null |
| +++ b/chrome/browser/signin/force_signin_manager.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/signin/force_signin_manager.h" |
| + |
| +#include "base/bind.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_attributes_entry.h" |
| +#include "chrome/browser/profiles/profile_attributes_storage.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/browser/ui/user_manager.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/prefs/pref_service.h" |
| + |
| +namespace { |
| + |
| +void LockProfile(const base::FilePath& profile_path) { |
| + ProfileAttributesEntry* entry; |
| + bool has_entry = g_browser_process->profile_manager() |
| + ->GetProfileAttributesStorage() |
| + .GetProfileAttributesWithPath(profile_path, &entry); |
| + DCHECK(has_entry); |
| + entry->SetIsSigninRequired(true); |
| +} |
| + |
| +void PostPostCloseBrowsersAborted(const base::FilePath& profile_path) {} |
| + |
| +} // namespace |
| + |
| +ForceSigninManager::ForceSigninManager( |
| + Profile* profile, |
| + SigninClient* client, |
| + ProfileOAuth2TokenService* token_service, |
| + AccountTrackerService* account_tracker_service, |
| + GaiaCookieManagerService* cookie_manager_service) |
| + : SigninManager(client, |
| + token_service, |
| + account_tracker_service, |
| + cookie_manager_service), |
| + profile_(profile) {} |
| + |
| +ForceSigninManager::~ForceSigninManager() {} |
| + |
| +void ForceSigninManager::SignOut( |
| + signin_metrics::ProfileSignout signout_source_metric, |
| + signin_metrics::SignoutDelete signout_delete_metric) { |
| + if (profile_->IsSystemProfile() || profile_->IsGuestSession()) { |
| + SigninManager::SignOut(signout_source_metric, signout_delete_metric); |
| + } else { |
| + BrowserList::CloseAllBrowsersWithProfile( |
| + profile_, base::Bind(&ForceSigninManager::PostCloseBrowsers, |
| + base::Unretained(this), signout_source_metric, |
| + signout_delete_metric), |
| + base::Bind(&PostPostCloseBrowsersAborted)); |
| + } |
|
Roger Tawa OOO till Jul 10th
2016/10/26 18:25:31
I wonder if it is better to always call BrowserLis
|
| +} |
| + |
| +// static |
| +bool ForceSigninManager::IsForceSigninEnabled() { |
| + PrefService* prefs = g_browser_process->local_state(); |
| + return prefs && prefs->GetBoolean(prefs::kForceBrowserSignin); |
| +} |
| + |
| +// static |
| +void ForceSigninManager::DisableUserManagerDisplayForNextSignOut( |
| + SigninManager* signin_manager) { |
| + if (IsForceSigninEnabled()) { |
| + static_cast<ForceSigninManager*>(signin_manager) |
| + ->SetIsUserManagerDisplayed(false); |
| + } |
|
Roger Tawa OOO till Jul 10th
2016/10/26 18:25:31
This static cast seems dangerous. How are we guar
|
| +} |
| + |
| +void ForceSigninManager::DoSignOut( |
| + signin_metrics::ProfileSignout signout_source_metric, |
| + signin_metrics::SignoutDelete signout_delete_metric, |
| + const base::FilePath& profile_path) { |
| + SigninManager::SignOut(signout_source_metric, signout_delete_metric); |
| + LockProfile(profile_path); |
| +} |
| + |
| +void ForceSigninManager::ShowUserManager(const base::FilePath& profile_path) { |
| + UserManager::Show(profile_path, profiles::USER_MANAGER_NO_TUTORIAL, |
| + profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| +} |
| + |
| +void ForceSigninManager::PostCloseBrowsers( |
| + signin_metrics::ProfileSignout signout_source_metric, |
| + signin_metrics::SignoutDelete signout_delete_metric, |
| + const base::FilePath& profile_path) { |
| + DoSignOut(signout_source_metric, signout_delete_metric, profile_path); |
| + if (is_user_manager_displayed) { |
| + ShowUserManager(profile_path); |
| + } else { |
| + is_user_manager_displayed = true; |
| + } |
| +} |
| + |
| +void ForceSigninManager::SetIsUserManagerDisplayed(bool displayed) { |
| + is_user_manager_displayed = displayed; |
| +} |