Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Side by Side Diff: webkit/database/database_tracker.h

Issue 7234014: Move code to clear web databases on shutdown to the database tracker (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/database/database_quota_client_unittest.cc ('k') | webkit/database/database_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 bool IsIncognitoProfile() const { return is_incognito_; } 154 bool IsIncognitoProfile() const { return is_incognito_; }
153 155
154 void GetIncognitoFileHandle(const string16& vfs_file_path, 156 void GetIncognitoFileHandle(const string16& vfs_file_path,
155 base::PlatformFile* file_handle) const; 157 base::PlatformFile* file_handle) const;
156 void SaveIncognitoFileHandle(const string16& vfs_file_path, 158 void SaveIncognitoFileHandle(const string16& vfs_file_path,
157 const base::PlatformFile& file_handle); 159 const base::PlatformFile& file_handle);
158 bool CloseIncognitoFileHandle(const string16& vfs_file_path); 160 bool CloseIncognitoFileHandle(const string16& vfs_file_path);
159 bool HasSavedIncognitoFileHandle(const string16& vfs_file_path) const; 161 bool HasSavedIncognitoFileHandle(const string16& vfs_file_path) const;
160 162
161 // Deletes the directory that stores all DBs in incognito mode, if it exists. 163 // Shutdown the database tracker, deleting database files if the tracker is
162 void DeleteIncognitoDBDirectory(); 164 // used for an incognito profile or |clear_local_state_on_exit_| is true.
163 165 void Shutdown();
164 static void ClearLocalState(const FilePath& profile_path); 166 void SetClearLocalStateOnExit(bool clear_local_state_on_exit);
165 167
166 private: 168 private:
167 friend class base::RefCountedThreadSafe<DatabaseTracker>; 169 friend class base::RefCountedThreadSafe<DatabaseTracker>;
168 friend class MockDatabaseTracker; // for testing 170 friend class MockDatabaseTracker; // for testing
169 171
170 typedef std::map<string16, std::set<string16> > DatabaseSet; 172 typedef std::map<string16, std::set<string16> > DatabaseSet;
171 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap; 173 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap;
172 typedef std::map<string16, base::PlatformFile> FileHandlesMap; 174 typedef std::map<string16, base::PlatformFile> FileHandlesMap;
173 typedef std::map<string16, string16> OriginDirectoriesMap; 175 typedef std::map<string16, string16> OriginDirectoriesMap;
174 176
(...skipping 11 matching lines...) Expand all
186 } 188 }
187 void SetDatabaseDescription(const string16& database_name, 189 void SetDatabaseDescription(const string16& database_name,
188 const string16& description) { 190 const string16& description) {
189 database_info_[database_name].second = description; 191 database_info_[database_name].second = description;
190 } 192 }
191 }; 193 };
192 194
193 // virtual for unittesting only 195 // virtual for unittesting only
194 virtual ~DatabaseTracker(); 196 virtual ~DatabaseTracker();
195 197
198 // Deletes the directory that stores all DBs in incognito mode, if it exists.
199 void DeleteIncognitoDBDirectory();
200
201 // Deletes databases not protected by the special storage policy if
202 // |clear_local_state_on_exit_| is true and blocks databases from being
203 // created/opened.
204 void ClearLocalState();
205
196 bool DeleteClosedDatabase(const string16& origin_identifier, 206 bool DeleteClosedDatabase(const string16& origin_identifier,
197 const string16& database_name); 207 const string16& database_name);
198 bool DeleteOrigin(const string16& origin_identifier); 208
209 // Delete all files belonging to the given origin given that no database
210 // connections within this origin are open, or if |force| is true, delete
211 // the meta data and rename the associated directory.
212 bool DeleteOrigin(const string16& origin_identifier, bool force);
199 void DeleteDatabaseIfNeeded(const string16& origin_identifier, 213 void DeleteDatabaseIfNeeded(const string16& origin_identifier,
200 const string16& database_name); 214 const string16& database_name);
201 215
202 bool LazyInit(); 216 bool LazyInit();
203 bool UpgradeToCurrentVersion(); 217 bool UpgradeToCurrentVersion();
204 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier, 218 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier,
205 const string16& database_name, 219 const string16& database_name,
206 const string16& database_details, 220 const string16& database_details,
207 int64 estimated_size); 221 int64 estimated_size);
208 222
(...skipping 12 matching lines...) Expand all
221 // Schedule a set of open databases for deletion. If non-null, callback is 235 // Schedule a set of open databases for deletion. If non-null, callback is
222 // invoked upon completion. 236 // invoked upon completion.
223 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, 237 void ScheduleDatabasesForDeletion(const DatabaseSet& databases,
224 net::CompletionCallback* callback); 238 net::CompletionCallback* callback);
225 239
226 // Returns the directory where all DB files for the given origin are stored. 240 // Returns the directory where all DB files for the given origin are stored.
227 string16 GetOriginDirectory(const string16& origin_identifier); 241 string16 GetOriginDirectory(const string16& origin_identifier);
228 242
229 bool is_initialized_; 243 bool is_initialized_;
230 const bool is_incognito_; 244 const bool is_incognito_;
245 bool clear_local_state_on_exit_;
231 bool shutting_down_; 246 bool shutting_down_;
232 const FilePath profile_path_; 247 const FilePath profile_path_;
233 const FilePath db_dir_; 248 const FilePath db_dir_;
234 scoped_ptr<sql::Connection> db_; 249 scoped_ptr<sql::Connection> db_;
235 scoped_ptr<DatabasesTable> databases_table_; 250 scoped_ptr<DatabasesTable> databases_table_;
236 scoped_ptr<sql::MetaTable> meta_table_; 251 scoped_ptr<sql::MetaTable> meta_table_;
237 ObserverList<Observer, true> observers_; 252 ObserverList<Observer, true> observers_;
238 std::map<string16, CachedOriginInfo> origins_info_map_; 253 std::map<string16, CachedOriginInfo> origins_info_map_;
239 DatabaseConnections database_connections_; 254 DatabaseConnections database_connections_;
240 255
241 // The set of databases that should be deleted but are still opened 256 // The set of databases that should be deleted but are still opened
242 DatabaseSet dbs_to_be_deleted_; 257 DatabaseSet dbs_to_be_deleted_;
243 PendingCompletionMap deletion_callbacks_; 258 PendingCompletionMap deletion_callbacks_;
244 259
245 // Apps and Extensions can have special rights. 260 // Apps and Extensions can have special rights.
246 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 261 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
247 262
248 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; 263 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
249 264
265 // The database tracker thread we're supposed to run file IO on.
266 scoped_refptr<base::MessageLoopProxy> db_tracker_thread_;
267
250 // When in incognito mode, store a DELETE_ON_CLOSE handle to each 268 // 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 269 // 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 270 // goes away (or when the browser crashes), all these handles will be
253 // closed, and the files will be deleted. 271 // closed, and the files will be deleted.
254 FileHandlesMap incognito_file_handles_; 272 FileHandlesMap incognito_file_handles_;
255 273
256 // In a non-incognito profile, all DBs in an origin are stored in a directory 274 // 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 275 // 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 276 // 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 277 // 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. 278 // this map to assign directory names that do not reveal this information.
261 OriginDirectoriesMap incognito_origin_directories_; 279 OriginDirectoriesMap incognito_origin_directories_;
262 int incognito_origin_directories_generator_; 280 int incognito_origin_directories_generator_;
263 281
264 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); 282 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper);
265 }; 283 };
266 284
267 } // namespace webkit_database 285 } // namespace webkit_database
268 286
269 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_ 287 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_
OLDNEW
« no previous file with comments | « webkit/database/database_quota_client_unittest.cc ('k') | webkit/database/database_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698