Chromium Code Reviews| 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/ui/low_disk_notification.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "ash/common/system/system_notifier.h" | |
| 10 #include "base/bind.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "chrome/browser/browser_process.h" | |
| 14 #include "chrome/grit/generated_resources.h" | |
| 15 #include "chromeos/dbus/cryptohome_client.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/base/resource/resource_bundle.h" | |
| 18 #include "ui/chromeos/resources/grit/ui_chromeos_resources.h" | |
| 19 #include "ui/message_center/message_center.h" | |
| 20 #include "ui/message_center/notification.h" | |
| 21 #include "ui/message_center/notification_types.h" | |
| 22 #include "ui/message_center/notifier_settings.h" | |
| 23 | |
| 24 namespace { | |
| 25 const char kLowDiskId[] = "low_disk"; | |
| 26 const uint64_t kNotificationThreshold = 1 << 30; // 1GB | |
| 27 const uint64_t kNotificationSevereThreshold = 512 << 20; // 512MB | |
| 28 const base::TimeDelta kNotificationInterval = base::TimeDelta::FromMinutes(2); | |
|
yoshiki
2016/06/23 08:00:45
constexpr is better than const.
dspaid
2016/06/27 05:40:04
Done.
| |
| 29 } // namespace | |
| 30 | |
| 31 namespace chromeos { | |
| 32 | |
| 33 LowDiskNotification::LowDiskNotification(CryptohomeClient* cryptohome_client) | |
| 34 : cryptohome_client_(cryptohome_client) { | |
|
yoshiki
2016/06/23 08:00:45
I think it's better to use DBusThreadManager::Get(
dspaid
2016/06/27 05:40:04
Done.
| |
| 35 if (cryptohome_client_) { | |
|
yoshiki
2016/06/23 08:00:45
cryptohome_client_ is necessary for this class, so
dspaid
2016/06/27 05:40:04
Done.
| |
| 36 cryptohome_client_->SetLowDiskSpaceHandler(base::Bind( | |
| 37 &LowDiskNotification::OnLowDiskSpace, base::Unretained(this))); | |
|
yoshiki
2016/06/23 08:00:45
You might need to close the notification when the
dspaid
2016/06/27 05:40:04
We don't actually have this information. Notifica
| |
| 38 } | |
| 39 } | |
| 40 | |
| 41 LowDiskNotification::~LowDiskNotification() { | |
|
yoshiki
2016/06/23 08:00:45
Please DCHECK(DBusThreadManager::Get()->GetCryptoh
dspaid
2016/06/27 05:40:04
Done.
| |
| 42 if (cryptohome_client_) | |
| 43 cryptohome_client_->ResetLowDiskSpaceHandler(); | |
| 44 } | |
| 45 | |
| 46 void LowDiskNotification::OnLowDiskSpace(uint64_t free_disk_bytes) { | |
| 47 LOG(ERROR) << "LowDiskNotification received"; | |
| 48 Severity severity = GetSeverity(free_disk_bytes); | |
| 49 base::Time now = base::Time::Now(); | |
| 50 if (severity > last_notification_severity_ || | |
|
yoshiki
2016/06/23 08:00:45
Shouldn't we update the notification content when
dspaid
2016/06/27 05:40:04
Done.
| |
| 51 now - last_notification_time_ > kNotificationInterval) { | |
| 52 g_browser_process->message_center()->AddNotification( | |
|
yoshiki
2016/06/23 08:00:45
You shouldn't pass nullptr to AddNotification.
dspaid
2016/06/27 05:40:04
Done.
| |
| 53 CreateNotification(severity)); | |
| 54 last_notification_time_ = now; | |
| 55 last_notification_severity_ = severity; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 std::unique_ptr<message_center::Notification> | |
| 60 LowDiskNotification::CreateNotification(Severity severity) { | |
| 61 std::unique_ptr<message_center::Notification> notification; | |
| 62 switch (severity) { | |
| 63 case MEDIUM: | |
| 64 notification = message_center::Notification::CreateSystemNotification( | |
| 65 kLowDiskId, | |
| 66 l10n_util::GetStringUTF16(IDS_LOW_DISK_NOTIFICATION_TITLE), | |
|
yoshiki
2016/06/23 08:00:45
Did you forget to add the string grd file to this
dspaid
2016/06/27 05:40:04
They were in a separate change which has now been
| |
| 67 l10n_util::GetStringUTF16(IDS_LOW_DISK_NOTIFICATION_MESSAGE), | |
| 68 gfx::Image(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 69 IDR_DISK_SPACE_NOTIFICATION_LOW)), | |
| 70 ash::system_notifier::kNotifierDisk, base::Closure()); | |
| 71 break; | |
| 72 case HIGH: | |
| 73 notification = message_center::Notification::CreateSystemNotification( | |
|
yoshiki
2016/06/23 08:00:45
Parhaps, pinned notification is better?
https://cs
dspaid
2016/06/27 05:40:04
Done.
| |
| 74 kLowDiskId, | |
| 75 l10n_util::GetStringUTF16(IDS_CRITICALLY_LOW_DISK_NOTIFICATION_TITLE), | |
| 76 l10n_util::GetStringUTF16( | |
| 77 IDS_CRITICALLY_LOW_DISK_NOTIFICATION_MESSAGE), | |
| 78 gfx::Image(ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 79 IDR_DISK_SPACE_NOTIFICATION_CRITICAL)), | |
| 80 ash::system_notifier::kNotifierDisk, base::Closure()); | |
| 81 break; | |
| 82 default: | |
| 83 return nullptr; | |
| 84 } | |
| 85 std::vector<message_center::ButtonInfo> buttons; | |
| 86 buttons.push_back(message_center::ButtonInfo( | |
| 87 l10n_util::GetStringUTF16(IDS_LOW_DISK_NOTIFICATION_BUTTON))); | |
|
yoshiki
2016/06/23 08:00:45
Don't you add a click handler for this button?
dspaid
2016/06/27 05:40:04
Done.
| |
| 88 notification->set_buttons(buttons); | |
| 89 return notification; | |
| 90 } | |
| 91 | |
| 92 LowDiskNotification::Severity LowDiskNotification::GetSeverity( | |
| 93 uint64_t free_disk_bytes) { | |
| 94 if (free_disk_bytes < kNotificationSevereThreshold) | |
| 95 return Severity::HIGH; | |
| 96 if (free_disk_bytes < kNotificationThreshold) | |
| 97 return Severity::MEDIUM; | |
| 98 return Severity::NONE; | |
| 99 } | |
| 100 | |
| 101 } // namespace chromeos | |
| OLD | NEW |