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 23 matching lines...) Expand all Loading... |
34 class QuotaDatabase { | 34 class QuotaDatabase { |
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 bool DeleteHostQuota(const std::string& host, StorageType type); |
44 | 45 |
45 bool SetOriginLastAccessTime(const GURL& origin, StorageType type, | 46 bool SetOriginLastAccessTime(const GURL& origin, |
| 47 StorageType type, |
46 base::Time last_access_time); | 48 base::Time last_access_time); |
47 | 49 |
48 // Register |origins| to Database with |used_count| = 0 and | 50 bool SetOriginLastModifiedTime(const GURL& origin, |
49 // specified |last_access_time|. | 51 StorageType type, |
50 bool RegisterOrigins(const std::set<GURL>& origins, | 52 base::Time last_modified_time); |
51 StorageType type, | |
52 base::Time last_access_time); | |
53 | 53 |
54 bool DeleteHostQuota(const std::string& host, StorageType type); | 54 // Register initial |origins| info |type| to the database. |
55 bool DeleteOriginLastAccessTime(const GURL& origin, StorageType type); | 55 // This method is assumed to be called only after the installation or |
| 56 // the database schema reset. |
| 57 bool RegisterInitialOriginInfo( |
| 58 const std::set<GURL>& origins, StorageType type); |
| 59 |
| 60 bool DeleteOriginInfo(const GURL& origin, StorageType type); |
56 | 61 |
57 bool GetGlobalQuota(StorageType type, int64* quota); | 62 bool GetGlobalQuota(StorageType type, int64* quota); |
58 bool SetGlobalQuota(StorageType type, int64 quota); | 63 bool SetGlobalQuota(StorageType type, int64 quota); |
59 | 64 |
60 // Sets |origin| to the least recently used origin of origins not included | 65 // Sets |origin| to the least recently used origin of origins not included |
61 // in |exceptions| and not granted the special unlimited storage right. | 66 // in |exceptions| and not granted the special unlimited storage right. |
62 // It returns false when it failed in accessing the database. | 67 // It returns false when it failed in accessing the database. |
63 // |origin| is set to empty when there is no matching origin. | 68 // |origin| is set to empty when there is no matching origin. |
64 bool GetLRUOrigin(StorageType type, | 69 bool GetLRUOrigin(StorageType type, |
65 const std::set<GURL>& exceptions, | 70 const std::set<GURL>& exceptions, |
66 SpecialStoragePolicy* special_storage_policy, | 71 SpecialStoragePolicy* special_storage_policy, |
67 GURL* origin); | 72 GURL* origin); |
68 | 73 |
| 74 // Populates |origins| with the ones that have been modified since |
| 75 // the |modified_since|. |
| 76 bool GetOriginsModifiedSince(StorageType type, |
| 77 std::set<GURL>* origins, |
| 78 base::Time modified_since); |
| 79 |
69 // Returns false if SetOriginDatabaseBootstrapped has never | 80 // Returns false if SetOriginDatabaseBootstrapped has never |
70 // been called before, which means existing origins may not have been | 81 // been called before, which means existing origins may not have been |
71 // registered. | 82 // registered. |
72 bool IsOriginDatabaseBootstrapped(); | 83 bool IsOriginDatabaseBootstrapped(); |
73 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); | 84 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); |
74 | 85 |
75 private: | 86 private: |
76 struct QuotaTableEntry { | 87 struct QuotaTableEntry { |
77 std::string host; | 88 std::string host; |
78 StorageType type; | 89 StorageType type; |
79 int64 quota; | 90 int64 quota; |
80 }; | 91 }; |
81 friend bool operator <(const QuotaTableEntry& lhs, | 92 friend bool operator <(const QuotaTableEntry& lhs, |
82 const QuotaTableEntry& rhs); | 93 const QuotaTableEntry& rhs); |
83 | 94 |
84 struct LastAccessTimeTableEntry { | 95 struct OriginInfoTableEntry { |
85 GURL origin; | 96 GURL origin; |
86 StorageType type; | 97 StorageType type; |
87 int used_count; | 98 int used_count; |
88 base::Time last_access_time; | 99 base::Time last_access_time; |
| 100 base::Time last_modified_time; |
89 }; | 101 }; |
90 friend bool operator <(const LastAccessTimeTableEntry& lhs, | 102 friend bool operator <(const OriginInfoTableEntry& lhs, |
91 const LastAccessTimeTableEntry& rhs); | 103 const OriginInfoTableEntry& rhs); |
92 | 104 |
93 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; | 105 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; |
94 typedef base::Callback<bool (const LastAccessTimeTableEntry&)> | 106 typedef base::Callback<bool (const OriginInfoTableEntry&)> |
95 LastAccessTimeTableCallback; | 107 OriginInfoTableCallback; |
96 | 108 |
97 // For long-running transactions support. We always keep a transaction open | 109 // For long-running transactions support. We always keep a transaction open |
98 // so that multiple transactions can be batched. They are flushed | 110 // so that multiple transactions can be batched. They are flushed |
99 // with a delay after a modification has been made. We support neither | 111 // 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). | 112 // nested transactions nor rollback (as we don't need them for now). |
101 void Commit(); | 113 void Commit(); |
102 void ScheduleCommit(); | 114 void ScheduleCommit(); |
103 | 115 |
104 bool FindOriginUsedCount(const GURL& origin, | 116 bool FindOriginUsedCount(const GURL& origin, |
105 StorageType type, | 117 StorageType type, |
106 int* used_count); | 118 int* used_count); |
107 | 119 |
108 bool LazyOpen(bool create_if_needed); | 120 bool LazyOpen(bool create_if_needed); |
109 bool EnsureDatabaseVersion(); | 121 bool EnsureDatabaseVersion(); |
110 bool CreateSchema(); | 122 bool CreateSchema(); |
111 bool ResetSchema(); | 123 bool ResetSchema(); |
112 | 124 |
113 // |callback| may return false to stop reading data | 125 // |callback| may return false to stop reading data. |
114 bool DumpQuotaTable(QuotaTableCallback* callback); | 126 bool DumpQuotaTable(QuotaTableCallback* callback); |
115 bool DumpLastAccessTimeTable(LastAccessTimeTableCallback* callback); | 127 bool DumpOriginInfoTable(OriginInfoTableCallback* callback); |
116 | |
117 | 128 |
118 FilePath db_file_path_; | 129 FilePath db_file_path_; |
119 | 130 |
120 scoped_ptr<sql::Connection> db_; | 131 scoped_ptr<sql::Connection> db_; |
121 scoped_ptr<sql::MetaTable> meta_table_; | 132 scoped_ptr<sql::MetaTable> meta_table_; |
122 bool is_recreating_; | 133 bool is_recreating_; |
123 bool is_disabled_; | 134 bool is_disabled_; |
124 | 135 |
125 base::OneShotTimer<QuotaDatabase> timer_; | 136 base::OneShotTimer<QuotaDatabase> timer_; |
126 | 137 |
127 friend class QuotaDatabaseTest; | 138 friend class QuotaDatabaseTest; |
128 friend class QuotaManager; | 139 friend class QuotaManager; |
129 | 140 |
130 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); | 141 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); |
131 }; | 142 }; |
132 | 143 |
133 } // namespace quota | 144 } // namespace quota |
134 | 145 |
135 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ | 146 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
OLD | NEW |