Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / storage / browser / quota / storage_observer.h
blob729dadda53fd204a333abedbc295193b18c3f14e
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
3 // found in the LICENSE file.
5 #ifndef STORAGE_BROWSER_QUOTA_STORAGE_OBSERVER_H_
6 #define STORAGE_BROWSER_QUOTA_STORAGE_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "base/time/time.h"
10 #include "storage/browser/quota/quota_client.h"
11 #include "storage/common/quota/quota_types.h"
12 #include "url/gurl.h"
14 namespace storage {
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;
25 // The origin to monitor usage for. Must be specified.
26 GURL origin;
28 Filter();
29 Filter(StorageType storage_type, const GURL& origin);
30 bool operator==(const Filter& other) const;
33 struct STORAGE_EXPORT MonitorParams {
34 // Storage type and origin to monitor.
35 Filter filter;
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;
42 // If set to true, the observer will be dispatched an event when added.
43 bool dispatch_initial_state;
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);
55 struct STORAGE_EXPORT Event {
56 // The storage type and origin monitored.
57 Filter filter;
59 // The current usage corresponding to the filter.
60 int64 usage;
62 // The quota corresponding to the filter.
63 int64 quota;
65 Event();
66 Event(const Filter& filter, int64 usage, int64 quota);
67 bool operator==(const Event& other) const;
70 // Will be called on the IO thread when a storage event occurs.
71 virtual void OnStorageEvent(const Event& event) = 0;
73 protected:
74 virtual ~StorageObserver() {}
77 } // namespace storage
79 #endif // STORAGE_BROWSER_QUOTA_STORAGE_OBSERVER_H_