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