Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: ash/display/display_error_observer_chromeos.cc

Issue 1636153002: Give user ability to file a feedback report from the display error notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix errors Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/stringprintf.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() {}
oshima 2016/01/27 09:18:14 = default. (this seems to be allowed now)
afakhry 2016/01/29 02:16:51 Done.
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 {}
oshima 2016/01/27 09:18:14 ditto
afakhry 2016/01/29 02:16:51 Done.
47
48 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate);
49 };
50
51 // Returns an error message to be logged when there is a failure in changing
52 // the display mode, so that it shows in the system logs when the user files
53 // a feedback report.
54 std::string CreateErrorLogMessage(
55 const ui::DisplayConfigurator::DisplayStateList& displays) {
56 std::string error_log_message(
57 "Failed to configure the following display(s):\n");
58 for (const auto& display : displays) {
59 base::StringAppendF(&error_log_message,
60 "\t- Display with ID = %" PRId64 ", and EDID = ",
61 display->display_id());
62
63 for (const auto& edid_byte : display->edid())
64 base::StringAppendF(&error_log_message, "%02X", edid_byte);
oshima 2016/01/27 09:18:14 base::HexEncode?
afakhry 2016/01/29 02:16:51 Done.
65
66 base::StringAppendF(&error_log_message, ".\n");
67 }
68
69 return error_log_message;
oshima 2016/01/27 09:18:14 can't you jus log it to the stream instead of crea
afakhry 2016/01/29 02:16:51 Done.
70 }
71
26 } // namespace 72 } // namespace
27 73
28 DisplayErrorObserver::DisplayErrorObserver() { 74 DisplayErrorObserver::DisplayErrorObserver() {
29 } 75 }
30 76
31 DisplayErrorObserver::~DisplayErrorObserver() { 77 DisplayErrorObserver::~DisplayErrorObserver() {
32 } 78 }
33 79
34 void DisplayErrorObserver::OnDisplayModeChangeFailed( 80 void DisplayErrorObserver::OnDisplayModeChangeFailed(
35 const ui::DisplayConfigurator::DisplayStateList& displays, 81 const ui::DisplayConfigurator::DisplayStateList& displays,
36 ui::MultipleDisplayState new_state) { 82 ui::MultipleDisplayState new_state) {
83 LOG(ERROR) << CreateErrorLogMessage(displays);
84
37 // Always remove the notification to make sure the notification appears 85 // Always remove the notification to make sure the notification appears
38 // as a popup in any situation. 86 // as a popup in any situation.
39 message_center::MessageCenter::Get()->RemoveNotification( 87 message_center::MessageCenter::Get()->RemoveNotification(
40 kDisplayErrorNotificationId, false /* by_user */); 88 kDisplayErrorNotificationId, false /* by_user */);
41 89
42 int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ? 90 int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ?
43 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING : 91 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING :
44 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING; 92 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING;
45 93
46 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
47 scoped_ptr<Notification> notification(new Notification( 95 scoped_ptr<Notification> notification(new Notification(
48 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, 96 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId,
49 base::string16(), // title 97 base::string16(), // title
50 l10n_util::GetStringUTF16(message_id), 98 l10n_util::GetStringUTF16(message_id),
51 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), 99 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
52 base::string16(), // display_source 100 base::string16(), // display_source
53 GURL(), 101 GURL(),
54 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 102 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
55 system_notifier::kNotifierDisplayError), 103 system_notifier::kNotifierDisplayError),
56 message_center::RichNotificationData(), NULL)); 104 message_center::RichNotificationData(),
105 new DisplayErrorNotificationDelegate));
57 message_center::MessageCenter::Get()->AddNotification( 106 message_center::MessageCenter::Get()->AddNotification(
58 std::move(notification)); 107 std::move(notification));
59 } 108 }
60 109
61 base::string16 110 base::string16
62 DisplayErrorObserver::GetDisplayErrorNotificationMessageForTest() { 111 DisplayErrorObserver::GetDisplayErrorNotificationMessageForTest() {
63 message_center::NotificationList::Notifications notifications = 112 message_center::NotificationList::Notifications notifications =
64 message_center::MessageCenter::Get()->GetVisibleNotifications(); 113 message_center::MessageCenter::Get()->GetVisibleNotifications();
65 for (message_center::NotificationList::Notifications::const_iterator iter = 114 for (message_center::NotificationList::Notifications::const_iterator iter =
66 notifications.begin(); iter != notifications.end(); ++iter) { 115 notifications.begin(); iter != notifications.end(); ++iter) {
67 if ((*iter)->id() == kDisplayErrorNotificationId) 116 if ((*iter)->id() == kDisplayErrorNotificationId)
68 return (*iter)->message(); 117 return (*iter)->message();
69 } 118 }
70 119
71 return base::string16(); 120 return base::string16();
72 } 121 }
73 122
74 } // namespace ash 123 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698