| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/display/display_error_observer_chromeos.h" | 5 #include "ash/display/display_error_observer_chromeos.h" |
| 6 | 6 |
| 7 #include <cinttypes> | |
| 8 #include <utility> | 7 #include <utility> |
| 9 | 8 |
| 10 #include "ash/new_window_delegate.h" | |
| 11 #include "ash/shell.h" | |
| 12 #include "ash/system/system_notifier.h" | 9 #include "ash/system/system_notifier.h" |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
| 15 #include "grit/ash_strings.h" | 11 #include "grit/ash_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/message_center/message_center.h" | 14 #include "ui/message_center/message_center.h" |
| 19 #include "ui/message_center/notification.h" | 15 #include "ui/message_center/notification.h" |
| 20 #include "ui/message_center/notification_delegate.h" | 16 #include "ui/message_center/notification_delegate.h" |
| 21 #include "ui/message_center/notification_list.h" | 17 #include "ui/message_center/notification_list.h" |
| 22 | 18 |
| 23 using message_center::Notification; | 19 using message_center::Notification; |
| 24 | 20 |
| 25 namespace ash { | 21 namespace ash { |
| 26 namespace { | 22 namespace { |
| 27 | 23 |
| 28 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; | 24 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; |
| 29 | 25 |
| 30 // A notification delegate that will start the feedback app when the notication | |
| 31 // is clicked. | |
| 32 class DisplayErrorNotificationDelegate | |
| 33 : public message_center::NotificationDelegate { | |
| 34 public: | |
| 35 DisplayErrorNotificationDelegate() = default; | |
| 36 | |
| 37 // message_center::NotificationDelegate: | |
| 38 bool HasClickedListener() override { return true; } | |
| 39 | |
| 40 void Click() override { | |
| 41 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 // Private destructor since NotificationDelegate is ref-counted. | |
| 46 ~DisplayErrorNotificationDelegate() override = default; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); | |
| 49 }; | |
| 50 | |
| 51 } // namespace | 26 } // namespace |
| 52 | 27 |
| 53 DisplayErrorObserver::DisplayErrorObserver() { | 28 DisplayErrorObserver::DisplayErrorObserver() { |
| 54 } | 29 } |
| 55 | 30 |
| 56 DisplayErrorObserver::~DisplayErrorObserver() { | 31 DisplayErrorObserver::~DisplayErrorObserver() { |
| 57 } | 32 } |
| 58 | 33 |
| 59 void DisplayErrorObserver::OnDisplayModeChangeFailed( | 34 void DisplayErrorObserver::OnDisplayModeChangeFailed( |
| 60 const ui::DisplayConfigurator::DisplayStateList& displays, | 35 const ui::DisplayConfigurator::DisplayStateList& displays, |
| 61 ui::MultipleDisplayState new_state) { | 36 ui::MultipleDisplayState new_state) { |
| 62 LOG(ERROR) << "Failed to configure the following display(s):"; | |
| 63 for (const auto& display : displays) { | |
| 64 LOG(ERROR) << "- Display with ID = " << display->display_id() | |
| 65 << ", and EDID = " << base::HexEncode(display->edid().data(), | |
| 66 display->edid().size()) | |
| 67 << "."; | |
| 68 } | |
| 69 | |
| 70 // Always remove the notification to make sure the notification appears | 37 // Always remove the notification to make sure the notification appears |
| 71 // as a popup in any situation. | 38 // as a popup in any situation. |
| 72 message_center::MessageCenter::Get()->RemoveNotification( | 39 message_center::MessageCenter::Get()->RemoveNotification( |
| 73 kDisplayErrorNotificationId, false /* by_user */); | 40 kDisplayErrorNotificationId, false /* by_user */); |
| 74 | 41 |
| 75 int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ? | 42 int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ? |
| 76 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING : | 43 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING : |
| 77 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING; | 44 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING; |
| 78 | 45 |
| 79 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 46 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 80 scoped_ptr<Notification> notification(new Notification( | 47 scoped_ptr<Notification> notification(new Notification( |
| 81 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, | 48 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, |
| 82 base::string16(), // title | 49 base::string16(), // title |
| 83 l10n_util::GetStringUTF16(message_id), | 50 l10n_util::GetStringUTF16(message_id), |
| 84 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 51 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
| 85 base::string16(), // display_source | 52 base::string16(), // display_source |
| 86 GURL(), | 53 GURL(), |
| 87 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 54 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| 88 system_notifier::kNotifierDisplayError), | 55 system_notifier::kNotifierDisplayError), |
| 89 message_center::RichNotificationData(), | 56 message_center::RichNotificationData(), NULL)); |
| 90 new DisplayErrorNotificationDelegate)); | |
| 91 message_center::MessageCenter::Get()->AddNotification( | 57 message_center::MessageCenter::Get()->AddNotification( |
| 92 std::move(notification)); | 58 std::move(notification)); |
| 93 } | 59 } |
| 94 | 60 |
| 95 base::string16 | 61 base::string16 |
| 96 DisplayErrorObserver::GetDisplayErrorNotificationMessageForTest() { | 62 DisplayErrorObserver::GetDisplayErrorNotificationMessageForTest() { |
| 97 message_center::NotificationList::Notifications notifications = | 63 message_center::NotificationList::Notifications notifications = |
| 98 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 64 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 99 for (message_center::NotificationList::Notifications::const_iterator iter = | 65 for (message_center::NotificationList::Notifications::const_iterator iter = |
| 100 notifications.begin(); iter != notifications.end(); ++iter) { | 66 notifications.begin(); iter != notifications.end(); ++iter) { |
| 101 if ((*iter)->id() == kDisplayErrorNotificationId) | 67 if ((*iter)->id() == kDisplayErrorNotificationId) |
| 102 return (*iter)->message(); | 68 return (*iter)->message(); |
| 103 } | 69 } |
| 104 | 70 |
| 105 return base::string16(); | 71 return base::string16(); |
| 106 } | 72 } |
| 107 | 73 |
| 108 } // namespace ash | 74 } // namespace ash |
| OLD | NEW |