Home | History | Annotate | Download | only in display
      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_chromeos.h"
      6 
      7 #include "ash/system/system_notifier.h"
      8 #include "grit/ash_resources.h"
      9 #include "grit/ash_strings.h"
     10 #include "ui/base/l10n/l10n_util.h"
     11 #include "ui/base/resource/resource_bundle.h"
     12 #include "ui/message_center/message_center.h"
     13 #include "ui/message_center/notification.h"
     14 #include "ui/message_center/notification_delegate.h"
     15 #include "ui/message_center/notification_list.h"
     16 
     17 using message_center::Notification;
     18 
     19 namespace ash {
     20 namespace {
     21 
     22 const char kDisplayErrorNotificationId[] = "chrome://settings/display/error";
     23 
     24 }  // namespace
     25 
     26 DisplayErrorObserver::DisplayErrorObserver() {
     27 }
     28 
     29 DisplayErrorObserver::~DisplayErrorObserver() {
     30 }
     31 
     32 void DisplayErrorObserver::OnDisplayModeChangeFailed(
     33     ui::MultipleDisplayState new_state) {
     34   // Always remove the notification to make sure the notification appears
     35   // as a popup in any situation.
     36   message_center::MessageCenter::Get()->RemoveNotification(
     37       kDisplayErrorNotificationId, false /* by_user */);
     38 
     39   int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ?
     40       IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING :
     41       IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING;
     42 
     43   ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
     44   scoped_ptr<Notification> notification(new Notification(
     45       message_center::NOTIFICATION_TYPE_SIMPLE,
     46       kDisplayErrorNotificationId,
     47       l10n_util::GetStringUTF16(message_id),
     48       base::string16(),  // message
     49       bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
     50       base::string16(),  // display_source
     51       message_center::NotifierId(
     52           message_center::NotifierId::SYSTEM_COMPONENT,
     53           system_notifier::kNotifierDisplayError),
     54       message_center::RichNotificationData(),
     55       NULL));
     56   message_center::MessageCenter::Get()->AddNotification(notification.Pass());
     57 }
     58 
     59 base::string16 DisplayErrorObserver::
     60     GetTitleOfDisplayErrorNotificationForTest() {
     61   message_center::NotificationList::Notifications notifications =
     62       message_center::MessageCenter::Get()->GetVisibleNotifications();
     63   for (message_center::NotificationList::Notifications::const_iterator iter =
     64            notifications.begin(); iter != notifications.end(); ++iter) {
     65     if ((*iter)->id() == kDisplayErrorNotificationId)
     66       return (*iter)->title();
     67   }
     68 
     69   return base::string16();
     70 }
     71 
     72 }  // namespace ash
     73