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

Side by Side Diff: chrome/browser/ui/views/frame/glass_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/glass_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/themes/theme_service.h" 16 #include "chrome/browser/themes/theme_service.h"
14 #include "chrome/browser/ui/profile_menu_model.h" 17 #include "chrome/browser/ui/profile_menu_model.h"
15 #include "chrome/browser/ui/views/avatar_menu_button.h" 18 #include "chrome/browser/ui/views/avatar_menu_button.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/side_tab_strip.h" 20 #include "chrome/browser/ui/views/tabs/side_tab_strip.h"
18 #include "chrome/browser/ui/views/tabs/tab.h" 21 #include "chrome/browser/ui/views/tabs/tab.h"
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" 22 #include "chrome/browser/ui/views/tabs/tab_strip.h"
20 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
22 #include "content/common/notification_service.h" 25 #include "content/common/notification_service.h"
23 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 27 #include "grit/theme_resources.h"
25 #include "grit/theme_resources_standard.h" 28 #include "grit/theme_resources_standard.h"
26 #include "grit/ui_resources.h" 29 #include "grit/ui_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/base/theme_provider.h" 32 #include "ui/base/theme_provider.h"
30 #include "ui/gfx/canvas_skia.h" 33 #include "ui/gfx/canvas_skia.h"
31 #include "ui/gfx/icon_util.h" 34 #include "ui/gfx/icon_util.h"
35 #include "ui/gfx/image/image.h"
32 #include "views/window/client_view.h" 36 #include "views/window/client_view.h"
33 #include "views/window/window_resources.h" 37 #include "views/window/window_resources.h"
34 38
35 HICON GlassBrowserFrameView::throbber_icons_[ 39 HICON GlassBrowserFrameView::throbber_icons_[
36 GlassBrowserFrameView::kThrobberIconCount]; 40 GlassBrowserFrameView::kThrobberIconCount];
37 41
38 namespace { 42 namespace {
39 // There are 3 px of client edge drawn inside the outer frame borders. 43 // There are 3 px of client edge drawn inside the outer frame borders.
40 const int kNonClientBorderThickness = 3; 44 const int kNonClientBorderThickness = 3;
41 // Vertical tabs have 4 px border. 45 // Vertical tabs have 4 px border.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 throbber_frame_(0) { 84 throbber_frame_(0) {
81 if (browser_view_->ShouldShowWindowIcon()) 85 if (browser_view_->ShouldShowWindowIcon())
82 InitThrobberIcons(); 86 InitThrobberIcons();
83 87
84 if (browser_view_->ShouldShowAvatar()) { 88 if (browser_view_->ShouldShowAvatar()) {
85 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ? 89 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ?
86 NULL : new ProfileMenuModel; 90 NULL : new ProfileMenuModel;
87 // AvatarMenuButton takes ownership of |menu_model|. 91 // AvatarMenuButton takes ownership of |menu_model|.
88 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model)); 92 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model));
89 AddChildView(avatar_button_.get()); 93 AddChildView(avatar_button_.get());
90 94 UpdateAvatarInfo();
91 if (browser_view_->IsOffTheRecord()) { 95 if (!browser_view_->IsOffTheRecord()) {
92 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon()); 96 registrar_.Add(this, NotificationType::PROFILE_CACHED_INFO_CHANGED,
93 } else { 97 NotificationService::AllSources());
94 // TODO(sail) Get the avatar icon assigned to this profile.
95 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
96 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1));
97 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon().
98 } 98 }
99 } 99 }
100
101 // If multi-profile is enabled set up login notifications.
102 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
103 if (browser_command_line.HasSwitch(switches::kMultiProfiles) &&
104 !browser_view->IsOffTheRecord()) {
105 RegisterLoginNotifications();
106 }
107 } 100 }
108 101
109 GlassBrowserFrameView::~GlassBrowserFrameView() { 102 GlassBrowserFrameView::~GlassBrowserFrameView() {
110 } 103 }
111 104
112 /////////////////////////////////////////////////////////////////////////////// 105 ///////////////////////////////////////////////////////////////////////////////
113 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: 106 // GlassBrowserFrameView, BrowserNonClientFrameView implementation:
114 107
115 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( 108 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip(
116 views::View* tabstrip) const { 109 views::View* tabstrip) const {
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 void GlassBrowserFrameView::DisplayNextThrobberFrame() { 512 void GlassBrowserFrameView::DisplayNextThrobberFrame() {
520 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; 513 throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount;
521 SendMessage(frame_->GetNativeWindow(), WM_SETICON, 514 SendMessage(frame_->GetNativeWindow(), WM_SETICON,
522 static_cast<WPARAM>(ICON_SMALL), 515 static_cast<WPARAM>(ICON_SMALL),
523 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); 516 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_]));
524 } 517 }
525 518
526 void GlassBrowserFrameView::Observe(NotificationType type, 519 void GlassBrowserFrameView::Observe(NotificationType type,
527 const NotificationSource& source, 520 const NotificationSource& source,
528 const NotificationDetails& details) { 521 const NotificationDetails& details) {
529 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); 522 switch (type.value) {
530 std::string* name = Details<std::string>(details).ptr(); 523 case NotificationType::PROFILE_CACHED_INFO_CHANGED:
531 if (prefs::kGoogleServicesUsername == *name) 524 UpdateAvatarInfo();
532 LayoutAvatar(); 525 LayoutAvatar();
533 } 526 break;
534 527 default:
535 void GlassBrowserFrameView::RegisterLoginNotifications() { 528 NOTREACHED() << "Got a notification we didn't register for!";
536 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); 529 break;
537 DCHECK(pref_service); 530 }
538 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this);
539 } 531 }
540 532
541 // static 533 // static
542 void GlassBrowserFrameView::InitThrobberIcons() { 534 void GlassBrowserFrameView::InitThrobberIcons() {
543 static bool initialized = false; 535 static bool initialized = false;
544 if (!initialized) { 536 if (!initialized) {
545 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); 537 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
546 for (int i = 0; i < kThrobberIconCount; ++i) { 538 for (int i = 0; i < kThrobberIconCount; ++i) {
547 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i); 539 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i);
548 DCHECK(throbber_icons_[i]); 540 DCHECK(throbber_icons_[i]);
549 } 541 }
550 initialized = true; 542 initialized = true;
551 } 543 }
552 } 544 }
545
546 void GlassBrowserFrameView::UpdateAvatarInfo() {
547 if (browser_view_->IsOffTheRecord()) {
548 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon());
549 } else {
550 ProfileInfoCache& cache =
551 g_browser_process->profile_manager()->GetProfileInfoCache();
552 Profile* profile = browser_view_->browser()->profile();
553 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath());
554 if (index != std::string::npos) {
555 avatar_button_->SetIcon(cache.GetAvatarIconOfProfileAtIndex(index));
556 avatar_button_->SetText(cache.GetNameOfProfileAtIndex(index));
557 }
558 }
559 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/glass_browser_frame_view.h ('k') | chrome/browser/ui/views/frame/opaque_browser_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698