| OLD | NEW |
| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 content::NotificationService::AllSources()); | 134 content::NotificationService::AllSources()); |
| 135 | 135 |
| 136 // Build the initial menu. | 136 // Build the initial menu. |
| 137 RebuildMenu(); | 137 RebuildMenu(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 AvatarMenuModel::~AvatarMenuModel() { | 140 AvatarMenuModel::~AvatarMenuModel() { |
| 141 ClearMenu(); | 141 ClearMenu(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 AvatarMenuModel::Item::Item(size_t model_index, const gfx::Image& icon) | |
| 145 : icon(icon), | |
| 146 active(false), | |
| 147 signed_in(false), | |
| 148 signin_required(false), | |
| 149 model_index(model_index) { | |
| 150 } | |
| 151 | |
| 152 AvatarMenuModel::Item::~Item() { | |
| 153 } | |
| 154 | |
| 155 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { | 144 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { |
| 156 DCHECK(profiles::IsMultipleProfilesEnabled() || | 145 DCHECK(profiles::IsMultipleProfilesEnabled() || |
| 157 index == GetActiveProfileIndex()); | 146 index == GetActiveProfileIndex()); |
| 158 const Item& item = GetItemAt(index); | 147 const AvatarMenuItemModel& item = GetItemAt(index); |
| 159 base::FilePath path = | 148 base::FilePath path = |
| 160 profile_info_->GetPathOfProfileAtIndex(item.model_index); | 149 profile_info_->GetPathOfProfileAtIndex(item.model_index); |
| 161 | 150 |
| 162 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 151 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
| 163 if (browser_) | 152 if (browser_) |
| 164 desktop_type = browser_->host_desktop_type(); | 153 desktop_type = browser_->host_desktop_type(); |
| 165 | 154 |
| 166 profiles::SwitchToProfile(path, desktop_type, always_create); | 155 profiles::SwitchToProfile(path, desktop_type, always_create); |
| 167 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); | 156 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); |
| 168 } | 157 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 186 if (!browser) { | 175 if (!browser) { |
| 187 const Browser::CreateParams params(ProfileManager::GetLastUsedProfile(), | 176 const Browser::CreateParams params(ProfileManager::GetLastUsedProfile(), |
| 188 chrome::GetActiveDesktop()); | 177 chrome::GetActiveDesktop()); |
| 189 browser = new Browser(params); | 178 browser = new Browser(params); |
| 190 } | 179 } |
| 191 chrome::ShowSettingsSubPage(browser, chrome::kCreateProfileSubPage); | 180 chrome::ShowSettingsSubPage(browser, chrome::kCreateProfileSubPage); |
| 192 ProfileMetrics::LogProfileAddNewUser(type); | 181 ProfileMetrics::LogProfileAddNewUser(type); |
| 193 } | 182 } |
| 194 | 183 |
| 195 base::FilePath AvatarMenuModel::GetProfilePath(size_t index) { | 184 base::FilePath AvatarMenuModel::GetProfilePath(size_t index) { |
| 196 const Item& item = GetItemAt(index); | 185 const AvatarMenuItemModel& item = GetItemAt(index); |
| 197 return profile_info_->GetPathOfProfileAtIndex(item.model_index); | 186 return profile_info_->GetPathOfProfileAtIndex(item.model_index); |
| 198 } | 187 } |
| 199 | 188 |
| 200 // static | 189 // static |
| 201 void AvatarMenuModel::SwitchToGuestProfileWindow(Browser* browser) { | 190 void AvatarMenuModel::SwitchToGuestProfileWindow(Browser* browser) { |
| 202 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 191 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 203 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(), | 192 profile_manager->CreateProfileAsync(ProfileManager::GetGuestProfilePath(), |
| 204 base::Bind(&OnGuestProfileCreated, | 193 base::Bind(&OnGuestProfileCreated, |
| 205 false, | 194 false, |
| 206 browser->host_desktop_type()), | 195 browser->host_desktop_type()), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 225 else | 214 else |
| 226 active_profile = browser_->profile(); | 215 active_profile = browser_->profile(); |
| 227 | 216 |
| 228 size_t index = | 217 size_t index = |
| 229 profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath()); | 218 profile_info_->GetIndexOfProfileWithPath(active_profile->GetPath()); |
| 230 | 219 |
| 231 DCHECK_LT(index, items_.size()); | 220 DCHECK_LT(index, items_.size()); |
| 232 return index; | 221 return index; |
| 233 } | 222 } |
| 234 | 223 |
| 235 const AvatarMenuModel::Item& AvatarMenuModel::GetItemAt(size_t index) { | 224 const AvatarMenuItemModel& AvatarMenuModel::GetItemAt(size_t index) { |
| 236 DCHECK_LT(index, items_.size()); | 225 DCHECK_LT(index, items_.size()); |
| 237 return *items_[index]; | 226 return *items_[index]; |
| 238 } | 227 } |
| 239 | 228 |
| 240 bool AvatarMenuModel::ShouldShowAddNewProfileLink() const { | 229 bool AvatarMenuModel::ShouldShowAddNewProfileLink() const { |
| 241 #if defined(ENABLE_MANAGED_USERS) | 230 #if defined(ENABLE_MANAGED_USERS) |
| 242 // |browser_| can be NULL in unit_tests. | 231 // |browser_| can be NULL in unit_tests. |
| 243 return !browser_ || | 232 return !browser_ || |
| 244 !ManagedUserService::ProfileIsManaged(browser_->profile()); | 233 !ManagedUserService::ProfileIsManaged(browser_->profile()); |
| 245 #endif | 234 #endif |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 profile_info_->IsUsingGAIAPictureOfProfileAtIndex(i) && | 295 profile_info_->IsUsingGAIAPictureOfProfileAtIndex(i) && |
| 307 profile_info_->GetGAIAPictureOfProfileAtIndex(i); | 296 profile_info_->GetGAIAPictureOfProfileAtIndex(i); |
| 308 | 297 |
| 309 gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i); | 298 gfx::Image icon = profile_info_->GetAvatarIconOfProfileAtIndex(i); |
| 310 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 299 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 311 switches::kNewProfileManagement)) { | 300 switches::kNewProfileManagement)) { |
| 312 // old avatar menu uses resized-small images | 301 // old avatar menu uses resized-small images |
| 313 icon = profiles::GetAvatarIconForMenu(icon, is_gaia_picture); | 302 icon = profiles::GetAvatarIconForMenu(icon, is_gaia_picture); |
| 314 } | 303 } |
| 315 | 304 |
| 316 Item* item = new Item(i, icon); | 305 AvatarMenuItemModel* item = new AvatarMenuItemModel(i, icon); |
| 317 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 306 item->name = profile_info_->GetNameOfProfileAtIndex(i); |
| 318 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); | 307 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); |
| 319 item->signed_in = !item->sync_state.empty(); | 308 item->signed_in = !item->sync_state.empty(); |
| 320 if (!item->signed_in) { | 309 if (!item->signed_in) { |
| 321 item->sync_state = l10n_util::GetStringUTF16( | 310 item->sync_state = l10n_util::GetStringUTF16( |
| 322 profile_info_->ProfileIsManagedAtIndex(i) ? | 311 profile_info_->ProfileIsManagedAtIndex(i) ? |
| 323 IDS_MANAGED_USER_AVATAR_LABEL : IDS_PROFILES_LOCAL_PROFILE_STATE); | 312 IDS_MANAGED_USER_AVATAR_LABEL : IDS_PROFILES_LOCAL_PROFILE_STATE); |
| 324 } | 313 } |
| 325 if (browser_) { | 314 if (browser_) { |
| 326 base::FilePath path = profile_info_->GetPathOfProfileAtIndex(i); | 315 base::FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 contents->GetController().LoadURL( | 349 contents->GetController().LoadURL( |
| 361 logout_url, content::Referrer(), | 350 logout_url, content::Referrer(), |
| 362 content::PAGE_TRANSITION_GENERATED, std::string()); | 351 content::PAGE_TRANSITION_GENERATED, std::string()); |
| 363 | 352 |
| 364 // This object may be destructed when the menu closes but we need something | 353 // This object may be destructed when the menu closes but we need something |
| 365 // around to finish the sign-out process and close the profile windows. | 354 // around to finish the sign-out process and close the profile windows. |
| 366 new SignoutTracker(current_profile, GURL(landing_url), contents); | 355 new SignoutTracker(current_profile, GURL(landing_url), contents); |
| 367 | 356 |
| 368 return contents; // returned for testing purposes | 357 return contents; // returned for testing purposes |
| 369 } | 358 } |
| OLD | NEW |