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

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: 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const int kMaxCharactersToDisplay = 15; 49 const int kMaxCharactersToDisplay = 15;
50 50
51 const gfx::FontList font_list; 51 const gfx::FontList font_list;
52 return gfx::ElideText( 52 return gfx::ElideText(
53 original_text, 53 original_text,
54 font_list, 54 font_list,
55 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay), 55 font_list.GetExpectedTextWidth(kMaxCharactersToDisplay),
56 gfx::ELIDE_AT_END); 56 gfx::ELIDE_AT_END);
57 } 57 }
58 58
59 SigninErrorController* GetSigninErrorController(Browser* browser) {
noms (inactive) 2014/05/23 16:59:57 Maybe this should go in profiles_state.h, given th
Roger Tawa OOO till Jul 10th 2014/05/23 20:54:37 Done.
60 ProfileOAuth2TokenService* token_service =
61 ProfileOAuth2TokenServiceFactory::GetForProfile(browser->profile());
62 return token_service ? token_service->signin_error_controller() : NULL;
63 }
64
59 } // namespace 65 } // namespace
60 66
61 NewAvatarButton::NewAvatarButton( 67 NewAvatarButton::NewAvatarButton(
62 views::ButtonListener* listener, 68 views::ButtonListener* listener,
63 const base::string16& profile_name, 69 const base::string16& profile_name,
64 AvatarButtonStyle button_style, 70 AvatarButtonStyle button_style,
65 Browser* browser) 71 Browser* browser)
66 : MenuButton(listener, GetElidedText(profile_name), NULL, true), 72 : MenuButton(listener, GetElidedText(profile_name), NULL, true),
67 browser_(browser) { 73 browser_(browser) {
68 set_animate_on_state_change(false); 74 set_animate_on_state_change(false);
(...skipping 28 matching lines...) Expand all
97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED); 103 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
98 104
99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 105 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
100 set_menu_marker( 106 set_menu_marker(
101 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia()); 107 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
102 } 108 }
103 109
104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 110 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
105 111
106 // Subscribe to authentication error changes so that the avatar button 112 // Subscribe to authentication error changes so that the avatar button
107 // can update itself. 113 // can update itself. Note that guest mode profiles won't have a token
108 SigninErrorController* error = 114 // service.
109 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 115 SigninErrorController* error = GetSigninErrorController(browser_);
110 signin_error_controller(); 116 if (error) {
111 error->AddObserver(this); 117 error->AddObserver(this);
112 OnErrorChanged(); 118 OnErrorChanged();
119 }
113 120
114 SchedulePaint(); 121 SchedulePaint();
115 } 122 }
116 123
117 NewAvatarButton::~NewAvatarButton() { 124 NewAvatarButton::~NewAvatarButton() {
118 g_browser_process->profile_manager()-> 125 g_browser_process->profile_manager()->
119 GetProfileInfoCache().RemoveObserver(this); 126 GetProfileInfoCache().RemoveObserver(this);
120 SigninErrorController* error = 127 SigninErrorController* error = GetSigninErrorController(browser_);
121 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 128 if (error)
122 signin_error_controller(); 129 error->RemoveObserver(this);
123 error->RemoveObserver(this);
124 } 130 }
125 131
126 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { 132 void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) {
127 // Get text bounds, and then adjust for the top and RTL languages. 133 // Get text bounds, and then adjust for the top and RTL languages.
128 gfx::Rect rect = GetTextBounds(); 134 gfx::Rect rect = GetTextBounds();
129 rect.Offset(0, -rect.y()); 135 rect.Offset(0, -rect.y());
130 if (rect.width() > 0) 136 if (rect.width() > 0)
131 rect.set_x(GetMirroredXForRect(rect)); 137 rect.set_x(GetMirroredXForRect(rect));
132 138
133 canvas->DrawStringRectWithHalo( 139 canvas->DrawStringRectWithHalo(
(...skipping 18 matching lines...) Expand all
152 void NewAvatarButton::OnProfileNameChanged( 158 void NewAvatarButton::OnProfileNameChanged(
153 const base::FilePath& profile_path, 159 const base::FilePath& profile_path,
154 const base::string16& old_profile_name) { 160 const base::string16& old_profile_name) {
155 UpdateAvatarButtonAndRelayoutParent(); 161 UpdateAvatarButtonAndRelayoutParent();
156 } 162 }
157 163
158 void NewAvatarButton::OnErrorChanged() { 164 void NewAvatarButton::OnErrorChanged() {
159 gfx::ImageSkia icon; 165 gfx::ImageSkia icon;
160 166
161 // If there is an error, show an warning icon. 167 // If there is an error, show an warning icon.
162 SigninErrorController* error = 168 const SigninErrorController* error = GetSigninErrorController(browser_);
163 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile())-> 169 if (error && error->HasError()) {
164 signin_error_controller();
165 if (error->HasError()) {
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 170 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
167 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); 171 icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia();
168 } 172 }
169 173
170 SetIcon(icon); 174 SetIcon(icon);
171 UpdateAvatarButtonAndRelayoutParent(); 175 UpdateAvatarButtonAndRelayoutParent();
172 } 176 }
173 177
174 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { 178 void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() {
175 // We want the button to resize if the new text is shorter. 179 // We want the button to resize if the new text is shorter.
176 SetText(GetElidedText( 180 SetText(GetElidedText(
177 profiles::GetAvatarNameForProfile(browser_->profile()))); 181 profiles::GetAvatarNameForProfile(browser_->profile())));
178 ClearMaxTextSize(); 182 ClearMaxTextSize();
179 183
180 // Because the width of the button might have changed, the parent browser 184 // Because the width of the button might have changed, the parent browser
181 // frame needs to recalculate the button bounds and redraw it. 185 // frame needs to recalculate the button bounds and redraw it.
182 if (parent()) 186 if (parent())
183 parent()->Layout(); 187 parent()->Layout();
184 } 188 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698