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