Skip to content

Commit

Permalink
Introduces NotificationBlocker.
Browse files Browse the repository at this point in the history
This CL replaces the existing blocking code by the new notification
blocker implementations. The new implementation detects the current
status more precisely, and each platform can implement different
blocking behaviors.

BUG=256404, 260060
TEST=covered by new tests
R=dewittj@chromium.org, stevenjb@chromium.org

Review URL: https://chromiumcodereview.appspot.com/23694021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222698 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mukai@chromium.org committed Sep 12, 2013
1 parent 85ac048 commit b78d79a
Show file tree
Hide file tree
Showing 49 changed files with 1,260 additions and 598 deletions.
2 changes: 1 addition & 1 deletion ash/display/display_error_observer_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void DisplayErrorObserver::OnDisplayModeChangeFailed(
base::string16(), // message
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16(), // display_source
message_center::NotifierId(NOTIFIER_DISPLAY_ERROR),
message_center::NotifierId(system_notifier::NOTIFIER_DISPLAY_ERROR),
message_center::RichNotificationData(),
NULL));
message_center::MessageCenter::Get()->AddNotification(notification.Pass());
Expand Down
3 changes: 2 additions & 1 deletion ash/display/resolution_notification_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void ResolutionNotificationController::CreateOrUpdateNotification(
timeout_message,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_DISPLAY_RESOLUTION_CHANGE),
message_center::NotifierId(
system_notifier::NOTIFIER_DISPLAY_RESOLUTION_CHANGE),
data,
new ResolutionChangeNotificationDelegate(
this, change_info_->timeout_count > 0)));
Expand Down
3 changes: 2 additions & 1 deletion ash/system/chromeos/managed/tray_locally_managed_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void TrayLocallyManagedUser::CreateOrUpdateNotification(
base::string16() /* body is empty */,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_MANAGED_USER),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_LOCALLY_MANAGED_USER),
message_center::NotifierId(
system_notifier::NOTIFIER_LOCALLY_MANAGED_USER),
message_center::RichNotificationData(),
NULL /* no delegate */));
notification->SetSystemPriority();
Expand Down
2 changes: 1 addition & 1 deletion ash/system/chromeos/network/network_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void ShowMobileSetup(const std::string& service_path) {
UTF8ToUTF16(cellular->name())),
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED),
ash::NOTIFIER_NETWORK,
ash::system_notifier::NOTIFIER_NETWORK,
base::Bind(&ash::network_connect::ShowNetworkSettings,
service_path)));
return;
Expand Down
4 changes: 2 additions & 2 deletions ash/system/chromeos/network/network_state_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void ShowErrorNotification(const std::string& notification_id,
title,
message,
icon,
ash::NOTIFIER_NETWORK_ERROR,
ash::system_notifier::NOTIFIER_NETWORK_ERROR,
callback));
}

Expand Down Expand Up @@ -189,7 +189,7 @@ void NetworkStateNotifier::UpdateCellularActivating(
l10n_util::GetStringFUTF16(IDS_NETWORK_CELLULAR_ACTIVATED,
UTF8ToUTF16((cellular->name()))),
icon,
NOTIFIER_NETWORK,
system_notifier::NOTIFIER_NETWORK,
base::Bind(&ash::network_connect::ShowNetworkSettings,
cellular->path())));
}
Expand Down
2 changes: 1 addition & 1 deletion ash/system/chromeos/power/tray_power.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ bool TrayPower::MaybeShowUsbChargerNotification() {
rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE),
rb.GetImageNamed(IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER),
base::string16(),
message_center::NotifierId(NOTIFIER_POWER),
message_center::NotifierId(system_notifier::NOTIFIER_POWER),
message_center::RichNotificationData(),
NULL));
message_center_->AddNotification(notification.Pass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
base::string16() /* body is blank */,
resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_SCREEN_CAPTURE),
message_center::NotifierId(system_notifier::NOTIFIER_SCREEN_CAPTURE),
data,
new tray::ScreenNotificationDelegate(this)));
notification->SetSystemPriority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ScreenShareTrayItem::CreateOrUpdateNotification() {
base::string16() /* body is blank */,
resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_SCREEN_SHARE),
message_center::NotifierId(system_notifier::NOTIFIER_SCREEN_SHARE),
data,
new tray::ScreenNotificationDelegate(this)));
notification->SetSystemPriority();
Expand Down
2 changes: 1 addition & 1 deletion ash/system/chromeos/tray_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void TrayDisplay::CreateOrUpdateNotification(
additional_message,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16(), // display_source
message_center::NotifierId(NOTIFIER_DISPLAY),
message_center::NotifierId(system_notifier::NOTIFIER_DISPLAY),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickedDelegate(
base::Bind(&OpenSettings))));
Expand Down
2 changes: 1 addition & 1 deletion ash/system/ime/tray_ime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void TrayIME::UpdateOrCreateNotification() {
base::string16(), // message
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME),
base::string16(), // display_source
message_center::NotifierId(NOTIFIER_INPUT_METHOD),
message_center::NotifierId(system_notifier::NOTIFIER_INPUT_METHOD),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickedDelegate(
base::Bind(&TrayIME::PopupDetailedView,
Expand Down
2 changes: 1 addition & 1 deletion ash/system/locale/locale_notification_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void LocaleNotificationController::OnLocaleChanged(
base::string16() /* message */,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_LOCALE),
message_center::NotifierId(system_notifier::NOTIFIER_LOCALE),
optional,
new LocaleNotificationDelegate(delegate)));
message_center::MessageCenter::Get()->AddNotification(notification.Pass());
Expand Down
3 changes: 2 additions & 1 deletion ash/system/session_length_limit/tray_session_length_limit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ void CreateOrUpdateNotification(const base::TimeDelta& remaining_time,
base::string16() /* message */,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SESSION_LENGTH_LIMIT_TIMER),
base::string16() /* display_source */,
message_center::NotifierId(NOTIFIER_SESSION_LENGTH_TIMEOUT),
message_center::NotifierId(
system_notifier::NOTIFIER_SESSION_LENGTH_TIMEOUT),
data,
NULL /* delegate */));
notification->SetSystemPriority();
Expand Down
2 changes: 0 additions & 2 deletions ash/system/status_area_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ void StatusAreaWidget::UpdateAfterLoginStatusChange(
login_status_ = login_status;
if (system_tray_)
system_tray_->UpdateAfterLoginStatusChange(login_status);
if (web_notification_tray_)
web_notification_tray_->UpdateAfterLoginStatusChange(login_status);
if (logout_button_tray_)
logout_button_tray_->UpdateAfterLoginStatusChange(login_status);
}
Expand Down
27 changes: 26 additions & 1 deletion ash/system/system_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
#include "base/logging.h"

namespace ash {
namespace system_notifier {

namespace {

// See http://dev.chromium.org/chromium-os/chromiumos-design-docs/
// system-notifications for the reasoning.
const AshSystemComponentNotifierType kAlwaysShownNotifierIds[] = {
NOTIFIER_DISPLAY,
NOTIFIER_DISPLAY_ERROR,
NOTIFIER_POWER,
};

} // namespace

std::string SystemComponentTypeToString(AshSystemComponentNotifierType type) {
if (type == NOTIFIER_SCREENSHOT)
Expand All @@ -17,4 +30,16 @@ std::string SystemComponentTypeToString(AshSystemComponentNotifierType type) {
return std::string();
}

} // namespace
bool ShouldAlwaysShowPopups(const message_center::NotifierId& notifier_id) {
if (notifier_id.type != message_center::NotifierId::SYSTEM_COMPONENT)
return false;

for (size_t i = 0; i < arraysize(kAlwaysShownNotifierIds); ++i) {
if (notifier_id.system_component_type == kAlwaysShownNotifierIds[i])
return true;
}
return false;
}

} // namespace system_notifier
} // namespace ash
9 changes: 9 additions & 0 deletions ash/system/system_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include <string>

#include "ash/ash_export.h"
#include "ui/message_center/notifier_settings.h"

namespace ash {
namespace system_notifier {

enum AshSystemComponentNotifierType {
NOTIFIER_NO_SYSTEM_COMPONENT = -1,
Expand All @@ -33,6 +35,13 @@ enum AshSystemComponentNotifierType {
ASH_EXPORT std::string SystemComponentTypeToString(
AshSystemComponentNotifierType type);

// Returns true if notifications from |notifier_id| should always appear as
// popups. "Always appear" means the popups should appear even in login screen,
// lock screen, or fullscreen state.
ASH_EXPORT bool ShouldAlwaysShowPopups(
const message_center::NotifierId& notifier_id);

} // namespace system_notifier
} // namespace ash

#endif // ASH_SYSTEM_SYSTEM_NOTIFIER_H_
20 changes: 1 addition & 19 deletions ash/system/web_notification/web_notification_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ void WebNotificationTray::SetSystemTrayHeight(int height) {
}

bool WebNotificationTray::ShowPopups() {
if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED ||
message_center_bubble()) {
if (message_center_bubble())
return false;
}

popup_collection_.reset(new message_center::MessagePopupCollection(
ash::Shell::GetContainer(
Expand All @@ -431,22 +429,6 @@ bool WebNotificationTray::ShouldShowMessageCenter() {
status_area_widget()->system_tray()->HasNotificationBubble());
}

void WebNotificationTray::UpdateAfterLoginStatusChange(
user::LoginStatus login_status) {
if (login_status == user::LOGGED_IN_LOCKED) {
show_message_center_on_unlock_ =
message_center_tray_->HideMessageCenterBubble();
message_center_tray_->HidePopupBubble();
} else {
// Only try once to show the message center bubble on login status change,
// so always set |show_message_center_on_unlock_| to false.
if (show_message_center_on_unlock_)
message_center_tray_->ShowMessageCenterBubble();
show_message_center_on_unlock_ = false;
}
OnMessageCenterTrayChanged();
}

bool WebNotificationTray::ShouldBlockLauncherAutoHide() const {
return should_block_shelf_auto_hide_;
}
Expand Down
3 changes: 0 additions & 3 deletions ash/system/web_notification/web_notification_tray.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ class ASH_EXPORT WebNotificationTray
// shown in the system tray side.
void SetSystemTrayHeight(int height);

// Updates tray visibility login status of the system changes.
void UpdateAfterLoginStatusChange(user::LoginStatus login_status);

// Returns true if it should block the auto hide behavior of the launcher.
bool ShouldBlockLauncherAutoHide() const;

Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/status/data_promo_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification() {
base::string16() /* title */,
message,
icon,
ash::NOTIFIER_NETWORK,
ash::system_notifier::NOTIFIER_NETWORK,
base::Bind(&NotificationClicked,
default_network->path(), info_url)));

Expand Down
Loading

0 comments on commit b78d79a

Please sign in to comment.