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 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 class GURL; | 27 class GURL; |
28 | 28 |
29 namespace quota { | 29 namespace quota { |
30 | 30 |
31 class SpecialStoragePolicy; | 31 class SpecialStoragePolicy; |
32 | 32 |
33 // All the methods of this class must run on the DB thread. | 33 // All the methods of this class must run on the DB thread. |
34 class QuotaDatabase { | 34 class QuotaDatabase { |
35 public: | 35 public: |
36 // Structures used for CreateSchema. | |
37 // TODO(kinuko): probably they should be defined somewhere else as a common | |
michaeln
2011/07/01 00:17:39
Can these structs be moved to the private section?
kinuko
2011/07/04 07:43:52
Done.
| |
38 // database types/utility. | |
39 struct TableSchema { | |
40 const char* table_name; | |
41 const char* columns; | |
42 }; | |
43 struct IndexSchema { | |
44 const char* index_name; | |
45 const char* table_name; | |
46 const char* columns; | |
47 bool unique; | |
48 }; | |
49 | |
36 // If 'path' is empty, an in memory database will be used. | 50 // If 'path' is empty, an in memory database will be used. |
37 explicit QuotaDatabase(const FilePath& path); | 51 explicit QuotaDatabase(const FilePath& path); |
38 ~QuotaDatabase(); | 52 ~QuotaDatabase(); |
39 | 53 |
40 void CloseConnection(); | 54 void CloseConnection(); |
41 | 55 |
42 bool GetHostQuota(const std::string& host, StorageType type, int64* quota); | 56 bool GetHostQuota(const std::string& host, StorageType type, int64* quota); |
43 bool SetHostQuota(const std::string& host, StorageType type, int64 quota); | 57 bool SetHostQuota(const std::string& host, StorageType type, int64 quota); |
58 bool DeleteHostQuota(const std::string& host, StorageType type); | |
44 | 59 |
45 bool SetOriginLastAccessTime(const GURL& origin, StorageType type, | 60 bool SetOriginLastAccessTime(const GURL& origin, |
61 StorageType type, | |
46 base::Time last_access_time); | 62 base::Time last_access_time); |
47 | 63 |
48 // Register |origins| to Database with |used_count| = 0 and | 64 bool SetOriginLastModifiedTime(const GURL& origin, |
49 // specified |last_access_time|. | 65 StorageType type, |
50 bool RegisterOrigins(const std::set<GURL>& origins, | 66 base::Time last_modified_time); |
51 StorageType type, | |
52 base::Time last_access_time); | |
53 | 67 |
54 bool DeleteHostQuota(const std::string& host, StorageType type); | 68 // Register initial |origins| info |type| to the database. |
55 bool DeleteOriginLastAccessTime(const GURL& origin, StorageType type); | 69 // This method is assumed to be called only after the installation or |
70 // the database schema reset. | |
71 bool RegisterInitialOriginInfo( | |
72 const std::set<GURL>& origins, StorageType type); | |
73 | |
74 bool DeleteOriginInfo(const GURL& origin, StorageType type); | |
56 | 75 |
57 bool GetGlobalQuota(StorageType type, int64* quota); | 76 bool GetGlobalQuota(StorageType type, int64* quota); |
58 bool SetGlobalQuota(StorageType type, int64 quota); | 77 bool SetGlobalQuota(StorageType type, int64 quota); |
59 | 78 |
60 // Sets |origin| to the least recently used origin of origins not included | 79 // Sets |origin| to the least recently used origin of origins not included |
61 // in |exceptions| and not granted the special unlimited storage right. | 80 // in |exceptions| and not granted the special unlimited storage right. |
62 // It returns false when it failed in accessing the database. | 81 // It returns false when it failed in accessing the database. |
63 // |origin| is set to empty when there is no matching origin. | 82 // |origin| is set to empty when there is no matching origin. |
64 bool GetLRUOrigin(StorageType type, | 83 bool GetLRUOrigin(StorageType type, |
65 const std::set<GURL>& exceptions, | 84 const std::set<GURL>& exceptions, |
66 SpecialStoragePolicy* special_storage_policy, | 85 SpecialStoragePolicy* special_storage_policy, |
67 GURL* origin); | 86 GURL* origin); |
68 | 87 |
88 // Populates |origins| with the ones that have been modified since | |
89 // the |modified_since|. | |
90 bool GetOriginsModifiedSince(StorageType type, | |
91 std::set<GURL>* origins, | |
92 base::Time modified_since); | |
93 | |
69 // Returns false if SetOriginDatabaseBootstrapped has never | 94 // Returns false if SetOriginDatabaseBootstrapped has never |
70 // been called before, which means existing origins may not have been | 95 // been called before, which means existing origins may not have been |
71 // registered. | 96 // registered. |
72 bool IsOriginDatabaseBootstrapped(); | 97 bool IsOriginDatabaseBootstrapped(); |
73 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); | 98 bool SetOriginDatabaseBootstrapped(bool bootstrap_flag); |
74 | 99 |
75 private: | 100 private: |
76 struct QuotaTableEntry { | 101 struct QuotaTableEntry { |
77 std::string host; | 102 std::string host; |
78 StorageType type; | 103 StorageType type; |
79 int64 quota; | 104 int64 quota; |
80 }; | 105 }; |
81 friend bool operator <(const QuotaTableEntry& lhs, | 106 friend bool operator <(const QuotaTableEntry& lhs, |
82 const QuotaTableEntry& rhs); | 107 const QuotaTableEntry& rhs); |
83 | 108 |
84 struct LastAccessTimeTableEntry { | 109 struct OriginInfoTableEntry { |
85 GURL origin; | 110 GURL origin; |
86 StorageType type; | 111 StorageType type; |
87 int used_count; | 112 int used_count; |
88 base::Time last_access_time; | 113 base::Time last_access_time; |
114 base::Time last_modified_time; | |
89 }; | 115 }; |
90 friend bool operator <(const LastAccessTimeTableEntry& lhs, | 116 friend bool operator <(const OriginInfoTableEntry& lhs, |
91 const LastAccessTimeTableEntry& rhs); | 117 const OriginInfoTableEntry& rhs); |
92 | 118 |
93 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; | 119 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; |
94 typedef base::Callback<bool (const LastAccessTimeTableEntry&)> | 120 typedef base::Callback<bool (const OriginInfoTableEntry&)> |
95 LastAccessTimeTableCallback; | 121 OriginInfoTableCallback; |
122 | |
123 struct QuotaTableImporter; | |
96 | 124 |
97 // For long-running transactions support. We always keep a transaction open | 125 // For long-running transactions support. We always keep a transaction open |
98 // so that multiple transactions can be batched. They are flushed | 126 // so that multiple transactions can be batched. They are flushed |
99 // with a delay after a modification has been made. We support neither | 127 // 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). | 128 // nested transactions nor rollback (as we don't need them for now). |
101 void Commit(); | 129 void Commit(); |
102 void ScheduleCommit(); | 130 void ScheduleCommit(); |
103 | 131 |
104 bool FindOriginUsedCount(const GURL& origin, | 132 bool FindOriginUsedCount(const GURL& origin, |
105 StorageType type, | 133 StorageType type, |
106 int* used_count); | 134 int* used_count); |
107 | 135 |
108 bool LazyOpen(bool create_if_needed); | 136 bool LazyOpen(bool create_if_needed); |
109 bool EnsureDatabaseVersion(); | 137 bool EnsureDatabaseVersion(); |
110 bool CreateSchema(); | |
111 bool ResetSchema(); | 138 bool ResetSchema(); |
139 bool UpgradeSchema(int current_version); | |
112 | 140 |
113 // |callback| may return false to stop reading data | 141 static bool CreateSchema( |
142 sql::Connection* database, | |
143 sql::MetaTable* meta_table, | |
144 int schema_version, int compatible_version, | |
145 const TableSchema* tables, size_t tables_size, | |
146 const IndexSchema* indexes, size_t indexes_size); | |
147 | |
148 // |callback| may return false to stop reading data. | |
114 bool DumpQuotaTable(QuotaTableCallback* callback); | 149 bool DumpQuotaTable(QuotaTableCallback* callback); |
115 bool DumpLastAccessTimeTable(LastAccessTimeTableCallback* callback); | 150 bool DumpOriginInfoTable(OriginInfoTableCallback* callback); |
116 | |
117 | 151 |
118 FilePath db_file_path_; | 152 FilePath db_file_path_; |
119 | 153 |
120 scoped_ptr<sql::Connection> db_; | 154 scoped_ptr<sql::Connection> db_; |
121 scoped_ptr<sql::MetaTable> meta_table_; | 155 scoped_ptr<sql::MetaTable> meta_table_; |
122 bool is_recreating_; | 156 bool is_recreating_; |
123 bool is_disabled_; | 157 bool is_disabled_; |
124 | 158 |
125 base::OneShotTimer<QuotaDatabase> timer_; | 159 base::OneShotTimer<QuotaDatabase> timer_; |
126 | 160 |
127 friend class QuotaDatabaseTest; | 161 friend class QuotaDatabaseTest; |
128 friend class QuotaManager; | 162 friend class QuotaManager; |
129 | 163 |
130 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); | 164 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); |
131 }; | 165 }; |
132 | 166 |
133 } // namespace quota | 167 } // namespace quota |
134 | 168 |
135 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ | 169 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
OLD | NEW |