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

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/views/profiles/avatar_button_delegate.h" 15 #include "chrome/browser/ui/views/profiles/avatar_button_delegate.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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } else { 95 } else {
95 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); 96 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
96 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER); 97 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
97 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED); 98 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
98 99
99 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); 100 SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
100 generic_avatar_ = 101 generic_avatar_ =
101 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia(); 102 *rb->GetImageNamed(IDR_AVATAR_NATIVE_BUTTON_AVATAR).ToImageSkia();
102 } 103 }
103 104
104 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 105 g_browser_process->profile_manager()->
106 GetProfileAttributesStorage().AddObserver(this);
105 107
106 // Subscribe to authentication error changes so that the avatar button can 108 // Subscribe to authentication error changes so that the avatar button can
107 // update itself. Note that guest mode profiles won't have a token service. 109 // update itself. Note that guest mode profiles won't have a token service.
108 SigninErrorController* error = profiles::GetSigninErrorController(profile_); 110 SigninErrorController* error = profiles::GetSigninErrorController(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 = profiles::GetSigninErrorController(profile_); 123 SigninErrorController* error =
124 profiles::GetSigninErrorController(profile_);
122 if (error) 125 if (error)
123 error->RemoveObserver(this); 126 error->RemoveObserver(this);
124 } 127 }
125 128
126 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) { 129 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) {
127 // 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.
128 suppress_mouse_released_action_ = ProfileChooserView::IsShowing(); 131 suppress_mouse_released_action_ = ProfileChooserView::IsShowing();
129 return LabelButton::OnMousePressed(event); 132 return LabelButton::OnMousePressed(event);
130 } 133 }
131 134
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 void NewAvatarButton::OnErrorChanged() { 179 void NewAvatarButton::OnErrorChanged() {
177 // If there is an error, show an warning icon. 180 // If there is an error, show an warning icon.
178 const SigninErrorController* error = 181 const SigninErrorController* error =
179 profiles::GetSigninErrorController(profile_); 182 profiles::GetSigninErrorController(profile_);
180 has_auth_error_ = error && error->HasError(); 183 has_auth_error_ = error && error->HasError();
181 184
182 Update(); 185 Update();
183 } 186 }
184 187
185 void NewAvatarButton::Update() { 188 void NewAvatarButton::Update() {
186 const ProfileInfoCache& cache = 189 ProfileAttributesStorage& storage =
187 g_browser_process->profile_manager()->GetProfileInfoCache(); 190 g_browser_process->profile_manager()->GetProfileAttributesStorage();
188 191
189 // 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
190 // 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
191 // the active profile is Guest. 194 // the active profile is Guest.
192 bool use_generic_button = 195 const bool use_generic_button =
193 (!profile_->IsGuestSession() && cache.GetNumberOfProfiles() == 1 && 196 !profile_->IsGuestSession() &&
194 !cache.ProfileIsAuthenticatedAtIndex(0)); 197 storage.GetNumberOfProfiles() == 1 &&
198 storage.GetAllProfilesAttributes().front()->IsAuthenticated();
195 199
196 SetText(use_generic_button 200 SetText(use_generic_button
197 ? base::string16() 201 ? base::string16()
198 : profiles::GetAvatarButtonTextForProfile(profile_)); 202 : profiles::GetAvatarButtonTextForProfile(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()
(...skipping 14 matching lines...) Expand all
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 delegate_->ButtonPreferredSizeChanged(); 231 delegate_->ButtonPreferredSizeChanged();
228 } 232 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/new_avatar_button.h ('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