Commit 028168c8 authored by Matthew Mourgos's avatar Matthew Mourgos Committed by Commit Bot

CrOS: Hide shelf and launcher app badges when quiet mode is enabled.

This change makes ShelfController and AppListControllerImpl a
MessageCenterObserver. This allows them to hide/show the app badges from
being shown whenever quiet mode is enabled/disabled.

Bug: 1130940
Change-Id: Ia26890b266b1d8ba26529afddf8347f21729bfb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436859Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811877}
parent 85491b31
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/message_center/message_center.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/wm/core/coordinate_conversion.h" #include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/public/activation_client.h" #include "ui/wm/public/activation_client.h"
...@@ -215,6 +216,7 @@ AppListControllerImpl::AppListControllerImpl() ...@@ -215,6 +216,7 @@ AppListControllerImpl::AppListControllerImpl()
shell->mru_window_tracker()->AddObserver(this); shell->mru_window_tracker()->AddObserver(this);
AssistantController::Get()->AddObserver(this); AssistantController::Get()->AddObserver(this);
AssistantUiController::Get()->GetModel()->AddObserver(this); AssistantUiController::Get()->GetModel()->AddObserver(this);
message_center::MessageCenter::Get()->AddObserver(this);
} }
AppListControllerImpl::~AppListControllerImpl() { AppListControllerImpl::~AppListControllerImpl() {
...@@ -1802,6 +1804,7 @@ void AppListControllerImpl::Shutdown() { ...@@ -1802,6 +1804,7 @@ void AppListControllerImpl::Shutdown() {
is_shutdown_ = true; is_shutdown_ = true;
Shell* shell = Shell::Get(); Shell* shell = Shell::Get();
message_center::MessageCenter::Get()->RemoveObserver(this);
AssistantController::Get()->RemoveObserver(this); AssistantController::Get()->RemoveObserver(this);
AssistantUiController::Get()->GetModel()->RemoveObserver(this); AssistantUiController::Get()->GetModel()->RemoveObserver(this);
shell->mru_window_tracker()->RemoveObserver(this); shell->mru_window_tracker()->RemoveObserver(this);
...@@ -1831,7 +1834,8 @@ gfx::Rect AppListControllerImpl::GetInitialAppListItemScreenBoundsForWindow( ...@@ -1831,7 +1834,8 @@ gfx::Rect AppListControllerImpl::GetInitialAppListItemScreenBoundsForWindow(
void AppListControllerImpl::OnAppUpdate(const apps::AppUpdate& update) { void AppListControllerImpl::OnAppUpdate(const apps::AppUpdate& update) {
if (update.HasBadgeChanged() && if (update.HasBadgeChanged() &&
notification_badging_pref_enabled_.value_or(false)) { notification_badging_pref_enabled_.value_or(false) &&
!quiet_mode_enabled_.value_or(false)) {
UpdateItemNotificationBadge(update.AppId(), update.HasBadge()); UpdateItemNotificationBadge(update.AppId(), update.HasBadge());
} }
} }
...@@ -1841,6 +1845,10 @@ void AppListControllerImpl::OnAppRegistryCacheWillBeDestroyed( ...@@ -1841,6 +1845,10 @@ void AppListControllerImpl::OnAppRegistryCacheWillBeDestroyed(
Observe(nullptr); Observe(nullptr);
} }
void AppListControllerImpl::OnQuietModeChanged(bool in_quiet_mode) {
UpdateAppBadging();
}
void AppListControllerImpl::UpdateTrackedAppWindow() { void AppListControllerImpl::UpdateTrackedAppWindow() {
aura::Window* top_window = GetTopVisibleWindow(); aura::Window* top_window = GetTopVisibleWindow();
if (tracked_app_window_ == top_window) if (tracked_app_window_ == top_window)
...@@ -1867,22 +1875,28 @@ void AppListControllerImpl::UpdateItemNotificationBadge( ...@@ -1867,22 +1875,28 @@ void AppListControllerImpl::UpdateItemNotificationBadge(
} }
void AppListControllerImpl::UpdateAppBadging() { void AppListControllerImpl::UpdateAppBadging() {
DCHECK(pref_change_registrar_); bool new_badging_enabled = pref_change_registrar_
PrefService* prefs = pref_change_registrar_->prefs(); ? pref_change_registrar_->prefs()->GetBoolean(
prefs::kAppNotificationBadgingEnabled)
: false;
bool new_quiet_mode_enabled =
message_center::MessageCenter::Get()->IsQuietMode();
bool new_badging_enabled =
prefs->GetBoolean(prefs::kAppNotificationBadgingEnabled);
if (notification_badging_pref_enabled_.has_value() && if (notification_badging_pref_enabled_.has_value() &&
notification_badging_pref_enabled_.value() == new_badging_enabled) { notification_badging_pref_enabled_.value() == new_badging_enabled &&
quiet_mode_enabled_.has_value() &&
quiet_mode_enabled_.value() == new_quiet_mode_enabled) {
return; return;
} }
notification_badging_pref_enabled_ = new_badging_enabled; notification_badging_pref_enabled_ = new_badging_enabled;
quiet_mode_enabled_ = new_quiet_mode_enabled;
if (cache_) { if (cache_) {
cache_->ForEachApp([this](const apps::AppUpdate& update) { cache_->ForEachApp([this](const apps::AppUpdate& update) {
// Set the app notification badge hidden when the pref is disabled. // Set the app notification badge hidden when the pref is disabled.
apps::mojom::OptionalBool has_badge = apps::mojom::OptionalBool has_badge =
notification_badging_pref_enabled_.value() && notification_badging_pref_enabled_.value() &&
!quiet_mode_enabled_.value() &&
(update.HasBadge() == apps::mojom::OptionalBool::kTrue) (update.HasBadge() == apps::mojom::OptionalBool::kTrue)
? apps::mojom::OptionalBool::kTrue ? apps::mojom::OptionalBool::kTrue
: apps::mojom::OptionalBool::kFalse; : apps::mojom::OptionalBool::kFalse;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "components/sync/model/string_ordinal.h" #include "components/sync/model/string_ordinal.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/message_center/message_center_observer.h"
class PrefChangeRegistrar; class PrefChangeRegistrar;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -69,7 +70,8 @@ class ASH_EXPORT AppListControllerImpl ...@@ -69,7 +70,8 @@ class ASH_EXPORT AppListControllerImpl
public AssistantControllerObserver, public AssistantControllerObserver,
public AssistantUiModelObserver, public AssistantUiModelObserver,
public HomeScreenDelegate, public HomeScreenDelegate,
public apps::AppRegistryCache::Observer { public apps::AppRegistryCache::Observer,
public message_center::MessageCenterObserver {
public: public:
AppListControllerImpl(); AppListControllerImpl();
~AppListControllerImpl() override; ~AppListControllerImpl() override;
...@@ -306,6 +308,9 @@ class ASH_EXPORT AppListControllerImpl ...@@ -306,6 +308,9 @@ class ASH_EXPORT AppListControllerImpl
void OnAppRegistryCacheWillBeDestroyed( void OnAppRegistryCacheWillBeDestroyed(
apps::AppRegistryCache* cache) override; apps::AppRegistryCache* cache) override;
// message_center::MessageCenterObserver:
void OnQuietModeChanged(bool in_quiet_mode) override;
bool onscreen_keyboard_shown() const { return onscreen_keyboard_shown_; } bool onscreen_keyboard_shown() const { return onscreen_keyboard_shown_; }
HomeLauncherTransitionState home_launcher_transition_state() const { HomeLauncherTransitionState home_launcher_transition_state() const {
...@@ -494,6 +499,9 @@ class ASH_EXPORT AppListControllerImpl ...@@ -494,6 +499,9 @@ class ASH_EXPORT AppListControllerImpl
// Whether the pref for notification badging is enabled. // Whether the pref for notification badging is enabled.
base::Optional<bool> notification_badging_pref_enabled_; base::Optional<bool> notification_badging_pref_enabled_;
// Whether quiet mode is currently enabled.
base::Optional<bool> quiet_mode_enabled_;
DISALLOW_COPY_AND_ASSIGN(AppListControllerImpl); DISALLOW_COPY_AND_ASSIGN(AppListControllerImpl);
}; };
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/message_center/message_center.h"
namespace ash { namespace ash {
...@@ -108,6 +109,7 @@ ShelfController::ShelfController() ...@@ -108,6 +109,7 @@ ShelfController::ShelfController()
Shell::Get()->tablet_mode_controller()->AddObserver(this); Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->window_tree_host_manager()->AddObserver(this); Shell::Get()->window_tree_host_manager()->AddObserver(this);
model_.AddObserver(this); model_.AddObserver(this);
message_center::MessageCenter::Get()->AddObserver(this);
} }
ShelfController::~ShelfController() { ShelfController::~ShelfController() {
...@@ -115,6 +117,7 @@ ShelfController::~ShelfController() { ...@@ -115,6 +117,7 @@ ShelfController::~ShelfController() {
} }
void ShelfController::Shutdown() { void ShelfController::Shutdown() {
message_center::MessageCenter::Get()->RemoveObserver(this);
model_.RemoveObserver(this); model_.RemoveObserver(this);
Shell::Get()->window_tree_host_manager()->RemoveObserver(this); Shell::Get()->window_tree_host_manager()->RemoveObserver(this);
Shell::Get()->tablet_mode_controller()->RemoveObserver(this); Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
...@@ -222,7 +225,8 @@ void ShelfController::OnDisplayConfigurationChanged() { ...@@ -222,7 +225,8 @@ void ShelfController::OnDisplayConfigurationChanged() {
void ShelfController::OnAppUpdate(const apps::AppUpdate& update) { void ShelfController::OnAppUpdate(const apps::AppUpdate& update) {
if (update.HasBadgeChanged() && if (update.HasBadgeChanged() &&
notification_badging_pref_enabled_.value_or(false)) { notification_badging_pref_enabled_.value_or(false) &&
!quiet_mode_enabled_.value_or(false)) {
bool has_badge = update.HasBadge() == apps::mojom::OptionalBool::kTrue; bool has_badge = update.HasBadge() == apps::mojom::OptionalBool::kTrue;
model_.UpdateItemNotification(update.AppId(), has_badge); model_.UpdateItemNotification(update.AppId(), has_badge);
} }
...@@ -247,23 +251,33 @@ void ShelfController::ShelfItemAdded(int index) { ...@@ -247,23 +251,33 @@ void ShelfController::ShelfItemAdded(int index) {
}); });
} }
void ShelfController::OnQuietModeChanged(bool in_quiet_mode) {
UpdateAppBadging();
}
void ShelfController::UpdateAppBadging() { void ShelfController::UpdateAppBadging() {
DCHECK(pref_change_registrar_); bool new_badging_enabled = pref_change_registrar_
PrefService* prefs = pref_change_registrar_->prefs(); ? pref_change_registrar_->prefs()->GetBoolean(
prefs::kAppNotificationBadgingEnabled)
: false;
bool new_quiet_mode_enabled =
message_center::MessageCenter::Get()->IsQuietMode();
bool new_badging_enabled =
prefs->GetBoolean(prefs::kAppNotificationBadgingEnabled);
if (notification_badging_pref_enabled_.has_value() && if (notification_badging_pref_enabled_.has_value() &&
notification_badging_pref_enabled_.value() == new_badging_enabled) { notification_badging_pref_enabled_.value() == new_badging_enabled &&
quiet_mode_enabled_.has_value() &&
quiet_mode_enabled_.value() == new_quiet_mode_enabled) {
return; return;
} }
notification_badging_pref_enabled_ = new_badging_enabled; notification_badging_pref_enabled_ = new_badging_enabled;
quiet_mode_enabled_ = new_quiet_mode_enabled;
if (cache_) { if (cache_) {
cache_->ForEachApp([this](const apps::AppUpdate& update) { cache_->ForEachApp([this](const apps::AppUpdate& update) {
// Set the app notification badge hidden when the pref is disabled. // Set the app notification badge hidden when the pref is disabled.
bool has_badge = bool has_badge =
notification_badging_pref_enabled_.value() notification_badging_pref_enabled_.value() &&
!quiet_mode_enabled_.value()
? (update.HasBadge() == apps::mojom::OptionalBool::kTrue) ? (update.HasBadge() == apps::mojom::OptionalBool::kTrue)
: false; : false;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "components/services/app_service/public/cpp/app_registry_cache.h" #include "components/services/app_service/public/cpp/app_registry_cache.h"
#include "components/services/app_service/public/cpp/app_update.h" #include "components/services/app_service/public/cpp/app_update.h"
#include "ui/message_center/message_center_observer.h"
class PrefChangeRegistrar; class PrefChangeRegistrar;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -25,11 +26,13 @@ namespace ash { ...@@ -25,11 +26,13 @@ namespace ash {
// ShelfController owns the ShelfModel and manages shelf preferences. // ShelfController owns the ShelfModel and manages shelf preferences.
// ChromeLauncherController and related classes largely manage the ShelfModel. // ChromeLauncherController and related classes largely manage the ShelfModel.
class ASH_EXPORT ShelfController : public SessionObserver, class ASH_EXPORT ShelfController
public TabletModeObserver, : public SessionObserver,
public WindowTreeHostManager::Observer, public TabletModeObserver,
public apps::AppRegistryCache::Observer, public WindowTreeHostManager::Observer,
public ShelfModelObserver { public apps::AppRegistryCache::Observer,
public ShelfModelObserver,
public message_center::MessageCenterObserver {
public: public:
ShelfController(); ShelfController();
~ShelfController() override; ~ShelfController() override;
...@@ -60,6 +63,9 @@ class ASH_EXPORT ShelfController : public SessionObserver, ...@@ -60,6 +63,9 @@ class ASH_EXPORT ShelfController : public SessionObserver,
// ShelfModelObserver: // ShelfModelObserver:
void ShelfItemAdded(int index) override; void ShelfItemAdded(int index) override;
// message_center::MessageCenterObserver:
void OnQuietModeChanged(bool in_quiet_mode) override;
// Updates whether an app badge is shown for the shelf items in the model. // Updates whether an app badge is shown for the shelf items in the model.
void UpdateAppBadging(); void UpdateAppBadging();
...@@ -72,6 +78,9 @@ class ASH_EXPORT ShelfController : public SessionObserver, ...@@ -72,6 +78,9 @@ class ASH_EXPORT ShelfController : public SessionObserver,
// Whether the pref for notification badging is enabled. // Whether the pref for notification badging is enabled.
base::Optional<bool> notification_badging_pref_enabled_; base::Optional<bool> notification_badging_pref_enabled_;
// Whether quiet mode is currently enabled.
base::Optional<bool> quiet_mode_enabled_;
// Observes user profile prefs for the shelf. // Observes user profile prefs for the shelf.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment