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

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

Issue 2746003: Support WebSQLDatabases in incognito mode. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | « chrome/test/testing_profile.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/platform_file.h"
13 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
14 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 #include "base/string_util.h" 17 #include "base/string_util.h"
17 #include "base/time.h" 18 #include "base/time.h"
18 #include "net/base/completion_callback.h" 19 #include "net/base/completion_callback.h"
19 #include "testing/gtest/include/gtest/gtest_prod.h" 20 #include "testing/gtest/include/gtest/gtest_prod.h"
20 #include "webkit/database/database_connections.h" 21 #include "webkit/database/database_connections.h"
21 22
22 namespace sql { 23 namespace sql {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual void OnDatabaseSizeChanged(const string16& origin_identifier, 94 virtual void OnDatabaseSizeChanged(const string16& origin_identifier,
94 const string16& database_name, 95 const string16& database_name,
95 int64 database_size, 96 int64 database_size,
96 int64 space_available) = 0; 97 int64 space_available) = 0;
97 virtual void OnDatabaseScheduledForDeletion( 98 virtual void OnDatabaseScheduledForDeletion(
98 const string16& origin_identifier, 99 const string16& origin_identifier,
99 const string16& database_name) = 0; 100 const string16& database_name) = 0;
100 virtual ~Observer() {} 101 virtual ~Observer() {}
101 }; 102 };
102 103
103 explicit DatabaseTracker(const FilePath& profile_path); 104 DatabaseTracker(const FilePath& profile_path, bool is_incognito);
104 105
105 void DatabaseOpened(const string16& origin_identifier, 106 void DatabaseOpened(const string16& origin_identifier,
106 const string16& database_name, 107 const string16& database_name,
107 const string16& database_details, 108 const string16& database_details,
108 int64 estimated_size, 109 int64 estimated_size,
109 int64* database_size, 110 int64* database_size,
110 int64* space_available); 111 int64* space_available);
111 void DatabaseModified(const string16& origin_identifier, 112 void DatabaseModified(const string16& origin_identifier,
112 const string16& database_name); 113 const string16& database_name);
113 void DatabaseClosed(const string16& origin_identifier, 114 void DatabaseClosed(const string16& origin_identifier,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // completion, if non-NULL. 150 // completion, if non-NULL.
150 int DeleteDataModifiedSince(const base::Time& cutoff, 151 int DeleteDataModifiedSince(const base::Time& cutoff,
151 net::CompletionCallback* callback); 152 net::CompletionCallback* callback);
152 153
153 // Delete all databases that belong to the given origin. Returns net::OK on 154 // Delete all databases that belong to the given origin. Returns net::OK on
154 // success, net::FAILED if not all databases could be deleted, and 155 // success, net::FAILED if not all databases could be deleted, and
155 // net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL. 156 // net::ERR_IO_PENDING and |callback| is invoked upon completion, if non-NULL.
156 int DeleteDataForOrigin(const string16& origin_identifier, 157 int DeleteDataForOrigin(const string16& origin_identifier,
157 net::CompletionCallback* callback); 158 net::CompletionCallback* callback);
158 159
160 bool IsIncognitoProfile() const { return is_incognito_; }
161
162 void GetIncognitoFileHandle(const string16& vfs_file_path,
163 base::PlatformFile* file_handle) const;
164 void SaveIncognitoFileHandle(const string16& vfs_file_path,
165 const base::PlatformFile& file_handle);
166 bool CloseIncognitoFileHandle(const string16& vfs_file_path);
167 bool HasSavedIncognitoFileHandle(const string16& vfs_file_path) const;
168
169 // Deletes the directory that stores all DBs in incognito mode, if it exists.
170 void DeleteIncognitoDBDirectory();
171
159 static void ClearLocalState(const FilePath& profile_path); 172 static void ClearLocalState(const FilePath& profile_path);
160 173
161 private: 174 private:
162 // Need this here to allow RefCountedThreadSafe to call ~DatabaseTracker(). 175 // Need this here to allow RefCountedThreadSafe to call ~DatabaseTracker().
163 friend class base::RefCountedThreadSafe<DatabaseTracker>; 176 friend class base::RefCountedThreadSafe<DatabaseTracker>;
164 177
165 typedef std::map<string16, std::set<string16> > DatabaseSet; 178 typedef std::map<string16, std::set<string16> > DatabaseSet;
166 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap; 179 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap;
180 typedef std::map<string16, base::PlatformFile> FileHandlesMap;
181 typedef std::map<string16, string16> OriginDirectoriesMap;
167 182
168 class CachedOriginInfo : public OriginInfo { 183 class CachedOriginInfo : public OriginInfo {
169 public: 184 public:
170 CachedOriginInfo() : OriginInfo(string16(), 0, 0) {} 185 CachedOriginInfo() : OriginInfo(string16(), 0, 0) {}
171 void SetOrigin(const string16& origin) { origin_ = origin; } 186 void SetOrigin(const string16& origin) { origin_ = origin; }
172 void SetQuota(int64 new_quota) { quota_ = new_quota; } 187 void SetQuota(int64 new_quota) { quota_ = new_quota; }
173 void SetDatabaseSize(const string16& database_name, int64 new_size) { 188 void SetDatabaseSize(const string16& database_name, int64 new_size) {
174 int64 old_size = 0; 189 int64 old_size = 0;
175 if (database_info_.find(database_name) != database_info_.end()) 190 if (database_info_.find(database_name) != database_info_.end())
176 old_size = database_info_[database_name].first; 191 old_size = database_info_[database_name].first;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 224
210 int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier, 225 int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier,
211 const string16& database_name); 226 const string16& database_name);
212 void ScheduleDatabaseForDeletion(const string16& origin_identifier, 227 void ScheduleDatabaseForDeletion(const string16& origin_identifier,
213 const string16& database_name); 228 const string16& database_name);
214 // Schedule a set of open databases for deletion. If non-null, callback is 229 // Schedule a set of open databases for deletion. If non-null, callback is
215 // invoked upon completion. 230 // invoked upon completion.
216 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, 231 void ScheduleDatabasesForDeletion(const DatabaseSet& databases,
217 net::CompletionCallback* callback); 232 net::CompletionCallback* callback);
218 233
234 // Returns the directory where all DB files for the given origin are stored.
235 string16 GetOriginDirectory(const string16& origin_identifier);
236
219 bool is_initialized_; 237 bool is_initialized_;
220 const bool is_incognito_; 238 const bool is_incognito_;
239 bool shutting_down_;
240 const FilePath profile_path_;
221 const FilePath db_dir_; 241 const FilePath db_dir_;
222 scoped_ptr<sql::Connection> db_; 242 scoped_ptr<sql::Connection> db_;
223 scoped_ptr<DatabasesTable> databases_table_; 243 scoped_ptr<DatabasesTable> databases_table_;
224 scoped_ptr<QuotaTable> quota_table_; 244 scoped_ptr<QuotaTable> quota_table_;
225 scoped_ptr<sql::MetaTable> meta_table_; 245 scoped_ptr<sql::MetaTable> meta_table_;
226 ObserverList<Observer, true> observers_; 246 ObserverList<Observer, true> observers_;
227 std::map<string16, CachedOriginInfo> origins_info_map_; 247 std::map<string16, CachedOriginInfo> origins_info_map_;
228 DatabaseConnections database_connections_; 248 DatabaseConnections database_connections_;
229 249
230 // The set of databases that should be deleted but are still opened 250 // The set of databases that should be deleted but are still opened
231 DatabaseSet dbs_to_be_deleted_; 251 DatabaseSet dbs_to_be_deleted_;
232 PendingCompletionMap deletion_callbacks_; 252 PendingCompletionMap deletion_callbacks_;
233 253
234 // Default quota for all origins; changed only by tests 254 // Default quota for all origins; changed only by tests
235 int64 default_quota_; 255 int64 default_quota_;
236 256
237 // Store quotas for extensions in memory, in order to prevent writing a row 257 // Store quotas for extensions in memory, in order to prevent writing a row
238 // to quota_table_ every time an extention is loaded. 258 // to quota_table_ every time an extention is loaded.
239 std::map<string16, int64> in_memory_quotas_; 259 std::map<string16, int64> in_memory_quotas_;
240 260
241 FRIEND_TEST(DatabaseTrackerTest, DatabaseTracker); 261 // When in incognito mode, store a DELETE_ON_CLOSE handle to each
242 FRIEND_TEST(DatabaseTrackerTest, NoInitIncognito); 262 // main DB and journal file that was accessed. When the incognito profile
263 // goes away (or when the browser crashes), all these handles will be
264 // closed, and the files will be deleted.
265 FileHandlesMap incognito_file_handles_;
266
267 // In a non-incognito profile, all DBs in an origin are stored in a directory
268 // named after the origin. In an incognito profile though, we do not want the
269 // directory structure to reveal the origins visited by the user (in case the
270 // browser process crashes and those directories are not deleted). So we use
271 // this map to assign directory names that do not reveal this information.
272 OriginDirectoriesMap incognito_origin_directories_;
273 int incognito_origin_directories_generator_;
274
275 FRIEND_TEST(DatabaseTracker, TestHelper);
243 }; 276 };
244 277
245 } // namespace webkit_database 278 } // namespace webkit_database
246 279
247 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_ 280 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/test/testing_profile.cc ('k') | webkit/database/database_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698