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

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view.cc

Issue 7155015: Store profile avatar to preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 5 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/frame/opaque_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/themes/theme_service.h" 15 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/ui/profile_menu_model.h" 16 #include "chrome/browser/ui/profile_menu_model.h"
14 #include "chrome/browser/ui/views/avatar_menu_button.h" 17 #include "chrome/browser/ui/views/avatar_menu_button.h"
15 #include "chrome/browser/ui/views/frame/browser_frame.h" 18 #include "chrome/browser/ui/views/frame/browser_frame.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 19 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/tabs/tab_strip.h" 20 #include "chrome/browser/ui/views/tabs/tab_strip.h"
18 #include "chrome/browser/ui/views/toolbar_view.h" 21 #include "chrome/browser/ui/views/toolbar_view.h"
19 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
21 #include "content/browser/tab_contents/tab_contents.h" 24 #include "content/browser/tab_contents/tab_contents.h"
22 #include "content/common/notification_service.h" 25 #include "content/common/notification_service.h"
23 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
24 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
26 #include "grit/theme_resources_standard.h" 29 #include "grit/theme_resources_standard.h"
27 #include "grit/ui_resources.h" 30 #include "grit/ui_resources.h"
28 #include "ui/base/accessibility/accessible_view_state.h" 31 #include "ui/base/accessibility/accessible_view_state.h"
29 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/base/theme_provider.h" 34 #include "ui/base/theme_provider.h"
32 #include "ui/gfx/canvas_skia.h" 35 #include "ui/gfx/canvas_skia.h"
33 #include "ui/gfx/font.h" 36 #include "ui/gfx/font.h"
37 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/path.h" 38 #include "ui/gfx/path.h"
35 #include "views/controls/button/image_button.h" 39 #include "views/controls/button/image_button.h"
36 #include "views/controls/image_view.h" 40 #include "views/controls/image_view.h"
37 #include "views/widget/root_view.h" 41 #include "views/widget/root_view.h"
38 #include "views/window/window_resources.h" 42 #include "views/window/window_resources.h"
39 #include "views/window/window_shape.h" 43 #include "views/window/window_shape.h"
40 44
41 #if !defined(OS_WIN) 45 #if !defined(OS_WIN)
42 #include "views/window/hit_test.h" 46 #include "views/window/hit_test.h"
43 #endif 47 #endif
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 AddChildView(window_icon_); 200 AddChildView(window_icon_);
197 window_icon_->Update(); 201 window_icon_->Update();
198 } 202 }
199 203
200 if (browser_view_->ShouldShowAvatar()) { 204 if (browser_view_->ShouldShowAvatar()) {
201 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ? 205 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ?
202 NULL : new ProfileMenuModel; 206 NULL : new ProfileMenuModel;
203 // AvatarMenuButton takes ownership of |menu_model|. 207 // AvatarMenuButton takes ownership of |menu_model|.
204 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model)); 208 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model));
205 AddChildView(avatar_button_.get()); 209 AddChildView(avatar_button_.get());
206 210 UpdateAvatarInfo();
207 if (browser_view_->IsOffTheRecord()) { 211 if (!browser_view_->IsOffTheRecord()) {
208 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon()); 212 registrar_.Add(this, NotificationType::PROFILE_CACHED_INFO_CHANGED,
209 } else { 213 NotificationService::AllSources());
210 // TODO(sail) Get the avatar icon assigned to this profile.
211 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
212 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1));
213 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon().
214 } 214 }
215 } 215 }
216
217 // If multi-profile is enabled set up login notifications.
218 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
219 if (browser_command_line.HasSwitch(switches::kMultiProfiles) &&
220 !browser_view->IsOffTheRecord()) {
221 RegisterLoginNotifications();
222 }
223 } 216 }
224 217
225 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { 218 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() {
226 } 219 }
227 220
228 /////////////////////////////////////////////////////////////////////////////// 221 ///////////////////////////////////////////////////////////////////////////////
229 // OpaqueBrowserFrameView, protected: 222 // OpaqueBrowserFrameView, protected:
230 223
231 int OpaqueBrowserFrameView::GetReservedHeight() const { 224 int OpaqueBrowserFrameView::GetReservedHeight() const {
232 return 0; 225 return 0;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 506 }
514 return delegate->GetWindowIcon(); 507 return delegate->GetWindowIcon();
515 } 508 }
516 509
517 /////////////////////////////////////////////////////////////////////////////// 510 ///////////////////////////////////////////////////////////////////////////////
518 // OpaqueBrowserFrameView, protected: 511 // OpaqueBrowserFrameView, protected:
519 512
520 void OpaqueBrowserFrameView::Observe(NotificationType type, 513 void OpaqueBrowserFrameView::Observe(NotificationType type,
521 const NotificationSource& source, 514 const NotificationSource& source,
522 const NotificationDetails& details) { 515 const NotificationDetails& details) {
523 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); 516 switch (type.value) {
524 std::string* name = Details<std::string>(details).ptr(); 517 case NotificationType::PROFILE_CACHED_INFO_CHANGED:
525 if (prefs::kGoogleServicesUsername == *name) 518 UpdateAvatarInfo();
526 LayoutAvatar(); 519 LayoutAvatar();
520 break;
521 default:
522 NOTREACHED() << "Got a notification we didn't register for!";
523 break;
524 }
527 } 525 }
528 526
529 /////////////////////////////////////////////////////////////////////////////// 527 ///////////////////////////////////////////////////////////////////////////////
530 // OpaqueBrowserFrameView, private: 528 // OpaqueBrowserFrameView, private:
531 529
532 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { 530 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
533 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ? 531 return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ?
534 0 : kFrameBorderThickness; 532 0 : kFrameBorderThickness;
535 } 533 }
536 534
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, 1147 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width,
1150 int height) const { 1148 int height) const {
1151 int top_height = NonClientTopBorderHeight(false, false); 1149 int top_height = NonClientTopBorderHeight(false, false);
1152 int border_thickness = NonClientBorderThickness(); 1150 int border_thickness = NonClientBorderThickness();
1153 return gfx::Rect(border_thickness, top_height, 1151 return gfx::Rect(border_thickness, top_height,
1154 std::max(0, width - (2 * border_thickness)), 1152 std::max(0, width - (2 * border_thickness)),
1155 std::max(0, height - GetReservedHeight() - 1153 std::max(0, height - GetReservedHeight() -
1156 top_height - border_thickness)); 1154 top_height - border_thickness));
1157 } 1155 }
1158 1156
1159 void OpaqueBrowserFrameView::RegisterLoginNotifications() { 1157 void OpaqueBrowserFrameView::UpdateAvatarInfo() {
1160 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); 1158 if (browser_view_->IsOffTheRecord()) {
1161 DCHECK(pref_service); 1159 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon());
1162 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); 1160 } else {
1161 ProfileInfoCache& cache =
1162 g_browser_process->profile_manager()->GetProfileInfoCache();
1163 Profile* profile = browser_view_->browser()->profile();
1164 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
1165 if (index != std::string::npos) {
1166 avatar_button_->SetIcon(cache.GetAvatarIconOfProfileAtIndex(index));
1167 avatar_button_->SetText(cache.GetNameOfProfileAtIndex(index));
1168 }
1169 }
1163 } 1170 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/opaque_browser_frame_view.h ('k') | content/common/notification_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698