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

Side by Side Diff: chrome/browser/ui/views/profiles/new_avatar_button.cc

Issue 297853006: Make sure auth error reporting handles guest mode correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" 5 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
6 6
7 #include "base/win/windows_version.h" 7 #include "base/win/windows_version.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/browser/profiles/profiles_state.h" 10 #include "chrome/browser/profiles/profiles_state.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
98 98
99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
100 set_menu_marker( 100 set_menu_marker(
101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); 101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
102 } 102 }
103 103
104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
105 105
106 // Subscribe to authentication error changes so that the avatar button 106 // Subscribe to authentication error changes so that the avatar button
107 // can update itself. 107 // can update itself. Note that guest mode profiles won't have a token
108 // service.
108 SigninErrorController* error = 109 SigninErrorController* error =
109 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 110 profiles::GetSigninErrorController(browser_->profile());
110 signin_error_controller(); 111 if (error) {
111 error->AddObserver(this); 112 error->AddObserver(this);
112 OnErrorChanged(); 113 OnErrorChanged();
114 }
113 115
114 SchedulePaint(); 116 SchedulePaint();
115 } 117 }
116 118
117 NewAvatarButton::~NewAvatarButton() { 119 NewAvatarButton::~NewAvatarButton() {
118 g_browser_process->profile_manager()-> 120 g_browser_process->profile_manager()->
119 GetProfileInfoCache().RemoveObserver(this); 121 GetProfileInfoCache().RemoveObserver(this);
120 SigninErrorController* error = 122 SigninErrorController* error =
121 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 123 profiles::GetSigninErrorController(browser_->profile());
122 signin_error_controller(); 124 if (error)
123 error->RemoveObserver(this); 125 error->RemoveObserver(this);
124 } 126 }
125 127
126 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { 128 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
127 // Get text bounds, and then adjust for the top and RTL languages. 129 // Get text bounds, and then adjust for the top and RTL languages.
128 gfx::Rect rect = GetTextBounds(); 130 gfx::Rect rect = GetTextBounds();
129 rect.Offset(0, -rect.y()); 131 rect.Offset(0, -rect.y());
130 if (rect.width() > 0) 132 if (rect.width() > 0)
131 rect.set_x(GetMirroredXForRect(rect)); 133 rect.set_x(GetMirroredXForRect(rect));
132 134
133 canvas->DrawStringRectWithHalo( 135 canvas->DrawStringRectWithHalo(
(...skipping 18 matching lines...) Expand all
152 void NewAvatarButton::OnProfileNameChanged( 154 void NewAvatarButton::OnProfileNameChanged(
153 const base::FilePath& profile_path, 155 const base::FilePath& profile_path,
154 const base::string16& old_profile_name) { 156 const base::string16& old_profile_name) {
155 UpdateAvatarButtonAndRelayoutParent(); 157 UpdateAvatarButtonAndRelayoutParent();
156 } 158 }
157 159
158 void NewAvatarButton::OnErrorChanged() { 160 void NewAvatarButton::OnErrorChanged() {
159 gfx::ImageSkia icon; 161 gfx::ImageSkia icon;
160 162
161 // If there is an error, show an warning icon. 163 // If there is an error, show an warning icon.
162 SigninErrorController* error = 164 const SigninErrorController* error =
163 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 165 profiles::GetSigninErrorController(browser_->profile());
164 signin_error_controller(); 166 if (error && error->HasError()) {
165 if (error->HasError()) {
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 167 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); 168 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
168 } 169 }
169 170
170 SetIcon(icon); 171 SetIcon(icon);
171 UpdateAvatarButtonAndRelayoutParent(); 172 UpdateAvatarButtonAndRelayoutParent();
172 } 173 }
173 174
174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { 175 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
175 // We want the button to resize if the new text is shorter. 176 // We want the button to resize if the new text is shorter.
176 SetText(GetElidedText( 177 SetText(GetElidedText(
177 profiles::GetAvatarNameForProfile(browser_->profile()))); 178 profiles::GetAvatarNameForProfile(browser_->profile())));
178 ClearMaxTextSize(); 179 ClearMaxTextSize();
179 180
180 // Because the width of the button might have changed, the parent browser 181 // Because the width of the button might have changed, the parent browser
181 // frame needs to recalculate the button bounds and redraw it. 182 // frame needs to recalculate the button bounds and redraw it.
182 if (parent()) 183 if (parent())
183 parent()->Layout(); 184 parent()->Layout();
184 } 185 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profiles_state.cc ('k') | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698