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

Side by Side Diff: chrome/browser/chromeos/ui/low_disk_notification.h

Issue 2082363004: Show notifications on low disk space. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@low-disk-strings
Patch Set: Switch to thread checker instead of checking for UI thread explicitly Created 4 years, 5 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
(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 #ifndef CHROME_BROWSER_CHROMEOS_UI_LOW_DISK_NOTIFICATION_H_
6 #define CHROME_BROWSER_CHROMEOS_UI_LOW_DISK_NOTIFICATION_H_
7
8 #include <stdint.h>
9
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h"
13 #include "base/time/time.h"
14
15 namespace message_center {
16 class Notification;
17 class MessageCenter;
18 }
19
20 namespace chromeos {
21
22 // LowDiskNotification manages the notification informing the user of low disk
23 // space. It is responsible for both creating the notifications in message
24 // center as well as throttling notifications shown to the user.
25 // This class should be created after DBus has been initialized and destroyed
26 // before DBus has been shutdown.
27 // This class must be instantiated on the UI thread.
28 class LowDiskNotification {
29 public:
30 // Registers this class as the CryptohomeClient LowDiskSpaceHandler.
31 LowDiskNotification();
32
33 // Resets CryptohomeClient LowDiskSpaceHandler.
34 ~LowDiskNotification();
35
36 // Called when the device is running low on disk space. This is responsible
37 // for deciding whether a notification should be shown or not and showing it
38 // if appropriate. This must be called from the thread that instantiated this
39 // object.
40 void OnLowDiskSpace(uint64_t free_disk_bytes);
41
42 private:
43 friend class LowDiskNotificationTest;
44
45 enum Severity { NONE = -1, MEDIUM = 0, HIGH = 1 };
46
47 // Creates a notification for the specified severity. If the severity does
48 // not match a known value MEDIUM is used by default.
49 std::unique_ptr<message_center::Notification> CreateNotification(
50 Severity severity);
51
52 // Gets the severity of the low disk status based on the amount of free space
53 // left on the disk.
54 Severity GetSeverity(uint64_t free_disk_bytes);
55
56 // Sets the MessageCenter instance to use. Should only be used in tests.
57 void SetMessageCenterForTest(message_center::MessageCenter* message_center);
58
59 // Sets the minimum time to wait between notifications of the same severity.
60 // Should only be used in tests.
61 void SetNotificationIntervalForTest(base::TimeDelta interval);
62
63 base::Time last_notification_time_;
64 Severity last_notification_severity_;
65 message_center::MessageCenter* message_center_;
66 base::TimeDelta notification_interval_;
67 base::ThreadChecker thread_checker_;
68 base::WeakPtrFactory<LowDiskNotification> weak_ptr_factory_;
69
70 DISALLOW_COPY_AND_ASSIGN(LowDiskNotification);
71 };
72
73 } // namespace chromeos
74
75 #endif // CHROME_BROWSER_CHROMEOS_UI_LOW_DISK_NOTIFICATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.cc ('k') | chrome/browser/chromeos/ui/low_disk_notification.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698