Skip to content

Commit

Permalink
Cleanup: do not use extension_id, use notifier's id.
Browse files Browse the repository at this point in the history
It will remove unnecessary methods. Also, each ash notifications
has its own notifier id as SYSTEM_COMPONENT. Then we can distinguish
those notification types, which means this will enable to allow
some urgent system notifications (like power) in the lock screen.

BUG=250937
R=dewittj@chromium.org, stevenjb@chromium.org
TEST=no breaks on existing tests

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219437 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mukai@chromium.org committed Aug 24, 2013
1 parent 28fb77a commit a69b6f8
Show file tree
Hide file tree
Showing 49 changed files with 308 additions and 266 deletions.
2 changes: 2 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@
'system/status_area_widget.h',
'system/status_area_widget_delegate.cc',
'system/status_area_widget_delegate.h',
'system/system_notifier.cc',
'system/system_notifier.h',
'system/tray/actionable_view.cc',
'system/tray/actionable_view.h',
'system/tray/fixed_sized_image_view.cc',
Expand Down
3 changes: 2 additions & 1 deletion ash/display/display_error_observer_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ash/display/display_error_observer_chromeos.h"

#include "ash/system/system_notifier.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -67,7 +68,7 @@ void DisplayErrorObserver::OnDisplayModeChangeFailed(
base::string16(), // message
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16(), // display_source
std::string(), // extension_id
message_center::NotifierId(NOTIFIER_DISPLAY_ERROR),
message_center::RichNotificationData(),
new DisplayErrorNotificationDelegate()));
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 @@ -7,6 +7,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
Expand Down Expand Up @@ -224,7 +225,7 @@ void ResolutionNotificationController::CreateOrUpdateNotification() {
timeout_message,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
std::string() /* extension_id */,
message_center::NotifierId(NOTIFIER_DISPLAY_RESOLUTION_CHANGE),
data,
new ResolutionChangeNotificationDelegate(
this, change_info_->timeout_count > 0)));
Expand Down
2 changes: 1 addition & 1 deletion ash/shell/window_type_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
ASCIIToUTF16("Notification message body."),
gfx::Image(),
ASCIIToUTF16("www.testshell.org"),
"" /* extension id */,
message_center::NotifierId(),
message_center::RichNotificationData(),
NULL /* delegate */));

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 @@ -5,6 +5,7 @@
#include "ash/system/chromeos/managed/tray_locally_managed_user.h"

#include "ash/system/chromeos/label_tray_view.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_notification_view.h"
#include "ash/system/user/login_status.h"
Expand Down Expand Up @@ -82,7 +83,7 @@ void TrayLocallyManagedUser::CreateOrUpdateNotification(
base::string16() /* body is empty */,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_MANAGED_USER),
base::string16() /* display_source */,
std::string() /* extension_id */,
message_center::NotifierId(NOTIFIER_LOCALLY_MANAGED_USER),
message_center::RichNotificationData(),
NULL /* no delegate */));
notification->SetSystemPriority();
Expand Down
2 changes: 2 additions & 0 deletions ash/system/chromeos/network/network_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/shell.h"
#include "ash/system/chromeos/network/network_state_notifier.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/bind.h"
Expand Down Expand Up @@ -382,6 +383,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,
base::Bind(&ash::network_connect::ShowNetworkSettings,
service_path)));
return;
Expand Down
9 changes: 8 additions & 1 deletion ash/system/chromeos/network/network_state_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/shell.h"
#include "ash/system/chromeos/network/network_connect.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -60,7 +61,12 @@ void ShowErrorNotification(const std::string& notification_id,
ui::ResourceBundle::GetSharedInstance().GetImageNamed(icon_id);
message_center::MessageCenter::Get()->AddNotification(
message_center::Notification::CreateSystemNotification(
notification_id, title, message, icon, callback));
notification_id,
title,
message,
icon,
ash::NOTIFIER_NETWORK_ERROR,
callback));
}

void ConfigureNetwork(const std::string& service_path) {
Expand Down Expand Up @@ -182,6 +188,7 @@ void NetworkStateNotifier::UpdateCellularActivating(
l10n_util::GetStringFUTF16(IDS_NETWORK_CELLULAR_ACTIVATED,
UTF8ToUTF16((cellular->name()))),
icon,
NOTIFIER_NETWORK,
base::Bind(&ash::network_connect::ShowNetworkSettings,
cellular->path())));
}
Expand Down
3 changes: 2 additions & 1 deletion ash/system/chromeos/power/tray_power.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/ash_switches.h"
#include "ash/system/chromeos/power/power_status_view.h"
#include "ash/system/date/date_view.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_notification_view.h"
#include "ash/system/tray/tray_utils.h"
Expand Down Expand Up @@ -207,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(),
std::string(),
message_center::NotifierId(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 @@ -5,6 +5,7 @@
#include "ash/system/chromeos/screen_security/screen_capture_tray_item.h"

#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -62,7 +63,7 @@ void ScreenCaptureTrayItem::CreateOrUpdateNotification() {
base::string16() /* body is blank */,
resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
std::string() /* extension_id */,
message_center::NotifierId(NOTIFIER_SCREEN_CAPTURE),
data,
new tray::ScreenNotificationDelegate(this)));
notification->SetSystemPriority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/system/chromeos/screen_security/screen_share_tray_item.h"

#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ void ScreenShareTrayItem::CreateOrUpdateNotification() {
base::string16() /* body is blank */,
resource_bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16() /* display_source */,
std::string() /* extension_id */,
message_center::NotifierId(NOTIFIER_SCREEN_SHARE),
data,
new tray::ScreenNotificationDelegate(this)));
notification->SetSystemPriority();
Expand Down
3 changes: 2 additions & 1 deletion ash/system/chromeos/tray_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/system_tray.h"
Expand Down Expand Up @@ -398,7 +399,7 @@ void TrayDisplay::CreateOrUpdateNotification(
additional_message,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY),
base::string16(), // display_source
"", // extension_id
message_center::NotifierId(NOTIFIER_DISPLAY),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickedDelegate(
base::Bind(&OpenSettings,
Expand Down
3 changes: 2 additions & 1 deletion ash/system/ime/tray_ime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
Expand Down Expand Up @@ -230,7 +231,7 @@ void TrayIME::UpdateOrCreateNotification() {
base::string16(), // message
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME),
base::string16(), // display_source
"", // extension_id
message_center::NotifierId(NOTIFIER_INPUT_METHOD),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickedDelegate(
base::Bind(&TrayIME::PopupDetailedView,
Expand Down
3 changes: 2 additions & 1 deletion ash/system/locale/locale_notification_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/system/locale/locale_notification_controller.h"

#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/strings/string16.h"
#include "grit/ash_resources.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ void LocaleNotificationController::OnLocaleChanged(
base::string16() /* message */,
bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE),
base::string16() /* display_source */,
std::string() /* extension_id */,
message_center::NotifierId(NOTIFIER_LOCALE),
optional,
new LocaleNotificationDelegate(delegate)));
message_center::MessageCenter::Get()->AddNotification(notification.Pass());
Expand Down
20 changes: 20 additions & 0 deletions ash/system/system_notifier.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2013 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 "ash/system/system_notifier.h"

#include "base/logging.h"

namespace ash {

std::string SystemComponentTypeToString(AshSystemComponentNotifierType type) {
if (type == NOTIFIER_SCREENSHOT)
return "screenshot";

// TODO(mukai): fill the names of other components.
NOTIMPLEMENTED();
return std::string();
}

} // namespace
37 changes: 37 additions & 0 deletions ash/system/system_notifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2013 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.

#ifndef ASH_SYSTEM_SYSTEM_NOTIFIER_H_
#define ASH_SYSTEM_SYSTEM_NOTIFIER_H_

#include <string>

#include "ash/ash_export.h"

namespace ash {

enum AshSystemComponentNotifierType {
NOTIFIER_NO_SYSTEM_COMPONENT = -1,

// Alphabetical order.
NOTIFIER_DISPLAY,
NOTIFIER_DISPLAY_RESOLUTION_CHANGE,
NOTIFIER_DISPLAY_ERROR,
NOTIFIER_INPUT_METHOD,
NOTIFIER_LOCALE,
NOTIFIER_LOCALLY_MANAGED_USER,
NOTIFIER_NETWORK,
NOTIFIER_NETWORK_ERROR,
NOTIFIER_SCREENSHOT,
NOTIFIER_SCREEN_CAPTURE,
NOTIFIER_SCREEN_SHARE,
NOTIFIER_POWER,
};

ASH_EXPORT std::string SystemComponentTypeToString(
AshSystemComponentNotifierType type);

} // namespace ash

#endif // ASH_SYSTEM_SYSTEM_NOTIFIER_H_
4 changes: 2 additions & 2 deletions ash/system/web_notification/web_notification_tray_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class WebNotificationTrayTest : public test::AshTestBase {
ASCIIToUTF16("Notification message body."),
gfx::Image(),
ASCIIToUTF16("www.test.org"),
"" /* extension id */,
message_center::NotifierId(),
message_center::RichNotificationData(),
NULL /* delegate */));
GetMessageCenter()->AddNotification(notification.Pass());
Expand All @@ -128,7 +128,7 @@ class WebNotificationTrayTest : public test::AshTestBase {
ASCIIToUTF16("Updated message body."),
gfx::Image(),
ASCIIToUTF16("www.test.org"),
"" /* extension id */,
message_center::NotifierId(),
message_center::RichNotificationData(),
NULL /* delegate */));
GetMessageCenter()->UpdateNotification(old_id, notification.Pass());
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/chromeos/status/data_promo_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/system/chromeos/network/network_connect.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "base/prefs/pref_registry_simple.h"
Expand Down Expand Up @@ -226,6 +227,7 @@ void DataPromoNotification::ShowOptionalMobileDataPromoNotification() {
base::string16() /* title */,
message,
icon,
ash::NOTIFIER_NETWORK,
base::Bind(&NotificationClicked,
default_network->path(), info_url)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ bool NotificationsApiFunction::CreateNotification(
message,
icon,
WebKit::WebTextDirectionDefault,
message_center::NotifierId(
message_center::NotifierId::APPLICATION,
extension_->id()),
UTF8ToUTF16(extension_->name()),
UTF8ToUTF16(api_delegate->id()),
optional_fields,
Expand Down
23 changes: 19 additions & 4 deletions chrome/browser/notifications/desktop_notification_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#include "ui/message_center/notifier_settings.h"
#include "ui/webui/web_ui_util.h"

#if defined(OS_CHROMEOS)
#include "ash/system/system_notifier.h"
#endif

using content::BrowserThread;
using content::RenderViewHost;
using content::WebContents;
Expand Down Expand Up @@ -566,9 +570,15 @@ bool DesktopNotificationService::IsNotifierEnabled(
case NotifierId::WEB_PAGE:
return GetContentSetting(notifier_id.url) == CONTENT_SETTING_ALLOW;
case NotifierId::SYSTEM_COMPONENT:
#if defined(OS_CHROMEOS)
return disabled_system_component_ids_.find(
message_center::ToString(notifier_id.system_component_type)) ==
disabled_system_component_ids_.end();
ash::SystemComponentTypeToString(
static_cast<ash::AshSystemComponentNotifierType>(
notifier_id.system_component_type)))
== disabled_system_component_ids_.end();
#else
return false;
#endif
case NotifierId::SYNCED_NOTIFICATION_SERVICE:
return enabled_sync_notifier_ids_.find(notifier_id.id) !=
enabled_sync_notifier_ids_.end();
Expand All @@ -593,10 +603,15 @@ void DesktopNotificationService::SetNotifierEnabled(
id.reset(new base::StringValue(notifier_id.id));
break;
case NotifierId::SYSTEM_COMPONENT:
#if defined(OS_CHROMEOS)
pref_name = prefs::kMessageCenterDisabledSystemComponentIds;
add_new_item = !enabled;
id.reset(new base::StringValue(
message_center::ToString(notifier_id.system_component_type)));
id.reset(new base::StringValue(ash::SystemComponentTypeToString(
static_cast<ash::AshSystemComponentNotifierType>(
notifier_id.system_component_type))));
#else
return;
#endif
break;
case NotifierId::SYNCED_NOTIFICATION_SERVICE:
pref_name = prefs::kMessageCenterEnabledSyncNotifierIds;
Expand Down
Loading

0 comments on commit a69b6f8

Please sign in to comment.