OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_QUOTA_QUOTA_DATABASE_H_ | 5 #ifndef WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
6 #define WEBKIT_QUOTA_QUOTA_DATABASE_H_ | 6 #define WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 public: | 35 public: |
36 // If 'path' is empty, an in memory database will be used. | 36 // If 'path' is empty, an in memory database will be used. |
37 explicit QuotaDatabase(const FilePath& path); | 37 explicit QuotaDatabase(const FilePath& path); |
38 ~QuotaDatabase(); | 38 ~QuotaDatabase(); |
39 | 39 |
40 void CloseConnection(); | 40 void CloseConnection(); |
41 | 41 |
42 bool GetHostQuota(const std::string& host, StorageType type, int64* quota); | 42 bool GetHostQuota(const std::string& host, StorageType type, int64* quota); |
43 bool SetHostQuota(const std::string& host, StorageType type, int64 quota); | 43 bool SetHostQuota(const std::string& host, StorageType type, int64 quota); |
44 | 44 |
45 bool SetOriginLastAccessTime(const GURL& origin, StorageType type, | 45 bool SetOriginLastAccessTime(const GURL& origin, |
46 StorageType type, | |
46 base::Time last_access_time); | 47 base::Time last_access_time); |
47 | 48 |
49 bool SetOriginLastModifiedTime(const GURL& origin, | |
50 StorageType type, | |
51 base::Time last_modified_time); | |
52 | |
48 // Register |origins| to Database with |used_count| = 0 and | 53 // Register |origins| to Database with |used_count| = 0 and |
49 // specified |last_access_time|. | 54 // specified |last_access_time|. Last modified time for the |
55 // registered origin will be initialized to 0. | |
Mike West
2011/06/16 09:39:33
Isn't the origin being modified at `base::Time::No
kinuko
2011/06/16 12:09:06
The naming might be confusing here, this is a one-
| |
50 bool RegisterOrigins(const std::set<GURL>& origins, | 56 bool RegisterOrigins(const std::set<GURL>& origins, |
51 StorageType type, | 57 StorageType type, |
52 base::Time last_access_time); | 58 base::Time last_access_time); |
53 | 59 |
54 bool DeleteHostQuota(const std::string& host, StorageType type); | 60 bool DeleteHostQuota(const std::string& host, StorageType type); |
Mike West
2011/06/16 09:39:33
Maybe move this up to live with `GetHostQuota` and
kinuko
2011/06/16 12:09:06
Done.
| |
55 bool DeleteOriginLastAccessTime(const GURL& origin, StorageType type); | 61 bool DeleteOriginInfo(const GURL& origin, StorageType type); |
56 | 62 |
57 bool GetGlobalQuota(StorageType type, int64* quota); | 63 bool GetGlobalQuota(StorageType type, int64* quota); |
58 bool SetGlobalQuota(StorageType type, int64 quota); | 64 bool SetGlobalQuota(StorageType type, int64 quota); |
59 | 65 |
60 // Sets |origin| to the least recently used origin of origins not included | 66 // Sets |origin| to the least recently used origin of origins not included |
61 // in |exceptions| and not granted the special unlimited storage right. | 67 // in |exceptions| and not granted the special unlimited storage right. |
62 // It returns false when it failed in accessing the database. | 68 // It returns false when it failed in accessing the database. |
63 // |origin| is set to empty when there is no matching origin. | 69 // |origin| is set to empty when there is no matching origin. |
64 bool GetLRUOrigin(StorageType type, | 70 bool GetLRUOrigin(StorageType type, |
65 const std::set<GURL>& exceptions, | 71 const std::set<GURL>& exceptions, |
66 SpecialStoragePolicy* special_storage_policy, | 72 SpecialStoragePolicy* special_storage_policy, |
67 GURL* origin); | 73 GURL* origin); |
68 | 74 |
75 // Populates |origins| with the ones that have been modified since | |
76 // the |modified_since|. | |
77 bool GetOriginsModifiedSince(StorageType type, | |
78 std::set<GURL>* origins, | |
79 base::Time modified_since); | |
80 | |
69 // Returns false if SetOriginDatabaseBootstrapped has never | 81 // Returns false if SetOriginDatabaseBootstrapped has never |
70 // been called before, which means existing origins may not have been | 82 // been called before, which means existing origins may not have been |
71 // registered. | 83 // registered. |
72 bool IsOriginDatabaseBootstrapped(); | 84 bool IsOriginDatabaseBootstrapped(); |
73 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); | 85 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); |
74 | 86 |
75 private: | 87 private: |
76 struct QuotaTableEntry { | 88 struct QuotaTableEntry { |
77 std::string host; | 89 std::string host; |
78 StorageType type; | 90 StorageType type; |
79 int64 quota; | 91 int64 quota; |
80 }; | 92 }; |
81 friend bool operator <(const QuotaTableEntry& lhs, | 93 friend bool operator <(const QuotaTableEntry& lhs, |
82 const QuotaTableEntry& rhs); | 94 const QuotaTableEntry& rhs); |
83 | 95 |
84 struct LastAccessTimeTableEntry { | 96 struct OriginInfoTableEntry { |
85 GURL origin; | 97 GURL origin; |
86 StorageType type; | 98 StorageType type; |
87 int used_count; | 99 int used_count; |
88 base::Time last_access_time; | 100 base::Time last_access_time; |
101 base::Time last_modified_time; | |
89 }; | 102 }; |
90 friend bool operator <(const LastAccessTimeTableEntry& lhs, | 103 friend bool operator <(const OriginInfoTableEntry& lhs, |
91 const LastAccessTimeTableEntry& rhs); | 104 const OriginInfoTableEntry& rhs); |
92 | 105 |
93 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; | 106 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; |
94 typedef base::Callback<bool (const LastAccessTimeTableEntry&)> | 107 typedef base::Callback<bool (const OriginInfoTableEntry&)> |
95 LastAccessTimeTableCallback; | 108 OriginInfoTableCallback; |
96 | 109 |
97 // For long-running transactions support. We always keep a transaction open | 110 // For long-running transactions support. We always keep a transaction open |
98 // so that multiple transactions can be batched. They are flushed | 111 // so that multiple transactions can be batched. They are flushed |
99 // with a delay after a modification has been made. We support neither | 112 // with a delay after a modification has been made. We support neither |
100 // nested transactions nor rollback (as we don't need them for now). | 113 // nested transactions nor rollback (as we don't need them for now). |
101 void Commit(); | 114 void Commit(); |
102 void ScheduleCommit(); | 115 void ScheduleCommit(); |
103 | 116 |
104 bool FindOriginUsedCount(const GURL& origin, | 117 bool FindOriginUsedCount(const GURL& origin, |
105 StorageType type, | 118 StorageType type, |
106 int* used_count); | 119 int* used_count); |
107 | 120 |
108 bool LazyOpen(bool create_if_needed); | 121 bool LazyOpen(bool create_if_needed); |
109 bool EnsureDatabaseVersion(); | 122 bool EnsureDatabaseVersion(); |
110 bool CreateSchema(); | 123 bool CreateSchema(); |
111 bool ResetSchema(); | 124 bool ResetSchema(); |
112 | 125 |
113 // |callback| may return false to stop reading data | 126 // |callback| may return false to stop reading data. |
114 bool DumpQuotaTable(QuotaTableCallback* callback); | 127 bool DumpQuotaTable(QuotaTableCallback* callback); |
115 bool DumpLastAccessTimeTable(LastAccessTimeTableCallback* callback); | 128 bool DumpOriginInfoTable(OriginInfoTableCallback* callback); |
116 | |
117 | 129 |
118 FilePath db_file_path_; | 130 FilePath db_file_path_; |
119 | 131 |
120 scoped_ptr<sql::Connection> db_; | 132 scoped_ptr<sql::Connection> db_; |
121 scoped_ptr<sql::MetaTable> meta_table_; | 133 scoped_ptr<sql::MetaTable> meta_table_; |
122 bool is_recreating_; | 134 bool is_recreating_; |
123 bool is_disabled_; | 135 bool is_disabled_; |
124 | 136 |
125 base::OneShotTimer<QuotaDatabase> timer_; | 137 base::OneShotTimer<QuotaDatabase> timer_; |
126 | 138 |
127 friend class QuotaDatabaseTest; | 139 friend class QuotaDatabaseTest; |
128 friend class QuotaManager; | 140 friend class QuotaManager; |
129 | 141 |
130 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); | 142 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); |
131 }; | 143 }; |
132 | 144 |
133 } // namespace quota | 145 } // namespace quota |
134 | 146 |
135 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ | 147 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
OLD | NEW |