| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/profiles/avatar_base_button.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/strings/string16.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/profiles/profile_manager.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "components/signin/core/common/profile_management_switches.h" | |
| 13 | |
| 14 AvatarBaseButton::AvatarBaseButton(Browser* browser) | |
| 15 : browser_(browser) { | |
| 16 // |profile_manager| might be null in tests. | |
| 17 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 18 if (profile_manager) | |
| 19 profile_manager->GetProfileInfoCache().AddObserver(this); | |
| 20 } | |
| 21 | |
| 22 AvatarBaseButton::~AvatarBaseButton() { | |
| 23 // |profile_manager| might be null in tests. | |
| 24 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 25 if (profile_manager) | |
| 26 profile_manager->GetProfileInfoCache().RemoveObserver(this); | |
| 27 } | |
| 28 | |
| 29 void AvatarBaseButton::OnProfileAdded(const base::FilePath& profile_path) { | |
| 30 Update(); | |
| 31 } | |
| 32 | |
| 33 void AvatarBaseButton::OnProfileWasRemoved( | |
| 34 const base::FilePath& profile_path, | |
| 35 const base::string16& profile_name) { | |
| 36 // If deleting the active profile, don't bother updating the avatar | |
| 37 // button, as the browser window is being closed anyway. | |
| 38 if (browser_->profile()->GetPath() != profile_path) | |
| 39 Update(); | |
| 40 } | |
| 41 | |
| 42 void AvatarBaseButton::OnProfileNameChanged( | |
| 43 const base::FilePath& profile_path, | |
| 44 const base::string16& old_profile_name) { | |
| 45 if (browser_->profile()->GetPath() == profile_path) | |
| 46 Update(); | |
| 47 } | |
| 48 | |
| 49 void AvatarBaseButton::OnProfileAvatarChanged( | |
| 50 const base::FilePath& profile_path) { | |
| 51 if (!switches::IsNewAvatarMenu() && | |
| 52 browser_->profile()->GetPath() == profile_path) | |
| 53 Update(); | |
| 54 } | |
| 55 | |
| 56 void AvatarBaseButton::OnProfileSupervisedUserIdChanged( | |
| 57 const base::FilePath& profile_path) { | |
| 58 if (browser_->profile()->GetPath() == profile_path) | |
| 59 Update(); | |
| 60 } | |
| OLD | NEW |