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. 4 5 #include "ash/display/display_error_observer.h" 6 7 #include "grit/ash_resources.h" 8 #include "grit/ash_strings.h" 9 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/message_center/message_center.h" 12 #include "ui/message_center/notification.h" 13 #include "ui/message_center/notification_delegate.h" 14 #include "ui/message_center/notification_list.h" 15 16 using message_center::Notification; 17 18 namespace ash { 19 namespace internal { 20 namespace { 21 22 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error"; 23 24 class DisplayErrorNotificationDelegate 25 : public message_center::NotificationDelegate { 26 public: 27 DisplayErrorNotificationDelegate() {} 28 29 // message_center::NotificationDelegate overrides: 30 virtual void Display() OVERRIDE {} 31 virtual void Error() OVERRIDE {} 32 virtual void Close(bool by_user) OVERRIDE {} 33 virtual bool HasClickedListener() OVERRIDE { return false; } 34 virtual void Click() OVERRIDE { } 35 36 protected: 37 virtual ~DisplayErrorNotificationDelegate() {} 38 39 private: 40 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); 41 }; 42 43 } // namespace 44 45 DisplayErrorObserver::DisplayErrorObserver() { 46 } 47 48 DisplayErrorObserver::~DisplayErrorObserver() { 49 } 50 51 void DisplayErrorObserver::OnDisplayModeChangeFailed( 52 chromeos::OutputState new_state) { 53 // Always remove the notification to make sure the notification appears 54 // as a popup in any situation. 55 message_center::MessageCenter::Get()->RemoveNotification( 56 kDisplayErrorNotificationId, false /* by_user */); 57 58 int message_id = (new_state == chromeos::STATE_DUAL_MIRROR) ? 59 IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING : 60 IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING; 61 62 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 63 scoped_ptr<Notification> notification(new Notification( 64 message_center::NOTIFICATION_TYPE_SIMPLE, 65 kDisplayErrorNotificationId, 66 l10n_util::GetStringUTF16(message_id), 67 base::string16(), // message 68 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY), 69 base::string16(), // display_source 70 std::string(), // extension_id 71 message_center::RichNotificationData(), 72 new DisplayErrorNotificationDelegate())); 73 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 74 } 75 76 string16 DisplayErrorObserver::GetTitleOfDisplayErrorNotificationForTest() { 77 message_center::NotificationList::Notifications notifications = 78 message_center::MessageCenter::Get()->GetNotifications(); 79 for (message_center::NotificationList::Notifications::const_iterator iter = 80 notifications.begin(); iter != notifications.end(); ++iter) { 81 if ((*iter)->id() == kDisplayErrorNotificationId) 82 return (*iter)->title(); 83 } 84 85 return base::string16(); 86 } 87 88 } // namespace internal 89 } // namespace ash 90