| 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 { |
| 88 QuotaTableEntry(); |
| 89 QuotaTableEntry( |
| 90 const std::string& host, |
| 91 StorageType type, |
| 92 int64 quota); |
| 77 std::string host; | 93 std::string host; |
| 78 StorageType type; | 94 StorageType type; |
| 79 int64 quota; | 95 int64 quota; |
| 80 }; | 96 }; |
| 81 friend bool operator <(const QuotaTableEntry& lhs, | 97 friend bool operator <(const QuotaTableEntry& lhs, |
| 82 const QuotaTableEntry& rhs); | 98 const QuotaTableEntry& rhs); |
| 83 | 99 |
| 84 struct LastAccessTimeTableEntry { | 100 struct OriginInfoTableEntry { |
| 101 OriginInfoTableEntry(); |
| 102 OriginInfoTableEntry( |
| 103 const GURL& origin, |
| 104 StorageType type, |
| 105 int used_count, |
| 106 const base::Time& last_access_time, |
| 107 const base::Time& last_modified_time); |
| 85 GURL origin; | 108 GURL origin; |
| 86 StorageType type; | 109 StorageType type; |
| 87 int used_count; | 110 int used_count; |
| 88 base::Time last_access_time; | 111 base::Time last_access_time; |
| 112 base::Time last_modified_time; |
| 89 }; | 113 }; |
| 90 friend bool operator <(const LastAccessTimeTableEntry& lhs, | 114 friend bool operator <(const OriginInfoTableEntry& lhs, |
| 91 const LastAccessTimeTableEntry& rhs); | 115 const OriginInfoTableEntry& rhs); |
| 116 |
| 117 // Structures used for CreateSchema. |
| 118 struct TableSchema { |
| 119 const char* table_name; |
| 120 const char* columns; |
| 121 }; |
| 122 struct IndexSchema { |
| 123 const char* index_name; |
| 124 const char* table_name; |
| 125 const char* columns; |
| 126 bool unique; |
| 127 }; |
| 92 | 128 |
| 93 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; | 129 typedef base::Callback<bool (const QuotaTableEntry&)> QuotaTableCallback; |
| 94 typedef base::Callback<bool (const LastAccessTimeTableEntry&)> | 130 typedef base::Callback<bool (const OriginInfoTableEntry&)> |
| 95 LastAccessTimeTableCallback; | 131 OriginInfoTableCallback; |
| 132 |
| 133 struct QuotaTableImporter; |
| 96 | 134 |
| 97 // For long-running transactions support. We always keep a transaction open | 135 // For long-running transactions support. We always keep a transaction open |
| 98 // so that multiple transactions can be batched. They are flushed | 136 // so that multiple transactions can be batched. They are flushed |
| 99 // with a delay after a modification has been made. We support neither | 137 // 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). | 138 // nested transactions nor rollback (as we don't need them for now). |
| 101 void Commit(); | 139 void Commit(); |
| 102 void ScheduleCommit(); | 140 void ScheduleCommit(); |
| 103 | 141 |
| 104 bool FindOriginUsedCount(const GURL& origin, | 142 bool FindOriginUsedCount(const GURL& origin, |
| 105 StorageType type, | 143 StorageType type, |
| 106 int* used_count); | 144 int* used_count); |
| 107 | 145 |
| 108 bool LazyOpen(bool create_if_needed); | 146 bool LazyOpen(bool create_if_needed); |
| 109 bool EnsureDatabaseVersion(); | 147 bool EnsureDatabaseVersion(); |
| 110 bool CreateSchema(); | |
| 111 bool ResetSchema(); | 148 bool ResetSchema(); |
| 149 bool UpgradeSchema(int current_version); |
| 112 | 150 |
| 113 // |callback| may return false to stop reading data | 151 static bool CreateSchema( |
| 152 sql::Connection* database, |
| 153 sql::MetaTable* meta_table, |
| 154 int schema_version, int compatible_version, |
| 155 const TableSchema* tables, size_t tables_size, |
| 156 const IndexSchema* indexes, size_t indexes_size); |
| 157 |
| 158 // |callback| may return false to stop reading data. |
| 114 bool DumpQuotaTable(QuotaTableCallback* callback); | 159 bool DumpQuotaTable(QuotaTableCallback* callback); |
| 115 bool DumpLastAccessTimeTable(LastAccessTimeTableCallback* callback); | 160 bool DumpOriginInfoTable(OriginInfoTableCallback* callback); |
| 116 | |
| 117 | 161 |
| 118 FilePath db_file_path_; | 162 FilePath db_file_path_; |
| 119 | 163 |
| 120 scoped_ptr<sql::Connection> db_; | 164 scoped_ptr<sql::Connection> db_; |
| 121 scoped_ptr<sql::MetaTable> meta_table_; | 165 scoped_ptr<sql::MetaTable> meta_table_; |
| 122 bool is_recreating_; | 166 bool is_recreating_; |
| 123 bool is_disabled_; | 167 bool is_disabled_; |
| 124 | 168 |
| 125 base::OneShotTimer<QuotaDatabase> timer_; | 169 base::OneShotTimer<QuotaDatabase> timer_; |
| 126 | 170 |
| 127 friend class QuotaDatabaseTest; | 171 friend class QuotaDatabaseTest; |
| 128 friend class QuotaManager; | 172 friend class QuotaManager; |
| 129 | 173 |
| 174 static const TableSchema kTables[]; |
| 175 static const IndexSchema kIndexes[]; |
| 176 |
| 130 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); | 177 DISALLOW_COPY_AND_ASSIGN(QuotaDatabase); |
| 131 }; | 178 }; |
| 132 | 179 |
| 133 } // namespace quota | 180 } // namespace quota |
| 134 | 181 |
| 135 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ | 182 #endif // WEBKIT_QUOTA_QUOTA_DATABASE_H_ |
| OLD | NEW |