OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef WEBKIT_BROWSER_QUOTA_STORAGE_OBSERVER_H_ | 5 #include "storage/browser/quota/storage_observer.h" |
6 #define WEBKIT_BROWSER_QUOTA_STORAGE_OBSERVER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/time/time.h" | |
10 #include "url/gurl.h" | |
11 #include "webkit/browser/quota/quota_client.h" | |
12 #include "webkit/common/quota/quota_types.h" | |
13 | |
14 namespace storage { | |
15 | |
16 // This interface is implemented by observers that wish to monitor storage | |
17 // events, such as changes in quota or usage. | |
18 class STORAGE_EXPORT StorageObserver { | |
19 public: | |
20 struct STORAGE_EXPORT Filter { | |
21 // The storage type to monitor. This must not be kStorageTypeUnknown or | |
22 // kStorageTypeQuotaNotManaged. | |
23 StorageType storage_type; | |
24 | |
25 // The origin to monitor usage for. Must be specified. | |
26 GURL origin; | |
27 | |
28 Filter(); | |
29 Filter(StorageType storage_type, const GURL& origin); | |
30 bool operator==(const Filter& other) const; | |
31 }; | |
32 | |
33 struct STORAGE_EXPORT MonitorParams { | |
34 // Storage type and origin to monitor. | |
35 Filter filter; | |
36 | |
37 // The rate at which storage events will be fired. Events will be fired at | |
38 // approximately this rate, or when a storage status change has been | |
39 // detected, whichever is the least frequent. | |
40 base::TimeDelta rate; | |
41 | |
42 // If set to true, the observer will be dispatched an event when added. | |
43 bool dispatch_initial_state; | |
44 | |
45 MonitorParams(); | |
46 MonitorParams(StorageType storage_type, | |
47 const GURL& origin, | |
48 const base::TimeDelta& rate, | |
49 bool get_initial_state); | |
50 MonitorParams(const Filter& filter, | |
51 const base::TimeDelta& rate, | |
52 bool get_initial_state); | |
53 }; | |
54 | |
55 struct STORAGE_EXPORT Event { | |
56 // The storage type and origin monitored. | |
57 Filter filter; | |
58 | |
59 // The current usage corresponding to the filter. | |
60 int64 usage; | |
61 | |
62 // The quota corresponding to the filter. | |
63 int64 quota; | |
64 | |
65 Event(); | |
66 Event(const Filter& filter, int64 usage, int64 quota); | |
67 bool operator==(const Event& other) const; | |
68 }; | |
69 | |
70 // Will be called on the IO thread when a storage event occurs. | |
71 virtual void OnStorageEvent(const Event& event) = 0; | |
72 | |
73 protected: | |
74 virtual ~StorageObserver() {} | |
75 }; | |
76 | |
77 } // namespace storage | |
78 | |
79 #endif // WEBKIT_BROWSER_QUOTA_STORAGE_OBSERVER_H_ | |
OLD | NEW |