OLD | NEW |
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/profiles/avatar_menu_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 9 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { | 96 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { |
97 DCHECK_LT(index, items_.size()); | 97 DCHECK_LT(index, items_.size()); |
98 return *items_[index]; | 98 return *items_[index]; |
99 } | 99 } |
100 | 100 |
101 void AvatarMenuModel::Observe(int type, | 101 void AvatarMenuModel::Observe(int type, |
102 const NotificationSource& source, | 102 const NotificationSource& source, |
103 const NotificationDetails& details) { | 103 const NotificationDetails& details) { |
104 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 104 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); |
105 RebuildMenu(); | 105 RebuildMenu(); |
| 106 observer_->OnAvatarMenuModelChanged(this); |
106 } | 107 } |
107 | 108 |
108 void AvatarMenuModel::RebuildMenu() { | 109 void AvatarMenuModel::RebuildMenu() { |
109 ClearMenu(); | 110 ClearMenu(); |
110 | 111 |
111 const size_t count = profile_info_->GetNumberOfProfiles(); | 112 const size_t count = profile_info_->GetNumberOfProfiles(); |
112 for (size_t i = 0; i < count; ++i) { | 113 for (size_t i = 0; i < count; ++i) { |
113 Item* item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); | 114 Item* item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); |
114 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 115 item->name = profile_info_->GetNameOfProfileAtIndex(i); |
115 if (browser_) { | 116 if (browser_) { |
116 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); | 117 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
117 item->active = browser_->profile()->GetPath() == path; | 118 item->active = browser_->profile()->GetPath() == path; |
118 } | 119 } |
119 items_.push_back(item); | 120 items_.push_back(item); |
120 } | 121 } |
121 | |
122 observer_->OnAvatarMenuModelChanged(this); | |
123 } | 122 } |
124 | 123 |
125 void AvatarMenuModel::ClearMenu() { | 124 void AvatarMenuModel::ClearMenu() { |
126 STLDeleteContainerPointers(items_.begin(), items_.end()); | 125 STLDeleteContainerPointers(items_.begin(), items_.end()); |
127 items_.clear(); | 126 items_.clear(); |
128 } | 127 } |
OLD | NEW |