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

Unified Diff: chrome/browser/ui/ash/palette_delegate_chromeos.cc

Issue 2258553004: Add pref to enable/disable palette tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Initial upload Created 4 years, 4 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/ash/palette_delegate_chromeos.cc
diff --git a/chrome/browser/ui/ash/palette_delegate_chromeos.cc b/chrome/browser/ui/ash/palette_delegate_chromeos.cc
index 0342a30c08b6f48a81a9f6cb3efed1d5a9b91b31..a68c7b34032ab3430d617cb710a7bb1a809378ad 100644
--- a/chrome/browser/ui/ash/palette_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/palette_delegate_chromeos.cc
@@ -4,10 +4,92 @@
#include "chrome/browser/ui/ash/palette_delegate_chromeos.h"
+#include "ash/shell.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/pref_names.h"
+#include "components/prefs/pref_change_registrar.h"
+#include "components/prefs/pref_service.h"
+#include "components/user_manager/user_manager.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+
namespace chromeos {
-PaletteDelegateChromeOS::PaletteDelegateChromeOS() {}
+PaletteDelegateChromeOS::PaletteDelegateChromeOS() {
+ registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
+ content::NotificationService::AllSources());
+ registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
+ content::NotificationService::AllSources());
+}
PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {}
+std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription>
+PaletteDelegateChromeOS::AddPaletteEnableListener(
+ const EnableListener& on_state_changed) {
+ auto subscription = callback_list_.Add(on_state_changed);
+ OnPaletteEnabledPrefChanged();
+ return subscription;
+}
+
+void PaletteDelegateChromeOS::ActiveUserChanged(const AccountId& account_id) {
+ const user_manager::User* user =
+ user_manager::UserManager::Get()->FindUser(account_id);
+ Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
+ SetProfile(profile);
+}
+
+void PaletteDelegateChromeOS::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_SESSION_STARTED:
+ // Update |profile_| when entering a session.
+ SetProfile(ProfileManager::GetActiveUserProfile());
+
+ // Add a session state observer to be able to monitor session changes.
+ if (!session_state_observer_.get() && ash::Shell::HasInstance()) {
+ session_state_observer_.reset(
+ new ash::ScopedSessionStateObserver(this));
+ }
+ break;
+ case chrome::NOTIFICATION_PROFILE_DESTROYED: {
+ // Update |profile_| when exiting a session or shutting down.
+ Profile* profile = content::Source<Profile>(source).ptr();
+ if (profile_ == profile)
+ SetProfile(nullptr);
+ break;
+ }
+ }
+}
+
+void PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged() {
+ if (profile_) {
+ callback_list_.Notify(
+ profile_->GetPrefs()->GetBoolean(prefs::kEnableAshPalette));
+ }
+}
+
+void PaletteDelegateChromeOS::SetProfile(Profile* profile) {
+ profile_ = profile;
+ pref_change_registrar_.reset();
+
+ if (profile_) {
stevenjb 2016/08/23 17:36:41 if (!profile_) return;
jdufault 2016/08/23 22:49:56 Done.
+ PrefService* prefs = profile_->GetPrefs();
+ pref_change_registrar_.reset(new PrefChangeRegistrar);
+ pref_change_registrar_->Init(prefs);
+ pref_change_registrar_->Add(
+ prefs::kEnableAshPalette,
+ base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged,
+ base::Unretained(this)));
+
+ // Run listener with new pref value, if any.
+ OnPaletteEnabledPrefChanged();
+ }
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698