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

Side by Side Diff: chrome/browser/profiles/avatar_menu_model.cc

Issue 9500003: Add a button to exit managed mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 } // namespace 45 } // namespace
46 46
47 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, 47 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache,
48 AvatarMenuModelObserver* observer, 48 AvatarMenuModelObserver* observer,
49 Browser* browser) 49 Browser* browser)
50 : profile_info_(profile_cache), 50 : profile_info_(profile_cache),
51 observer_(observer), 51 observer_(observer),
52 browser_(browser) { 52 browser_(browser) {
53 DCHECK(profile_info_); 53 DCHECK(profile_info_);
54 DCHECK(observer_);
55 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. 54 // Don't DCHECK(browser_) so that unit tests can reuse this ctor.
56 55
57 // Register this as an observer of the info cache. 56 // Register this as an observer of the info cache.
58 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 57 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
59 content::NotificationService::AllSources()); 58 content::NotificationService::AllSources());
60 59
61 // Build the initial menu. 60 // Build the initial menu.
62 RebuildMenu(); 61 RebuildMenu();
63 } 62 }
64 63
65 AvatarMenuModel::~AvatarMenuModel() { 64 AvatarMenuModel::~AvatarMenuModel() {
66 ClearMenu(); 65 ClearMenu();
67 } 66 }
68 67
69 AvatarMenuModel::Item::Item(size_t model_index, const gfx::Image& icon) 68 AvatarMenuModel::Item::Item(size_t model_index, const gfx::Image& icon)
70 : icon(icon), 69 : icon(icon),
71 active(false), 70 active(false),
72 model_index(model_index) { 71 model_index(model_index) {
73 } 72 }
74 73
75 AvatarMenuModel::Item::~Item() { 74 AvatarMenuModel::Item::~Item() {
76 } 75 }
77 76
78 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { 77 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) {
78 DCHECK(ProfileManager::IsMultipleProfilesEnabled() ||
79 index == GetActiveProfileIndex());
79 const Item& item = GetItemAt(index); 80 const Item& item = GetItemAt(index);
80 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index); 81 FilePath path = profile_info_->GetPathOfProfileAtIndex(item.model_index);
81 g_browser_process->profile_manager()->CreateProfileAsync( 82 g_browser_process->profile_manager()->CreateProfileAsync(
82 path, base::Bind(&OnProfileCreated, always_create)); 83 path, base::Bind(&OnProfileCreated, always_create));
83 84
84 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); 85 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON);
85 } 86 }
86 87
87 void AvatarMenuModel::EditProfile(size_t index) { 88 void AvatarMenuModel::EditProfile(size_t index) {
88 Browser* browser = browser_; 89 Browser* browser = browser_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { 129 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) {
129 DCHECK_LT(index, items_.size()); 130 DCHECK_LT(index, items_.size());
130 return *items_[index]; 131 return *items_[index];
131 } 132 }
132 133
133 void AvatarMenuModel::Observe(int type, 134 void AvatarMenuModel::Observe(int type,
134 const content::NotificationSource& source, 135 const content::NotificationSource& source,
135 const content::NotificationDetails& details) { 136 const content::NotificationDetails& details) {
136 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); 137 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type);
137 RebuildMenu(); 138 RebuildMenu();
138 observer_->OnAvatarMenuModelChanged(this); 139 if (observer_)
140 observer_->OnAvatarMenuModelChanged(this);
139 } 141 }
140 142
141 // static 143 // static
142 bool AvatarMenuModel::ShouldShowAvatarMenu() { 144 bool AvatarMenuModel::ShouldShowAvatarMenu() {
143 return ProfileManager::IsMultipleProfilesEnabled() && 145 return ProfileManager::IsMultipleProfilesEnabled() &&
144 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; 146 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1;
145 } 147 }
146 148
147 void AvatarMenuModel::RebuildMenu() { 149 void AvatarMenuModel::RebuildMenu() {
148 ClearMenu(); 150 ClearMenu();
(...skipping 19 matching lines...) Expand all
168 item->active = browser_->profile()->GetPath() == path; 170 item->active = browser_->profile()->GetPath() == path;
169 } 171 }
170 items_.push_back(item); 172 items_.push_back(item);
171 } 173 }
172 } 174 }
173 175
174 void AvatarMenuModel::ClearMenu() { 176 void AvatarMenuModel::ClearMenu() {
175 STLDeleteContainerPointers(items_.begin(), items_.end()); 177 STLDeleteContainerPointers(items_.begin(), items_.end());
176 items_.clear(); 178 items_.clear();
177 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698