| 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..7b6ac74caf3308d92bdb90a849732435d321da99
|
| --- /dev/null
|
| +++ b/chrome/browser/signin/force_signin_manager.cc
|
| @@ -0,0 +1,101 @@
|
| +// 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);
|
| +}
|
| +
|
| +} // 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),
|
| + BrowserList::CloseCallback());
|
| + }
|
| +}
|
| +
|
| +// 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);
|
| + }
|
| +}
|
| +
|
| +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;
|
| +}
|
|
|