This source file includes following definitions.
- weak_pointer_factory_
- Initialize
- IsInitialized
- IsSigninAllowed
- GetAuthenticatedUsername
- GetAuthenticatedAccountId
- SetAuthenticatedUsername
- clear_authenticated_username
- AuthInProgress
- Shutdown
- AddObserver
- RemoveObserver
- AddSigninDiagnosticsObserver
- RemoveSigninDiagnosticsObserver
- NotifyDiagnosticsObservers
- NotifyDiagnosticsObservers
#include "components/signin/core/browser/signin_manager_base.h"
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/memory/ref_counted.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/signin/core/browser/signin_client.h"
#include "components/signin/core/common/signin_pref_names.h"
#include "components/signin/core/common/signin_switches.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
using namespace signin_internals_util;
SigninManagerBase::SigninManagerBase(SigninClient* client)
: client_(client), initialized_(false), weak_pointer_factory_(this) {}
SigninManagerBase::~SigninManagerBase() {}
void SigninManagerBase::Initialize(PrefService* local_state) {
DCHECK(!IsInitialized());
initialized_ = true;
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kClearTokenService))
client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
std::string user =
client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
if (!user.empty())
SetAuthenticatedUsername(user);
}
bool SigninManagerBase::IsInitialized() const { return initialized_; }
bool SigninManagerBase::IsSigninAllowed() const {
return client_->GetPrefs()->GetBoolean(prefs::kSigninAllowed);
}
const std::string& SigninManagerBase::GetAuthenticatedUsername() const {
return authenticated_username_;
}
const std::string& SigninManagerBase::GetAuthenticatedAccountId() const {
return GetAuthenticatedUsername();
}
void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) {
if (!authenticated_username_.empty()) {
DLOG_IF(ERROR, !gaia::AreEmailsSame(username, authenticated_username_))
<< "Tried to change the authenticated username to something different: "
<< "Current: " << authenticated_username_ << ", New: " << username;
#if defined(OS_IOS)
if (!gaia::AreEmailsSame(username, authenticated_username_) ||
username == authenticated_username_) {
return;
}
#else
return;
#endif
}
std::string pref_username =
client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
DCHECK(pref_username.empty() || gaia::AreEmailsSame(username, pref_username))
<< "username: " << username << "; pref_username: " << pref_username;
authenticated_username_ = username;
client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username);
NotifyDiagnosticsObservers(USERNAME, username);
client_->GetPrefs()->SetString(prefs::kGoogleServicesLastUsername, username);
}
void SigninManagerBase::clear_authenticated_username() {
authenticated_username_.clear();
}
bool SigninManagerBase::AuthInProgress() const {
return false;
}
void SigninManagerBase::Shutdown() {}
void SigninManagerBase::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void SigninManagerBase::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
void SigninManagerBase::AddSigninDiagnosticsObserver(
SigninDiagnosticsObserver* observer) {
signin_diagnostics_observers_.AddObserver(observer);
}
void SigninManagerBase::RemoveSigninDiagnosticsObserver(
SigninDiagnosticsObserver* observer) {
signin_diagnostics_observers_.RemoveObserver(observer);
}
void SigninManagerBase::NotifyDiagnosticsObservers(
const UntimedSigninStatusField& field,
const std::string& value) {
FOR_EACH_OBSERVER(SigninDiagnosticsObserver,
signin_diagnostics_observers_,
NotifySigninValueChanged(field, value));
}
void SigninManagerBase::NotifyDiagnosticsObservers(
const TimedSigninStatusField& field,
const std::string& value) {
FOR_EACH_OBSERVER(SigninDiagnosticsObserver,
signin_diagnostics_observers_,
NotifySigninValueChanged(field, value));
}