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

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

Issue 1701563002: Refactor ProfileInfoCache in c/b/ui/views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments Created 4 years, 10 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile_attributes_entry.h"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h" 14 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
16 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_palette.h" 20 #include "ui/gfx/color_palette.h"
20 #include "ui/gfx/geometry/vector2d.h" 21 #include "ui/gfx/geometry/vector2d.h"
21 #include "ui/gfx/paint_vector_icon.h" 22 #include "ui/gfx/paint_vector_icon.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } else { 94 } else {
94 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); 95 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
95 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); 96 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
96 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); 97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
97 98
98 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
99 generic_avatar_ = 100 generic_avatar_ =
100 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); 101 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia();
101 } 102 }
102 103
103 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 104 g_browser_process->profile_manager()->
105 GetProfileAttributesStorage().AddObserver(this);
104 106
105 // Subscribe to authentication error changes so that the avatar button can 107 // Subscribe to authentication error changes so that the avatar button can
106 // update itself. Note that guest mode profiles won't have a token service. 108 // update itself. Note that guest mode profiles won't have a token service.
107 SigninErrorController* error = 109 SigninErrorController* error =
108 profiles::GetSigninErrorController(browser_->profile()); 110 profiles::GetSigninErrorController(browser_->profile());
109 if (error) { 111 if (error) {
110 error->AddObserver(this); 112 error->AddObserver(this);
111 OnErrorChanged(); // This calls Update(). 113 OnErrorChanged(); // This calls Update().
112 } else { 114 } else {
113 Update(); 115 Update();
114 } 116 }
115 SchedulePaint(); 117 SchedulePaint();
116 } 118 }
117 119
118 NewAvatarButton::~NewAvatarButton() { 120 NewAvatarButton::~NewAvatarButton() {
119 g_browser_process->profile_manager()-> 121 g_browser_process->profile_manager()->
120 GetProfileInfoCache().RemoveObserver(this); 122 GetProfileAttributesStorage().RemoveObserver(this);
121 SigninErrorController* error = 123 SigninErrorController* error =
122 profiles::GetSigninErrorController(browser_->profile()); 124 profiles::GetSigninErrorController(browser_->profile());
123 if (error) 125 if (error)
124 error->RemoveObserver(this); 126 error->RemoveObserver(this);
125 } 127 }
126 128
127 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { 129 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) {
128 // Prevent the bubble from being re-shown if it's already showing. 130 // Prevent the bubble from being re-shown if it's already showing.
129 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); 131 suppress_mouse_released_action_ = ProfileChooserView::IsShowing();
130 return LabelButton::OnMousePressed(event); 132 return LabelButton::OnMousePressed(event);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void NewAvatarButton::OnErrorChanged() { 179 void NewAvatarButton::OnErrorChanged() {
178 // If there is an error, show an warning icon. 180 // If there is an error, show an warning icon.
179 const SigninErrorController* error = 181 const SigninErrorController* error =
180 profiles::GetSigninErrorController(browser_->profile()); 182 profiles::GetSigninErrorController(browser_->profile());
181 has_auth_error_ = error && error->HasError(); 183 has_auth_error_ = error && error->HasError();
182 184
183 Update(); 185 Update();
184 } 186 }
185 187
186 void NewAvatarButton::Update() { 188 void NewAvatarButton::Update() {
187 const ProfileInfoCache& cache = 189 ProfileAttributesStorage& storage =
188 g_browser_process->profile_manager()->GetProfileInfoCache(); 190 g_browser_process->profile_manager()->GetProfileAttributesStorage();
189 191
190 // If we have a single local profile, then use the generic avatar 192 // If we have a single local profile, then use the generic avatar
191 // button instead of the profile name. Never use the generic button if 193 // button instead of the profile name. Never use the generic button if
192 // the active profile is Guest. 194 // the active profile is Guest.
193 bool use_generic_button = (!browser_->profile()->IsGuestSession() && 195 bool use_generic_button =
achuithb 2016/02/19 11:55:22 const
lwchkg 2016/02/20 05:20:04 Done.
194 cache.GetNumberOfProfiles() == 1 && 196 !browser_->profile()->IsGuestSession() &&
195 !cache.ProfileIsAuthenticatedAtIndex(0)); 197 storage.GetNumberOfProfiles() == 1 &&
198 storage.GetAllProfilesAttributes().front()->IsAuthenticated();
196 199
197 SetText(use_generic_button ? base::string16() : 200 SetText(use_generic_button
198 profiles::GetAvatarButtonTextForProfile(browser_->profile())); 201 ? base::string16()
202 : profiles::GetAvatarButtonTextForProfile(browser_->profile()));
199 203
200 // If the button has no text, clear the text shadows to make sure the 204 // If the button has no text, clear the text shadows to make sure the
201 // image is centered correctly. 205 // image is centered correctly.
202 SetTextShadows( 206 SetTextShadows(
203 use_generic_button 207 use_generic_button
204 ? gfx::ShadowValues() 208 ? gfx::ShadowValues()
205 : gfx::ShadowValues( 209 : gfx::ShadowValues(
206 10, gfx::ShadowValue(gfx::Vector2d(), 1.0f, SK_ColorDKGRAY))); 210 10, gfx::ShadowValue(gfx::Vector2d(), 1.0f, SK_ColorDKGRAY)));
207 211
208 // We want the button to resize if the new text is shorter. 212 // We want the button to resize if the new text is shorter.
209 SetMinSize(gfx::Size()); 213 SetMinSize(gfx::Size());
210 214
211 if (use_generic_button) { 215 if (use_generic_button) {
212 SetImage(views::Button::STATE_NORMAL, generic_avatar_); 216 SetImage(views::Button::STATE_NORMAL, generic_avatar_);
213 } else if (has_auth_error_) { 217 } else if (has_auth_error_) {
214 SetImage(views::Button::STATE_NORMAL, 218 SetImage(views::Button::STATE_NORMAL,
215 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 13, 219 gfx::CreateVectorIcon(gfx::VectorIconId::WARNING, 13,
216 gfx::kGoogleYellow700)); 220 gfx::kGoogleYellow700));
217 } else { 221 } else {
218 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia()); 222 SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia());
219 } 223 }
220 224
221 // If we are not using the generic button, then reset the spacing between 225 // If we are not using the generic button, then reset the spacing between
222 // the text and the possible authentication error icon. 226 // the text and the possible authentication error icon.
223 const int kDefaultImageTextSpacing = 5; 227 const int kDefaultImageTextSpacing = 5;
224 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing); 228 SetImageLabelSpacing(use_generic_button ? 0 : kDefaultImageTextSpacing);
225 229
226 PreferredSizeChanged(); 230 PreferredSizeChanged();
227 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698