| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "chrome/browser/chromeos/arc/arc_boot_error_notification.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/chrome_pages.h" |
| 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/user_manager/user_manager.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" |
| 16 #include "ui/message_center/message_center.h" |
| 17 #include "ui/message_center/notification.h" |
| 18 #include "ui/message_center/notification_types.h" |
| 19 #include "ui/message_center/notifier_settings.h" |
| 20 |
| 21 namespace arc { |
| 22 |
| 23 namespace { |
| 24 |
| 25 const char kLowDiskSpaceId[] = "arc_low_disk"; |
| 26 const char kNotifierId[] = "arc_boot_error"; |
| 27 const char kDisplaySource[] = "arc_boot_error_source"; |
| 28 const char kStoragePage[] = "storage"; |
| 29 |
| 30 class LowDiskSpaceErrorNotificationDelegate |
| 31 : public message_center::NotificationDelegate { |
| 32 public: |
| 33 LowDiskSpaceErrorNotificationDelegate() = default; |
| 34 |
| 35 // message_center::NotificationDelegate |
| 36 void ButtonClick(int button_index) override { |
| 37 chrome::ShowSettingsSubPageForProfile( |
| 38 ProfileManager::GetActiveUserProfile(), kStoragePage); |
| 39 } |
| 40 |
| 41 private: |
| 42 ~LowDiskSpaceErrorNotificationDelegate() override = default; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(LowDiskSpaceErrorNotificationDelegate); |
| 45 }; |
| 46 |
| 47 void ShowLowDiskSpaceErrorNotification() { |
| 48 message_center::ButtonInfo storage_settings( |
| 49 l10n_util::GetStringUTF16(IDS_LOW_DISK_NOTIFICATION_BUTTON)); |
| 50 storage_settings.icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 51 IDR_STORAGE_MANAGER_BUTTON); |
| 52 message_center::RichNotificationData optional_fields; |
| 53 optional_fields.buttons.push_back(storage_settings); |
| 54 |
| 55 message_center::NotifierId notifier_id( |
| 56 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 57 const AccountId& account_id = |
| 58 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId(); |
| 59 notifier_id.profile_id = account_id.GetUserEmail(); |
| 60 |
| 61 message_center::MessageCenter::Get()->AddNotification( |
| 62 base::MakeUnique<message_center::Notification>( |
| 63 message_center::NOTIFICATION_TYPE_SIMPLE, kLowDiskSpaceId, |
| 64 l10n_util::GetStringUTF16( |
| 65 IDS_ARC_CRITICALLY_LOW_DISK_NOTIFICATION_TITLE), |
| 66 l10n_util::GetStringUTF16( |
| 67 IDS_ARC_CRITICALLY_LOW_DISK_NOTIFICATION_MESSAGE), |
| 68 gfx::Image(ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 69 IDR_DISK_SPACE_NOTIFICATION_CRITICAL)), |
| 70 base::UTF8ToUTF16(kDisplaySource), GURL(), notifier_id, |
| 71 optional_fields, new LowDiskSpaceErrorNotificationDelegate())); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 |
| 76 ArcBootErrorNotification::ArcBootErrorNotification( |
| 77 ArcBridgeService* bridge_service) |
| 78 : ArcService(bridge_service) { |
| 79 arc_bridge_service()->AddObserver(this); |
| 80 } |
| 81 |
| 82 ArcBootErrorNotification::~ArcBootErrorNotification() { |
| 83 arc_bridge_service()->RemoveObserver(this); |
| 84 } |
| 85 |
| 86 void ArcBootErrorNotification::OnBridgeStopped( |
| 87 ArcBridgeService::StopReason reason) { |
| 88 if (reason == ArcBridgeService::StopReason::LOW_DISK_SPACE) { |
| 89 ShowLowDiskSpaceErrorNotification(); |
| 90 } |
| 91 } |
| 92 |
| 93 } // namespace arc |
| OLD | NEW |