• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef WEBKIT_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 quota {
15 
16 // This interface is implemented by observers that wish to monitor storage
17 // events, such as changes in quota or usage.
18 class WEBKIT_STORAGE_BROWSER_EXPORT StorageObserver {
19  public:
20   struct WEBKIT_STORAGE_BROWSER_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 WEBKIT_STORAGE_BROWSER_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 WEBKIT_STORAGE_BROWSER_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:
~StorageObserver()74   virtual ~StorageObserver() {}
75 };
76 
77 }  // namespace quota
78 
79 #endif  // WEBKIT_BROWSER_QUOTA_STORAGE_OBSERVER_H_
80