Commit 373bf95a authored by rogerta's avatar rogerta Committed by Commit bot

Add account id/gaia id to sign-in internals page.

BUG=405038

Review URL: https://codereview.chromium.org/956363002

Cr-Commit-Position: refs/heads/master@{#320907}
parent d42cf56f
......@@ -6,6 +6,7 @@
#include "base/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
......@@ -23,9 +24,10 @@ AboutSigninInternalsFactory::AboutSigninInternalsFactory()
: BrowserContextKeyedServiceFactory(
"AboutSigninInternals",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(SigninManagerFactory::GetInstance());
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
DependsOn(AccountTrackerServiceFactory::GetInstance());
DependsOn(ChromeSigninClientFactory::GetInstance());
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
DependsOn(SigninManagerFactory::GetInstance());
}
AboutSigninInternalsFactory::~AboutSigninInternalsFactory() {}
......@@ -45,6 +47,10 @@ AboutSigninInternalsFactory* AboutSigninInternalsFactory::GetInstance() {
void AboutSigninInternalsFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* user_prefs) {
// SigninManager information for about:signin-internals.
// TODO(rogerta): leaving untimed fields here for now because legacy
// profiles still have these prefs. In three or four version from M43
// we can probably remove them.
for (int i = UNTIMED_FIELDS_BEGIN; i < UNTIMED_FIELDS_END; ++i) {
const std::string pref_path = SigninStatusFieldToString(
static_cast<UntimedSigninStatusField>(i));
......@@ -53,6 +59,7 @@ void AboutSigninInternalsFactory::RegisterProfilePrefs(
std::string(),
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
for (int i = TIMED_FIELDS_BEGIN; i < TIMED_FIELDS_END; ++i) {
const std::string value = SigninStatusFieldToString(
static_cast<TimedSigninStatusField>(i)) + ".value";
......@@ -74,6 +81,7 @@ KeyedService* AboutSigninInternalsFactory::BuildServiceInstanceFor(
Profile* profile = Profile::FromBrowserContext(context);
AboutSigninInternals* service = new AboutSigninInternals(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
AccountTrackerServiceFactory::GetForProfile(profile),
SigninManagerFactory::GetForProfile(profile));
service->Initialize(ChromeSigninClientFactory::GetForProfile(profile));
return service;
......
......@@ -694,8 +694,7 @@ void InlineLoginHandlerImpl::CompleteLogin(const base::ListValue* args) {
AboutSigninInternals* about_signin_internals =
AboutSigninInternalsFactory::GetForProfile(Profile::FromWebUI(web_ui()));
about_signin_internals->OnAuthenticationResultReceived(
"GAIA Auth Successful");
about_signin_internals->OnAuthenticationResultReceived("Successful");
content::StoragePartition* partition =
content::BrowserContext::GetStoragePartitionForSite(
......
......@@ -19,10 +19,10 @@
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/oauth2_token_service.h"
class AccountTrackerService;
class GaiaAuthFetcher;
class ProfileOAuth2TokenService;
class SigninClient;
class SigninManagerBase;
// Many values in SigninStatus are also associated with a timestamp.
// This makes it easier to keep values and their associated times together.
......@@ -34,7 +34,8 @@ class AboutSigninInternals
: public KeyedService,
public signin_internals_util::SigninDiagnosticsObserver,
public OAuth2TokenService::DiagnosticsObserver,
public GaiaAuthConsumer {
public GaiaAuthConsumer,
SigninManagerBase::Observer {
public:
class Observer {
public:
......@@ -47,6 +48,7 @@ class AboutSigninInternals
};
AboutSigninInternals(ProfileOAuth2TokenService* token_service,
AccountTrackerService* account_tracker,
SigninManagerBase* signin_manager);
~AboutSigninInternals() override;
......@@ -58,17 +60,11 @@ class AboutSigninInternals
// Pulls all signin values that have been persisted in the user prefs.
void RefreshSigninPrefs();
// SigninManager::SigninDiagnosticsObserver implementation.
void NotifySigninValueChanged(
const signin_internals_util::UntimedSigninStatusField& field,
const std::string& value) override;
void NotifySigninValueChanged(
const signin_internals_util::TimedSigninStatusField& field,
const std::string& value) override;
void Initialize(SigninClient* client);
void OnRefreshTokenReceived(std::string status);
void OnAuthenticationResultReceived(std::string status);
// KeyedService implementation.
void Shutdown() override;
......@@ -92,22 +88,6 @@ class AboutSigninInternals
// corresponding to the cookies residing on the current cookie jar.
void GetCookieAccountsAsync();
// OAuth2TokenService::DiagnosticsObserver implementations.
void OnAccessTokenRequested(
const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes) override;
void OnFetchAccessTokenComplete(const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes,
GoogleServiceAuthError error,
base::Time expiration_time) override;
void OnTokenRemoved(const std::string& account_id,
const OAuth2TokenService::ScopeSet& scopes) override;
void OnRefreshTokenReceived(std::string status);
void OnAuthenticationResultReceived(std::string status);
private:
// Encapsulates diagnostic information about tokens for different services.
struct TokenInfo {
......@@ -137,7 +117,6 @@ class AboutSigninInternals
// by SigninInternals to maintain information that needs to be shown in
// the about:signin-internals page.
struct SigninStatus {
std::vector<std::string> untimed_signin_fields;
std::vector<TimedSigninStatusValue> timed_signin_fields;
TokenInfoMap token_info_map;
......@@ -165,16 +144,44 @@ class AboutSigninInternals
// "status" : request status} elems]
// }],
// }
scoped_ptr<base::DictionaryValue> ToValue(std::string product_version);
scoped_ptr<base::DictionaryValue> ToValue(
AccountTrackerService* account_tracker,
SigninManagerBase* signin_manager,
const std::string& product_version);
};
void NotifyObservers();
// SigninManager::SigninDiagnosticsObserver implementation.
void NotifySigninValueChanged(
const signin_internals_util::TimedSigninStatusField& field,
const std::string& value) override;
// OAuth2TokenService::DiagnosticsObserver implementations.
void OnAccessTokenRequested(
const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes) override;
void OnFetchAccessTokenComplete(const std::string& account_id,
const std::string& consumer_id,
const OAuth2TokenService::ScopeSet& scopes,
GoogleServiceAuthError error,
base::Time expiration_time) override;
void OnTokenRemoved(const std::string& account_id,
const OAuth2TokenService::ScopeSet& scopes) override;
// Overriden from GaiaAuthConsumer.
// GaiaAuthConsumer implementations.
void OnListAccountsSuccess(const std::string& data) override;
void OnListAccountsFailure(const GoogleServiceAuthError& error) override;
// SigninManagerBase::Observer implementations.
void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
void GoogleSigninSucceeded(const std::string& account_id,
const std::string& username,
const std::string& password) override;
void GoogleSignedOut(const std::string& account_id,
const std::string& username) override;
void NotifyObservers();
// Callback for ListAccounts. Once the email addresses are fetched from GAIA,
// they are pushed to the signin_internals_ui.
void OnListAccountsComplete(
......@@ -187,6 +194,9 @@ class AboutSigninInternals
// Weak pointer to the token service.
ProfileOAuth2TokenService* token_service_;
// Weak pointer to the account tracker.
AccountTrackerService* account_tracker_;
// Weak pointer to the signin manager.
SigninManagerBase* signin_manager_;
......
......@@ -21,6 +21,8 @@ const char kTokenPrefPrefix[] = "google.services.signin.tokens.";
#define ENUM_CASE(x) case x: return (std::string(kSigninPrefPrefix) + #x)
std::string SigninStatusFieldToString(UntimedSigninStatusField field) {
switch (field) {
ENUM_CASE(ACCOUNT_ID);
ENUM_CASE(GAIA_ID);
ENUM_CASE(USERNAME);
case UNTIMED_FIELDS_END:
NOTREACHED();
......@@ -33,12 +35,10 @@ std::string SigninStatusFieldToString(UntimedSigninStatusField field) {
std::string SigninStatusFieldToString(TimedSigninStatusField field) {
switch (field) {
ENUM_CASE(SIGNIN_TYPE);
ENUM_CASE(AUTHENTICATION_RESULT_RECEIVED);
ENUM_CASE(REFRESH_TOKEN_RECEIVED);
ENUM_CASE(GET_USER_INFO_STATUS);
ENUM_CASE(UBER_TOKEN_STATUS);
ENUM_CASE(MERGE_SESSION_STATUS);
ENUM_CASE(SIGNIN_STARTED);
ENUM_CASE(SIGNIN_COMPLETED);
case TIMED_FIELDS_END:
NOTREACHED();
return std::string();
......
......@@ -27,7 +27,9 @@ enum {
};
enum UntimedSigninStatusField {
USERNAME = UNTIMED_FIELDS_BEGIN,
ACCOUNT_ID = UNTIMED_FIELDS_BEGIN,
GAIA_ID,
USERNAME,
UNTIMED_FIELDS_END
};
......@@ -37,12 +39,10 @@ enum {
};
enum TimedSigninStatusField {
SIGNIN_TYPE = TIMED_FIELDS_BEGIN,
AUTHENTICATION_RESULT_RECEIVED,
AUTHENTICATION_RESULT_RECEIVED = TIMED_FIELDS_BEGIN,
REFRESH_TOKEN_RECEIVED,
GET_USER_INFO_STATUS,
UBER_TOKEN_STATUS,
MERGE_SESSION_STATUS,
SIGNIN_STARTED,
SIGNIN_COMPLETED,
TIMED_FIELDS_END
};
......@@ -65,8 +65,6 @@ std::string SigninStatusFieldToString(TimedSigninStatusField field);
class SigninDiagnosticsObserver {
public:
// Credentials and signin related changes.
virtual void NotifySigninValueChanged(const UntimedSigninStatusField& field,
const std::string& value) {}
virtual void NotifySigninValueChanged(const TimedSigninStatusField& field,
const std::string& value) {}
// OAuth tokens related changes.
......
......@@ -105,7 +105,7 @@ std::string SigninManager::SigninTypeToString(SigninManager::SigninType type) {
case SIGNIN_TYPE_NONE:
return "No Signin";
case SIGNIN_TYPE_WITH_REFRESH_TOKEN:
return "Signin with refresh token";
return "With refresh token";
}
NOTREACHED();
......@@ -137,7 +137,7 @@ bool SigninManager::PrepareForSignin(SigninType type,
password_.assign(password);
signin_manager_signed_in_ = false;
user_info_fetched_by_account_tracker_ = false;
NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type));
NotifyDiagnosticsObservers(SIGNIN_STARTED, SigninTypeToString(type));
return true;
}
......@@ -156,8 +156,6 @@ void SigninManager::StartSignInWithRefreshToken(
temp_refresh_token_ = refresh_token;
possibly_invalid_username_ = username;
NotifyDiagnosticsObservers(GET_USER_INFO_STATUS, "Successful");
if (!callback.is_null() && !temp_refresh_token_.empty()) {
callback.Run(temp_refresh_token_);
} else {
......@@ -229,9 +227,6 @@ void SigninManager::SignOut(
client_->GetPrefs()->ClearPref(prefs::kSignedInTime);
client_->OnSignedOut();
// Erase (now) stale information from AboutSigninInternals.
NotifyDiagnosticsObservers(USERNAME, "");
// Determine the duration the user was logged in and log that to UMA.
if (!signin_time.is_null()) {
base::TimeDelta signed_in_duration = base::Time::Now() - signin_time;
......@@ -389,6 +384,8 @@ void SigninManager::MergeSigninCredentialIntoCookieJar() {
}
void SigninManager::CompletePendingSignin() {
NotifyDiagnosticsObservers(SIGNIN_COMPLETED, "Successful");
DCHECK(!possibly_invalid_username_.empty());
OnSignedIn(possibly_invalid_username_);
......
......@@ -94,7 +94,6 @@ void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) {
username,
username);
client_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username);
NotifyDiagnosticsObservers(USERNAME, username);
// Go ahead and update the last signed in username here as well. Once a
// user is signed in the two preferences should match. Doing it here as
......@@ -136,14 +135,6 @@ void SigninManagerBase::RemoveSigninDiagnosticsObserver(
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) {
......
......@@ -131,10 +131,7 @@ class SigninManagerBase : public KeyedService {
// Makes sure list is empty on destruction.
ObserverList<Observer, true> observer_list_;
// Helper methods to notify all registered diagnostics observers with.
void NotifyDiagnosticsObservers(
const signin_internals_util::UntimedSigninStatusField& field,
const std::string& value);
// Helper method to notify all registered diagnostics observers with.
void NotifyDiagnosticsObservers(
const signin_internals_util::TimedSigninStatusField& field,
const std::string& value);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment