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

Unified Diff: chrome/browser/ui/views/profiles/avatar_base_button.cc

Issue 1009403002: Refactor the avatar button/icon class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/profiles/avatar_base_button.cc
diff --git a/chrome/browser/ui/views/profiles/avatar_base_button.cc b/chrome/browser/ui/views/profiles/avatar_base_button.cc
new file mode 100644
index 0000000000000000000000000000000000000000..18c6a2eaa2626d96109461d1a23879ea473658ac
--- /dev/null
+++ b/chrome/browser/ui/views/profiles/avatar_base_button.cc
@@ -0,0 +1,60 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/profiles/avatar_base_button.h"
+
+#include "base/files/file_path.h"
+#include "base/strings/string16.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "components/signin/core/common/profile_management_switches.h"
+
+AvatarBaseButton::AvatarBaseButton(Browser* browser)
+ : browser_(browser) {
+ // profile_manager might be null in tests.
msw 2015/05/05 17:36:39 nit: vertical brackets around identifier names: |p
yao 2015/05/05 17:45:00 Done.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ if (profile_manager)
+ profile_manager->GetProfileInfoCache().AddObserver(this);
+}
+
+AvatarBaseButton::~AvatarBaseButton() {
+ // profile_manager might be null in tests.
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ if (profile_manager)
+ profile_manager->GetProfileInfoCache().RemoveObserver(this);
+}
+
+void AvatarBaseButton::OnProfileAdded(const base::FilePath& profile_path) {
+ Update();
+}
+
+void AvatarBaseButton::OnProfileWasRemoved(
+ const base::FilePath& profile_path,
+ const base::string16& profile_name) {
+ // If deleting the active profile, don't bother updating the avatar
+ // button, as the browser window is being closed anyway.
+ if (browser_->profile()->GetPath() != profile_path)
+ Update();
+}
+
+void AvatarBaseButton::OnProfileNameChanged(
+ const base::FilePath& profile_path,
+ const base::string16& old_profile_name) {
+ if (browser_->profile()->GetPath() == profile_path)
+ Update();
+}
+
+void AvatarBaseButton::OnProfileAvatarChanged(
+ const base::FilePath& profile_path) {
+ if (!switches::IsNewAvatarMenu() &&
+ browser_->profile()->GetPath() == profile_path)
+ Update();
+}
+
+void AvatarBaseButton::OnProfileSupervisedUserIdChanged(
+ const base::FilePath& profile_path) {
+ if (browser_->profile()->GetPath() == profile_path)
+ Update();
+}

Powered by Google App Engine
This is Rietveld 408576698