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

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

Issue 7056025: More WebSQLDatabase and QuotaManager integration. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
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 22 matching lines...) Expand all
33 class QuotaManagerProxy; 33 class QuotaManagerProxy;
34 class SpecialStoragePolicy; 34 class SpecialStoragePolicy;
35 } 35 }
36 36
37 namespace webkit_database { 37 namespace webkit_database {
38 38
39 extern const FilePath::CharType kDatabaseDirectoryName[]; 39 extern const FilePath::CharType kDatabaseDirectoryName[];
40 extern const FilePath::CharType kTrackerDatabaseFileName[]; 40 extern const FilePath::CharType kTrackerDatabaseFileName[];
41 41
42 class DatabasesTable; 42 class DatabasesTable;
43 class QuotaTable; 43 //class QuotaTable;
44 44
45 // This class is used to store information about all databases in an origin. 45 // This class is used to store information about all databases in an origin.
46 class OriginInfo { 46 class OriginInfo {
47 public: 47 public:
48 OriginInfo(); 48 OriginInfo();
49 OriginInfo(const OriginInfo& origin_info); 49 OriginInfo(const OriginInfo& origin_info);
50 ~OriginInfo(); 50 ~OriginInfo();
51 51
52 const string16& GetOrigin() const { return origin_; } 52 const string16& GetOrigin() const { return origin_; }
53 int64 TotalSize() const { return total_size_; } 53 int64 TotalSize() const { return total_size_; }
54 int64 Quota() const { return quota_; } 54 //int64 Quota() const { return quota_; }
55 void GetAllDatabaseNames(std::vector<string16>* databases) const; 55 void GetAllDatabaseNames(std::vector<string16>* databases) const;
56 int64 GetDatabaseSize(const string16& database_name) const; 56 int64 GetDatabaseSize(const string16& database_name) const;
57 string16 GetDatabaseDescription(const string16& database_name) const; 57 string16 GetDatabaseDescription(const string16& database_name) const;
58 58
59 protected: 59 protected:
60 typedef std::map<string16, std::pair<int64, string16> > DatabaseInfoMap; 60 typedef std::map<string16, std::pair<int64, string16> > DatabaseInfoMap;
61 61
62 OriginInfo(const string16& origin, int64 total_size, int64 quota); 62 OriginInfo(const string16& origin, int64 total_size); //, int64 quota);
63 63
64 string16 origin_; 64 string16 origin_;
65 int64 total_size_; 65 int64 total_size_;
66 int64 quota_; 66 //int64 quota_;
67 DatabaseInfoMap database_info_; 67 DatabaseInfoMap database_info_;
68 }; 68 };
69 69
70 // This class manages the main database, and keeps track of per origin quotas. 70 // This class manages the main database and keeps track of open databases.
71 // 71 //
72 // The data in this class is not thread-safe, so all methods of this class 72 // The data in this class is not thread-safe, so all methods of this class
73 // should be called on the same thread. The only exceptions are the ctor(), 73 // should be called on the same thread. The only exceptions are the ctor(),
74 // the dtor() and the database_directory() and quota_manager_proxy() getters. 74 // the dtor() and the database_directory() and quota_manager_proxy() getters.
75 // 75 //
76 // Furthermore, some methods of this class have to read/write data from/to 76 // Furthermore, some methods of this class have to read/write data from/to
77 // the disk. Therefore, in a multi-threaded application, all methods of this 77 // the disk. Therefore, in a multi-threaded application, all methods of this
78 // class should be called on the thread dedicated to file operations (file 78 // class should be called on the thread dedicated to file operations (file
79 // thread in the browser process, for example), if such a thread exists. 79 // thread in the browser process, for example), if such a thread exists.
80 class DatabaseTracker 80 class DatabaseTracker
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 FilePath GetFullDBFilePath(const string16& origin_identifier, 118 FilePath GetFullDBFilePath(const string16& origin_identifier,
119 const string16& database_name); 119 const string16& database_name);
120 120
121 // virtual for unittesting only 121 // virtual for unittesting only
122 virtual bool GetOriginInfo(const string16& origin_id, OriginInfo* info); 122 virtual bool GetOriginInfo(const string16& origin_id, OriginInfo* info);
123 virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids); 123 virtual bool GetAllOriginIdentifiers(std::vector<string16>* origin_ids);
124 virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info); 124 virtual bool GetAllOriginsInfo(std::vector<OriginInfo>* origins_info);
125 125
126 // TODO(michaeln): remove quota related stuff when quota manager 126 // TODO(michaeln): remove quota related stuff when quota manager
127 // integration is complete 127 // integration is complete
128 void SetOriginQuota(const string16& origin_identifier, int64 new_quota); 128 //void SetOriginQuota(const string16& origin_identifier, int64 new_quota);
129 int64 GetDefaultQuota() { return default_quota_; } 129 //int64 GetDefaultQuota() { return default_quota_; }
130 void SetDefaultQuota(int64 quota); // for testing 130 //void SetDefaultQuota(int64 quota); // for testing
131 131
132 // Safe to call on any thread. 132 // Safe to call on any thread.
133 quota::QuotaManagerProxy* quota_manager_proxy() const { 133 quota::QuotaManagerProxy* quota_manager_proxy() const {
134 return quota_manager_proxy_.get(); 134 return quota_manager_proxy_.get();
135 } 135 }
136 136
137 bool IsDatabaseScheduledForDeletion(const string16& origin_identifier, 137 bool IsDatabaseScheduledForDeletion(const string16& origin_identifier,
138 const string16& database_name); 138 const string16& database_name);
139 139
140 // Deletes a single database. Returns net::OK on success, net::FAILED on 140 // Deletes a single database. Returns net::OK on success, net::FAILED on
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 friend class base::RefCountedThreadSafe<DatabaseTracker>; 178 friend class base::RefCountedThreadSafe<DatabaseTracker>;
179 friend class MockDatabaseTracker; // for testing 179 friend class MockDatabaseTracker; // for testing
180 180
181 typedef std::map<string16, std::set<string16> > DatabaseSet; 181 typedef std::map<string16, std::set<string16> > DatabaseSet;
182 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap; 182 typedef std::map<net::CompletionCallback*, DatabaseSet> PendingCompletionMap;
183 typedef std::map<string16, base::PlatformFile> FileHandlesMap; 183 typedef std::map<string16, base::PlatformFile> FileHandlesMap;
184 typedef std::map<string16, string16> OriginDirectoriesMap; 184 typedef std::map<string16, string16> OriginDirectoriesMap;
185 185
186 class CachedOriginInfo : public OriginInfo { 186 class CachedOriginInfo : public OriginInfo {
187 public: 187 public:
188 CachedOriginInfo() : OriginInfo(string16(), 0, 0) {} 188 CachedOriginInfo() : OriginInfo(string16(), 0) {}
189 void SetOrigin(const string16& origin) { origin_ = origin; } 189 void SetOrigin(const string16& origin) { origin_ = origin; }
190 void SetQuota(int64 new_quota) { quota_ = new_quota; } 190 //void SetQuota(int64 new_quota) { quota_ = new_quota; }
191 void SetDatabaseSize(const string16& database_name, int64 new_size) { 191 void SetDatabaseSize(const string16& database_name, int64 new_size) {
192 int64 old_size = 0; 192 int64 old_size = 0;
193 if (database_info_.find(database_name) != database_info_.end()) 193 if (database_info_.find(database_name) != database_info_.end())
194 old_size = database_info_[database_name].first; 194 old_size = database_info_[database_name].first;
195 database_info_[database_name].first = new_size; 195 database_info_[database_name].first = new_size;
196 if (new_size != old_size) 196 if (new_size != old_size)
197 total_size_ += new_size - old_size; 197 total_size_ += new_size - old_size;
198 } 198 }
199 void SetDatabaseDescription(const string16& database_name, 199 void SetDatabaseDescription(const string16& database_name,
200 const string16& description) { 200 const string16& description) {
(...skipping 15 matching lines...) Expand all
216 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier, 216 void InsertOrUpdateDatabaseDetails(const string16& origin_identifier,
217 const string16& database_name, 217 const string16& database_name,
218 const string16& database_details, 218 const string16& database_details,
219 int64 estimated_size); 219 int64 estimated_size);
220 220
221 void ClearAllCachedOriginInfo(); 221 void ClearAllCachedOriginInfo();
222 CachedOriginInfo* GetCachedOriginInfo(const string16& origin_identifier); 222 CachedOriginInfo* GetCachedOriginInfo(const string16& origin_identifier);
223 223
224 int64 GetDBFileSize(const string16& origin_identifier, 224 int64 GetDBFileSize(const string16& origin_identifier,
225 const string16& database_name); 225 const string16& database_name);
226 int64 SeedOpenDatabaseSize(const string16& origin_identifier,
227 const string16& database_name);
228 int64 UpdateOpenDatabaseSizeAndNotify(const string16& origin_identifier,
229 const string16& database_name);
226 230
227 int64 GetOriginSpaceAvailable(const string16& origin_identifier);
228
229 int64 UpdateCachedDatabaseFileSize(const string16& origin_identifier,
230 const string16& database_name);
231 void ScheduleDatabaseForDeletion(const string16& origin_identifier, 231 void ScheduleDatabaseForDeletion(const string16& origin_identifier,
232 const string16& database_name); 232 const string16& database_name);
233 // Schedule a set of open databases for deletion. If non-null, callback is 233 // Schedule a set of open databases for deletion. If non-null, callback is
234 // invoked upon completion. 234 // invoked upon completion.
235 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, 235 void ScheduleDatabasesForDeletion(const DatabaseSet& databases,
236 net::CompletionCallback* callback); 236 net::CompletionCallback* callback);
237 237
238 // Returns the directory where all DB files for the given origin are stored. 238 // Returns the directory where all DB files for the given origin are stored.
239 string16 GetOriginDirectory(const string16& origin_identifier); 239 string16 GetOriginDirectory(const string16& origin_identifier);
240 240
241 bool is_initialized_; 241 bool is_initialized_;
242 const bool is_incognito_; 242 const bool is_incognito_;
243 bool shutting_down_; 243 bool shutting_down_;
244 const FilePath profile_path_; 244 const FilePath profile_path_;
245 const FilePath db_dir_; 245 const FilePath db_dir_;
246 scoped_ptr<sql::Connection> db_; 246 scoped_ptr<sql::Connection> db_;
247 scoped_ptr<DatabasesTable> databases_table_; 247 scoped_ptr<DatabasesTable> databases_table_;
248 scoped_ptr<QuotaTable> quota_table_; 248 //scoped_ptr<QuotaTable> quota_table_;
249 scoped_ptr<sql::MetaTable> meta_table_; 249 scoped_ptr<sql::MetaTable> meta_table_;
250 ObserverList<Observer, true> observers_; 250 ObserverList<Observer, true> observers_;
251 std::map<string16, CachedOriginInfo> origins_info_map_; 251 std::map<string16, CachedOriginInfo> origins_info_map_;
252 DatabaseConnections database_connections_; 252 DatabaseConnections database_connections_;
253 253
254 // The set of databases that should be deleted but are still opened 254 // The set of databases that should be deleted but are still opened
255 DatabaseSet dbs_to_be_deleted_; 255 DatabaseSet dbs_to_be_deleted_;
256 PendingCompletionMap deletion_callbacks_; 256 PendingCompletionMap deletion_callbacks_;
257 257
258 // Default quota for all origins; changed only by tests 258 // Default quota for all origins; changed only by tests
259 int64 default_quota_; 259 //int64 default_quota_;
260 260
261 // Apps and Extensions can have special rights. 261 // Apps and Extensions can have special rights.
262 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; 262 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
263 263
264 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; 264 scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
265 265
266 // When in incognito mode, store a DELETE_ON_CLOSE handle to each 266 // When in incognito mode, store a DELETE_ON_CLOSE handle to each
267 // main DB and journal file that was accessed. When the incognito profile 267 // main DB and journal file that was accessed. When the incognito profile
268 // goes away (or when the browser crashes), all these handles will be 268 // goes away (or when the browser crashes), all these handles will be
269 // closed, and the files will be deleted. 269 // closed, and the files will be deleted.
270 FileHandlesMap incognito_file_handles_; 270 FileHandlesMap incognito_file_handles_;
271 271
272 // In a non-incognito profile, all DBs in an origin are stored in a directory 272 // In a non-incognito profile, all DBs in an origin are stored in a directory
273 // named after the origin. In an incognito profile though, we do not want the 273 // named after the origin. In an incognito profile though, we do not want the
274 // directory structure to reveal the origins visited by the user (in case the 274 // directory structure to reveal the origins visited by the user (in case the
275 // browser process crashes and those directories are not deleted). So we use 275 // browser process crashes and those directories are not deleted). So we use
276 // this map to assign directory names that do not reveal this information. 276 // this map to assign directory names that do not reveal this information.
277 OriginDirectoriesMap incognito_origin_directories_; 277 OriginDirectoriesMap incognito_origin_directories_;
278 int incognito_origin_directories_generator_; 278 int incognito_origin_directories_generator_;
279 279
280 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); 280 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper);
281 }; 281 };
282 282
283 } // namespace webkit_database 283 } // namespace webkit_database
284 284
285 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_ 285 #endif // WEBKIT_DATABASE_DATABASE_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698