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"
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
{
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.
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.
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.
42 // If set to true, the observer will be dispatched an event when added.
43 bool dispatch_initial_state
;
46 MonitorParams(StorageType storage_type
,
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.
59 // The current usage corresponding to the filter.
62 // The quota corresponding to the filter.
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;
74 virtual ~StorageObserver() {}
77 } // namespace storage
79 #endif // STORAGE_BROWSER_QUOTA_STORAGE_OBSERVER_H_