Commit 8023bc89 authored by rogerta@chromium.org's avatar rogerta@chromium.org

Make sure auth error reporting handles guest mode correctly.

BUG=376648

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273070 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b6a1c23
......@@ -122,4 +122,10 @@ void UpdateGaiaProfilePhotoIfNeeded(Profile* profile) {
GAIAInfoUpdateServiceFactory::GetInstance()->GetForProfile(profile)->Update();
}
SigninErrorController* GetSigninErrorController(Profile* profile) {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
return token_service ? token_service->signin_error_controller() : NULL;
}
} // namespace profiles
......@@ -11,6 +11,7 @@
class Browser;
class PrefRegistrySimple;
class Profile;
class SigninErrorController;
namespace base { class FilePath; }
namespace profiles {
......@@ -52,6 +53,11 @@ bool IsRegularOrGuestSession(Browser* browser);
// version of the Gaia profile picture.
void UpdateGaiaProfilePhotoIfNeeded(Profile* profile);
// Returns the sign-in error controller for the given profile. Some profiles,
// like guest profiles, may not have a controller so this function may return
// NULL.
SigninErrorController* GetSigninErrorController(Profile* profile);
} // namespace profiles
#endif // CHROME_BROWSER_PROFILES_PROFILES_STATE_H_
......@@ -104,12 +104,14 @@ NewAvatarButton::NewAvatarButton(
g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
// Subscribe to authentication error changes so that the avatar button
// can update itself.
// can update itself. Note that guest mode profiles won't have a token
// service.
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
signin_error_controller();
error->AddObserver(this);
OnErrorChanged();
profiles::GetSigninErrorController(browser_->profile());
if (error) {
error->AddObserver(this);
OnErrorChanged();
}
SchedulePaint();
}
......@@ -118,9 +120,9 @@ NewAvatarButton::~NewAvatarButton() {
g_browser_process->profile_manager()->
GetProfileInfoCache().RemoveObserver(this);
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
signin_error_controller();
error->RemoveObserver(this);
profiles::GetSigninErrorController(browser_->profile());
if (error)
error->RemoveObserver(this);
}
void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
......@@ -159,10 +161,9 @@ void NewAvatarButton::OnErrorChanged() {
gfx::ImageSkia icon;
// If there is an error, show an warning icon.
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())->
signin_error_controller();
if (error->HasError()) {
const SigninErrorController* error =
profiles::GetSigninErrorController(browser_->profile());
if (error && error->HasError()) {
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
}
......
......@@ -101,16 +101,14 @@ gfx::ImageSkia CreateSquarePlaceholderImage(int size) {
}
bool HasAuthError(Profile* profile) {
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
signin_error_controller();
const SigninErrorController* error =
profiles::GetSigninErrorController(profile);
return error && error->HasError();
}
std::string GetAuthErrorAccountId(Profile* profile) {
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
signin_error_controller();
const SigninErrorController* error =
profiles::GetSigninErrorController(profile);
if (!error)
return std::string();
......@@ -118,9 +116,8 @@ std::string GetAuthErrorAccountId(Profile* profile) {
}
std::string GetAuthErrorUsername(Profile* profile) {
SigninErrorController* error =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
signin_error_controller();
const SigninErrorController* error =
profiles::GetSigninErrorController(profile);
if (!error)
return std::string();
......
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