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_DATABASE_DATABASE_TRACKER_H_ | 5 #ifndef WEBKIT_DATABASE_DATABASE_TRACKER_H_ |
6 #define WEBKIT_DATABASE_DATABASE_TRACKER_H_ | 6 #define WEBKIT_DATABASE_DATABASE_TRACKER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 public: | 81 public: |
82 virtual void OnDatabaseSizeChanged(const string16& origin_identifier, | 82 virtual void OnDatabaseSizeChanged(const string16& origin_identifier, |
83 const string16& database_name, | 83 const string16& database_name, |
84 int64 database_size) = 0; | 84 int64 database_size) = 0; |
85 virtual void OnDatabaseScheduledForDeletion( | 85 virtual void OnDatabaseScheduledForDeletion( |
86 const string16& origin_identifier, | 86 const string16& origin_identifier, |
87 const string16& database_name) = 0; | 87 const string16& database_name) = 0; |
88 virtual ~Observer() {} | 88 virtual ~Observer() {} |
89 }; | 89 }; |
90 | 90 |
91 DatabaseTracker(const FilePath& profile_path, bool is_incognito, | 91 DatabaseTracker(const FilePath& profile_path, |
| 92 bool is_incognito, |
| 93 bool clear_local_state_on_exit, |
92 quota::SpecialStoragePolicy* special_storage_policy, | 94 quota::SpecialStoragePolicy* special_storage_policy, |
93 quota::QuotaManagerProxy* quota_manager_proxy, | 95 quota::QuotaManagerProxy* quota_manager_proxy, |
94 base::MessageLoopProxy* db_tracker_thread); | 96 base::MessageLoopProxy* db_tracker_thread); |
95 | 97 |
96 void DatabaseOpened(const string16& origin_identifier, | 98 void DatabaseOpened(const string16& origin_identifier, |
97 const string16& database_name, | 99 const string16& database_name, |
98 const string16& database_details, | 100 const string16& database_details, |
99 int64 estimated_size, | 101 int64 estimated_size, |
100 int64* database_size); | 102 int64* database_size); |
101 void DatabaseModified(const string16& origin_identifier, | 103 void DatabaseModified(const string16& origin_identifier, |
(...skipping 14 matching lines...) Expand all Loading... |
116 // virtual for unittesting only | 118 // virtual for unittesting only |
117 virtual bool GetOriginInfo(const string16& origin_id, OriginInfo* info); | 119 virtual bool GetOriginInfo(const string16& origin_id, OriginInfo* info); |
118 virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids); | 120 virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids); |
119 virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info); | 121 virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info); |
120 | 122 |
121 // Safe to call on any thread. | 123 // Safe to call on any thread. |
122 quota::QuotaManagerProxy* quota_manager_proxy() const { | 124 quota::QuotaManagerProxy* quota_manager_proxy() const { |
123 return quota_manager_proxy_.get(); | 125 return quota_manager_proxy_.get(); |
124 } | 126 } |
125 | 127 |
| 128 // Safe to call on any thread. |
| 129 quota::SpecialStoragePolicy* special_storage_policy() const { |
| 130 return special_storage_policy_.get(); |
| 131 } |
| 132 |
| 133 |
126 bool IsDatabaseScheduledForDeletion(const string16& origin_identifier, | 134 bool IsDatabaseScheduledForDeletion(const string16& origin_identifier, |
127 const string16& database_name); | 135 const string16& database_name); |
128 | 136 |
129 // Deletes a single database. Returns net::OK on success, net::FAILED on | 137 // Deletes a single database. Returns net::OK on success, net::FAILED on |
130 // failure, or net::ERR_IO_PENDING and |callback| is invoked upon completion, | 138 // failure, or net::ERR_IO_PENDING and |callback| is invoked upon completion, |
131 // if non-NULL. | 139 // if non-NULL. |
132 int DeleteDatabase(const string16& origin_identifier, | 140 int DeleteDatabase(const string16& origin_identifier, |
133 const string16& database_name, | 141 const string16& database_name, |
134 net::CompletionCallback* callback); | 142 net::CompletionCallback* callback); |
135 | 143 |
136 // Delete any databases that have been touched since the cutoff date that's | 144 // Delete any databases that have been touched since the cutoff date that's |
137 // supplied, omitting any that match IDs within |protected_origins|. | 145 // supplied, omitting any that match IDs within |protected_origins|. |
138 // Returns net::OK on success, net::FAILED if not all databases could be | 146 // Returns net::OK on success, net::FAILED if not all databases could be |
139 // deleted, and net::ERR_IO_PENDING and |callback| is invoked upon completion, | 147 // deleted, and net::ERR_IO_PENDING and |callback| is invoked upon completion, |
140 // if non-NULL. Protected origins, according the the SpecialStoragePolicy, | 148 // if non-NULL. Protected origins, according the the SpecialStoragePolicy, |
141 // are not deleted by this method. | 149 // are not deleted by this method. |
142 int DeleteDataModifiedSince(const base::Time& cutoff, | 150 int DeleteDataModifiedSince(const base::Time& cutoff, |
143 net::CompletionCallback* callback); | 151 net::CompletionCallback* callback); |
144 | 152 |
145 // Delete all databases that belong to the given origin. Returns net::OK on | 153 // Delete all databases that belong to the given origin. Returns net::OK on |
146 // success, net::FAILED if not all databases could be deleted, and | 154 // success, net::FAILED if not all databases could be deleted, and |
147 // net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL. | 155 // net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL. |
148 // virtual for unit testing only | 156 // virtual for unit testing only |
149 virtual int DeleteDataForOrigin(const string16& origin_identifier, | 157 virtual int DeleteDataForOrigin(const string16& origin_identifier, |
150 net::CompletionCallback* callback); | 158 net::CompletionCallback* callback); |
151 | 159 |
| 160 // Delete all files belonging to the given origin given that no database |
| 161 // connections within this origin are open, or if |force| is true, delete |
| 162 // the meta data and rename the associated directory. |
| 163 bool DeleteOrigin(const string16& origin_identifier, bool force); |
| 164 |
152 bool IsIncognitoProfile() const { return is_incognito_; } | 165 bool IsIncognitoProfile() const { return is_incognito_; } |
153 | 166 |
154 void GetIncognitoFileHandle(const string16& vfs_file_path, | 167 void GetIncognitoFileHandle(const string16& vfs_file_path, |
155 base::PlatformFile* file_handle) const; | 168 base::PlatformFile* file_handle) const; |
156 void SaveIncognitoFileHandle(const string16& vfs_file_path, | 169 void SaveIncognitoFileHandle(const string16& vfs_file_path, |
157 const base::PlatformFile& file_handle); | 170 const base::PlatformFile& file_handle); |
158 bool CloseIncognitoFileHandle(const string16& vfs_file_path); | 171 bool CloseIncognitoFileHandle(const string16& vfs_file_path); |
159 bool HasSavedIncognitoFileHandle(const string16& vfs_file_path) const; | 172 bool HasSavedIncognitoFileHandle(const string16& vfs_file_path) const; |
160 | 173 |
161 // Deletes the directory that stores all DBs in incognito mode, if it exists. | 174 // Deletes the directory that stores all DBs in incognito mode, if it exists. |
162 void DeleteIncognitoDBDirectory(); | 175 void DeleteIncognitoDBDirectory(); |
163 | 176 |
164 static void ClearLocalState(const FilePath& profile_path); | 177 // Deletes databases not protected by the special storage policy if |
| 178 // |clear_local_state_on_exit_| is true and blocks databases from being |
| 179 // created/opened. |
| 180 void Shutdown(); |
| 181 void SetClearLocalStateOnExit(bool clear_local_state_on_exit); |
165 | 182 |
166 private: | 183 private: |
167 friend class base::RefCountedThreadSafe<DatabaseTracker>; | 184 friend class base::RefCountedThreadSafe<DatabaseTracker>; |
168 friend class MockDatabaseTracker; // for testing | 185 friend class MockDatabaseTracker; // for testing |
169 | 186 |
170 typedef std::map<string16, std::set<string16> > DatabaseSet; | 187 typedef std::map<string16, std::set<string16> > DatabaseSet; |
171 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap; | 188 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap; |
172 typedef std::map<string16, base::PlatformFile> FileHandlesMap; | 189 typedef std::map<string16, base::PlatformFile> FileHandlesMap; |
173 typedef std::map<string16, string16> OriginDirectoriesMap; | 190 typedef std::map<string16, string16> OriginDirectoriesMap; |
174 | 191 |
(...skipping 13 matching lines...) Expand all Loading... |
188 const string16& description) { | 205 const string16& description) { |
189 database_info_[database_name].second = description; | 206 database_info_[database_name].second = description; |
190 } | 207 } |
191 }; | 208 }; |
192 | 209 |
193 // virtual for unittesting only | 210 // virtual for unittesting only |
194 virtual ~DatabaseTracker(); | 211 virtual ~DatabaseTracker(); |
195 | 212 |
196 bool DeleteClosedDatabase(const string16& origin_identifier, | 213 bool DeleteClosedDatabase(const string16& origin_identifier, |
197 const string16& database_name); | 214 const string16& database_name); |
198 bool DeleteOrigin(const string16& origin_identifier); | |
199 void DeleteDatabaseIfNeeded(const string16& origin_identifier, | 215 void DeleteDatabaseIfNeeded(const string16& origin_identifier, |
200 const string16& database_name); | 216 const string16& database_name); |
201 | 217 |
202 bool LazyInit(); | 218 bool LazyInit(); |
203 bool UpgradeToCurrentVersion(); | 219 bool UpgradeToCurrentVersion(); |
204 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier, | 220 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier, |
205 const string16& database_name, | 221 const string16& database_name, |
206 const string16& database_details, | 222 const string16& database_details, |
207 int64 estimated_size); | 223 int64 estimated_size); |
208 | 224 |
(...skipping 12 matching lines...) Expand all Loading... |
221 // Schedule a set of open databases for deletion. If non-null, callback is | 237 // Schedule a set of open databases for deletion. If non-null, callback is |
222 // invoked upon completion. | 238 // invoked upon completion. |
223 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, | 239 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, |
224 net::CompletionCallback* callback); | 240 net::CompletionCallback* callback); |
225 | 241 |
226 // Returns the directory where all DB files for the given origin are stored. | 242 // Returns the directory where all DB files for the given origin are stored. |
227 string16 GetOriginDirectory(const string16& origin_identifier); | 243 string16 GetOriginDirectory(const string16& origin_identifier); |
228 | 244 |
229 bool is_initialized_; | 245 bool is_initialized_; |
230 const bool is_incognito_; | 246 const bool is_incognito_; |
| 247 bool clear_local_state_on_exit_; |
231 bool shutting_down_; | 248 bool shutting_down_; |
232 const FilePath profile_path_; | 249 const FilePath profile_path_; |
233 const FilePath db_dir_; | 250 const FilePath db_dir_; |
234 scoped_ptr<sql::Connection> db_; | 251 scoped_ptr<sql::Connection> db_; |
235 scoped_ptr<DatabasesTable> databases_table_; | 252 scoped_ptr<DatabasesTable> databases_table_; |
236 scoped_ptr<sql::MetaTable> meta_table_; | 253 scoped_ptr<sql::MetaTable> meta_table_; |
237 ObserverList<Observer, true> observers_; | 254 ObserverList<Observer, true> observers_; |
238 std::map<string16, CachedOriginInfo> origins_info_map_; | 255 std::map<string16, CachedOriginInfo> origins_info_map_; |
239 DatabaseConnections database_connections_; | 256 DatabaseConnections database_connections_; |
240 | 257 |
241 // The set of databases that should be deleted but are still opened | 258 // The set of databases that should be deleted but are still opened |
242 DatabaseSet dbs_to_be_deleted_; | 259 DatabaseSet dbs_to_be_deleted_; |
243 PendingCompletionMap deletion_callbacks_; | 260 PendingCompletionMap deletion_callbacks_; |
244 | 261 |
245 // Apps and Extensions can have special rights. | 262 // Apps and Extensions can have special rights. |
246 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 263 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
247 | 264 |
248 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; | 265 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; |
249 | 266 |
| 267 // The database tracker thread we're supposed to run file IO on. |
| 268 scoped_refptr<base::MessageLoopProxy> db_tracker_thread_; |
| 269 |
250 // When in incognito mode, store a DELETE_ON_CLOSE handle to each | 270 // When in incognito mode, store a DELETE_ON_CLOSE handle to each |
251 // main DB and journal file that was accessed. When the incognito profile | 271 // main DB and journal file that was accessed. When the incognito profile |
252 // goes away (or when the browser crashes), all these handles will be | 272 // goes away (or when the browser crashes), all these handles will be |
253 // closed, and the files will be deleted. | 273 // closed, and the files will be deleted. |
254 FileHandlesMap incognito_file_handles_; | 274 FileHandlesMap incognito_file_handles_; |
255 | 275 |
256 // In a non-incognito profile, all DBs in an origin are stored in a directory | 276 // In a non-incognito profile, all DBs in an origin are stored in a directory |
257 // named after the origin. In an incognito profile though, we do not want the | 277 // named after the origin. In an incognito profile though, we do not want the |
258 // directory structure to reveal the origins visited by the user (in case the | 278 // directory structure to reveal the origins visited by the user (in case the |
259 // browser process crashes and those directories are not deleted). So we use | 279 // browser process crashes and those directories are not deleted). So we use |
260 // this map to assign directory names that do not reveal this information. | 280 // this map to assign directory names that do not reveal this information. |
261 OriginDirectoriesMap incognito_origin_directories_; | 281 OriginDirectoriesMap incognito_origin_directories_; |
262 int incognito_origin_directories_generator_; | 282 int incognito_origin_directories_generator_; |
263 | 283 |
264 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); | 284 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); |
265 }; | 285 }; |
266 | 286 |
267 } // namespace webkit_database | 287 } // namespace webkit_database |
268 | 288 |
269 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_ | 289 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_ |
OLD | NEW |