Revert of Revert of Revert of Revert of Revert of Enable ServiceWorkerPerfTest (servi...
[chromium-blink-merge.git] / ash / display / display_error_observer_chromeos.cc
blob91e07db26008460c77bf17ccebe8a8d8c5b18fe5
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/display_error_observer_chromeos.h"
7 #include "ash/system/system_notifier.h"
8 #include "grit/ash_resources.h"
9 #include "grit/ash_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/message_center/message_center.h"
13 #include "ui/message_center/notification.h"
14 #include "ui/message_center/notification_delegate.h"
15 #include "ui/message_center/notification_list.h"
17 using message_center::Notification;
19 namespace ash {
20 namespace {
22 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error";
24 } // namespace
26 DisplayErrorObserver::DisplayErrorObserver() {
29 DisplayErrorObserver::~DisplayErrorObserver() {
32 void DisplayErrorObserver::OnDisplayModeChangeFailed(
33 const ui::DisplayConfigurator::DisplayStateList& displays,
34 ui::MultipleDisplayState new_state) {
35 // Always remove the notification to make sure the notification appears
36 // as a popup in any situation.
37 message_center::MessageCenter::Get()->RemoveNotification(
38 kDisplayErrorNotificationId, false /* by_user */);
40 int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ?
41 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING :
42 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING;
44 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
45 scoped_ptr<Notification> notification(new Notification(
46 message_center::NOTIFICATION_TYPE_SIMPLE,
47 kDisplayErrorNotificationId,
48 l10n_util::GetStringUTF16(message_id),
49 base::string16(), // message
50 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
51 base::string16(), // display_source
52 message_center::NotifierId(
53 message_center::NotifierId::SYSTEM_COMPONENT,
54 system_notifier::kNotifierDisplayError),
55 message_center::RichNotificationData(),
56 NULL));
57 message_center::MessageCenter::Get()->AddNotification(notification.Pass());
60 base::string16 DisplayErrorObserver::
61 GetTitleOfDisplayErrorNotificationForTest() {
62 message_center::NotificationList::Notifications notifications =
63 message_center::MessageCenter::Get()->GetVisibleNotifications();
64 for (message_center::NotificationList::Notifications::const_iterator iter =
65 notifications.begin(); iter != notifications.end(); ++iter) {
66 if ((*iter)->id() == kDisplayErrorNotificationId)
67 return (*iter)->title();
70 return base::string16();
73 } // namespace ash