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