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

Unified Diff: chrome/browser/signin/signin_manager_base.cc

Issue 14630003: signin: move SigninManagerBase::Signout to SigninManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apocalypse Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/signin/signin_manager_base.h ('k') | chrome/browser/signin/signin_manager_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/signin/signin_manager_base.cc
diff --git a/chrome/browser/signin/signin_manager_base.cc b/chrome/browser/signin/signin_manager_base.cc
index 980a1fd4cc09d4cbed8d42d62083d57f0a10b67a..8326e963023ab5b6110b1bd95ff19236d450bc3a 100644
--- a/chrome/browser/signin/signin_manager_base.cc
+++ b/chrome/browser/signin/signin_manager_base.cc
@@ -14,9 +14,6 @@
#include "base/strings/string_split.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile_info_cache.h"
-#include "chrome/browser/profiles/profile_io_data.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/about_signin_internals.h"
#include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/browser/signin/signin_global_error.h"
@@ -32,45 +29,11 @@
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
-#include "third_party/icu/public/i18n/unicode/regex.h"
using namespace signin_internals_util;
using content::BrowserThread;
-// static
-bool SigninManagerBase::IsAllowedUsername(const std::string& username,
- const std::string& policy) {
- if (policy.empty())
- return true;
-
- // Patterns like "*@foo.com" are not accepted by our regex engine (since they
- // are not valid regular expressions - they should instead be ".*@foo.com").
- // For convenience, detect these patterns and insert a "." character at the
- // front.
- string16 pattern = UTF8ToUTF16(policy);
- if (pattern[0] == L'*')
- pattern.insert(pattern.begin(), L'.');
-
- // See if the username matches the policy-provided pattern.
- UErrorCode status = U_ZERO_ERROR;
- const icu::UnicodeString icu_pattern(pattern.data(), pattern.length());
- icu::RegexMatcher matcher(icu_pattern, UREGEX_CASE_INSENSITIVE, status);
- if (!U_SUCCESS(status)) {
- LOG(ERROR) << "Invalid login regex: " << pattern << ", status: " << status;
- // If an invalid pattern is provided, then prohibit *all* logins (better to
- // break signin than to quietly allow users to sign in).
- return false;
- }
- string16 username16 = UTF8ToUTF16(username);
- icu::UnicodeString icu_input(username16.data(), username16.length());
- matcher.reset(icu_input);
- status = U_ZERO_ERROR;
- UBool match = matcher.matches(status);
- DCHECK(U_SUCCESS(status));
- return !!match; // !! == convert from UBool to bool.
-}
-
SigninManagerBase::SigninManagerBase()
: profile_(NULL),
weak_pointer_factory_(this) {
@@ -89,18 +52,6 @@ void SigninManagerBase::Initialize(Profile* profile) {
signin_global_error_.reset(new SigninGlobalError(this, profile));
GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
signin_global_error_.get());
- PrefService* local_state = g_browser_process->local_state();
- // local_state can be null during unit tests.
- if (local_state) {
- local_state_pref_registrar_.Init(local_state);
- local_state_pref_registrar_.Add(
- prefs::kGoogleServicesUsernamePattern,
- base::Bind(&SigninManagerBase::OnGoogleServicesUsernamePatternChanged,
- weak_pointer_factory_.GetWeakPtr()));
- }
- signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(),
- base::Bind(&SigninManagerBase::OnSigninAllowedPrefChanged,
- base::Unretained(this)));
// If the user is clearing the token service from the command line, then
// clear their login info also (not valid to be logged in without any
@@ -115,12 +66,6 @@ void SigninManagerBase::Initialize(Profile* profile) {
SetAuthenticatedUsername(user);
InitTokenService();
-
- if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) {
- // User is signed in, but the username is invalid - the administrator must
- // have changed the policy since the last signin, so sign out the user.
- SignOut();
- }
}
void SigninManagerBase::InitTokenService() {
@@ -136,24 +81,8 @@ bool SigninManagerBase::IsInitialized() const {
return profile_ != NULL;
}
-bool SigninManagerBase::IsAllowedUsername(const std::string& username) const {
- PrefService* local_state = g_browser_process->local_state();
- if (!local_state)
- return true; // In a unit test with no local state - all names are allowed.
-
- std::string pattern = local_state->GetString(
- prefs::kGoogleServicesUsernamePattern);
- return IsAllowedUsername(username, pattern);
-}
-
bool SigninManagerBase::IsSigninAllowed() const {
- return signin_allowed_.GetValue();
-}
-
-// static
-bool SigninManagerBase::IsSigninAllowedOnIOThread(ProfileIOData* io_data) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- return io_data->signin_allowed()->GetValue();
+ return profile_->GetPrefs()->GetBoolean(prefs::kSigninAllowed);
}
const std::string& SigninManagerBase::GetAuthenticatedUsername() const {
@@ -180,29 +109,8 @@ void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) {
profile_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username);
}
-void SigninManagerBase::SignOut() {
- DCHECK(IsInitialized());
-
- if (authenticated_username_.empty() && !AuthInProgress())
- return;
-
- GoogleServiceSignoutDetails details(authenticated_username_);
+void SigninManagerBase::clear_authenticated_username() {
authenticated_username_.clear();
- profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
-
- // Erase (now) stale information from AboutSigninInternals.
- NotifyDiagnosticsObservers(USERNAME, "");
- NotifyDiagnosticsObservers(LSID, "");
- NotifyDiagnosticsObservers(
- signin_internals_util::SID, "");
-
- TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
- content::Source<Profile>(profile_),
- content::Details<const GoogleServiceSignoutDetails>(&details));
- token_service->ResetCredentialsInMemory();
- token_service->EraseTokensFromDB();
}
bool SigninManagerBase::AuthInProgress() const {
@@ -218,20 +126,6 @@ void SigninManagerBase::Shutdown() {
}
}
-void SigninManagerBase::OnGoogleServicesUsernamePatternChanged() {
- if (!authenticated_username_.empty() &&
- !IsAllowedUsername(authenticated_username_)) {
- // Signed in user is invalid according to the current policy so sign
- // the user out.
- SignOut();
- }
-}
-
-void SigninManagerBase::OnSigninAllowedPrefChanged() {
- if (!IsSigninAllowed())
- SignOut();
-}
-
void SigninManagerBase::AddSigninDiagnosticsObserver(
SigninDiagnosticsObserver* observer) {
signin_diagnostics_observers_.AddObserver(observer);
« no previous file with comments | « chrome/browser/signin/signin_manager_base.h ('k') | chrome/browser/signin/signin_manager_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698