| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_DATABASE_DATABASE_TRACKER_H_ | 5 #ifndef WEBKIT_BROWSER_DATABASE_DATABASE_TRACKER_H_ |
| 6 #define WEBKIT_BROWSER_DATABASE_DATABASE_TRACKER_H_ | 6 #define WEBKIT_BROWSER_DATABASE_DATABASE_TRACKER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
| 22 #include "webkit/browser/webkit_storage_browser_export.h" | 22 #include "storage/common/storage_export.h" |
| 23 #include "webkit/common/database/database_connections.h" | 23 #include "storage/common/database/database_connections.h" |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class MessageLoopProxy; | 26 class MessageLoopProxy; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 class DatabaseTracker_TestHelper_Test; | 30 class DatabaseTracker_TestHelper_Test; |
| 31 class MockDatabaseTracker; | 31 class MockDatabaseTracker; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace sql { | 34 namespace sql { |
| 35 class Connection; | 35 class Connection; |
| 36 class MetaTable; | 36 class MetaTable; |
| 37 } | 37 } |
| 38 | 38 |
| 39 namespace quota { | 39 namespace quota { |
| 40 class QuotaManagerProxy; | 40 class QuotaManagerProxy; |
| 41 class SpecialStoragePolicy; | 41 class SpecialStoragePolicy; |
| 42 } | 42 } |
| 43 | 43 |
| 44 namespace webkit_database { | 44 namespace webkit_database { |
| 45 | 45 |
| 46 WEBKIT_STORAGE_BROWSER_EXPORT extern const base::FilePath::CharType | 46 STORAGE_EXPORT extern const base::FilePath::CharType kDatabaseDirectoryName[]; |
| 47 kDatabaseDirectoryName[]; | 47 STORAGE_EXPORT extern const base::FilePath::CharType kTrackerDatabaseFileName[]; |
| 48 WEBKIT_STORAGE_BROWSER_EXPORT extern const base::FilePath::CharType | |
| 49 kTrackerDatabaseFileName[]; | |
| 50 | 48 |
| 51 class DatabasesTable; | 49 class DatabasesTable; |
| 52 | 50 |
| 53 // This class is used to store information about all databases in an origin. | 51 // This class is used to store information about all databases in an origin. |
| 54 class WEBKIT_STORAGE_BROWSER_EXPORT OriginInfo { | 52 class STORAGE_EXPORT OriginInfo { |
| 55 public: | 53 public: |
| 56 OriginInfo(); | 54 OriginInfo(); |
| 57 OriginInfo(const OriginInfo& origin_info); | 55 OriginInfo(const OriginInfo& origin_info); |
| 58 ~OriginInfo(); | 56 ~OriginInfo(); |
| 59 | 57 |
| 60 const std::string& GetOriginIdentifier() const { return origin_identifier_; } | 58 const std::string& GetOriginIdentifier() const { return origin_identifier_; } |
| 61 int64 TotalSize() const { return total_size_; } | 59 int64 TotalSize() const { return total_size_; } |
| 62 void GetAllDatabaseNames(std::vector<base::string16>* databases) const; | 60 void GetAllDatabaseNames(std::vector<base::string16>* databases) const; |
| 63 int64 GetDatabaseSize(const base::string16& database_name) const; | 61 int64 GetDatabaseSize(const base::string16& database_name) const; |
| 64 base::string16 GetDatabaseDescription( | 62 base::string16 GetDatabaseDescription( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 // This class manages the main database and keeps track of open databases. | 76 // This class manages the main database and keeps track of open databases. |
| 79 // | 77 // |
| 80 // The data in this class is not thread-safe, so all methods of this class | 78 // The data in this class is not thread-safe, so all methods of this class |
| 81 // should be called on the same thread. The only exceptions are the ctor(), | 79 // should be called on the same thread. The only exceptions are the ctor(), |
| 82 // the dtor() and the database_directory() and quota_manager_proxy() getters. | 80 // the dtor() and the database_directory() and quota_manager_proxy() getters. |
| 83 // | 81 // |
| 84 // Furthermore, some methods of this class have to read/write data from/to | 82 // Furthermore, some methods of this class have to read/write data from/to |
| 85 // the disk. Therefore, in a multi-threaded application, all methods of this | 83 // the disk. Therefore, in a multi-threaded application, all methods of this |
| 86 // class should be called on the thread dedicated to file operations (file | 84 // class should be called on the thread dedicated to file operations (file |
| 87 // thread in the browser process, for example), if such a thread exists. | 85 // thread in the browser process, for example), if such a thread exists. |
| 88 class WEBKIT_STORAGE_BROWSER_EXPORT DatabaseTracker | 86 class STORAGE_EXPORT DatabaseTracker |
| 89 : public base::RefCountedThreadSafe<DatabaseTracker> { | 87 : public base::RefCountedThreadSafe<DatabaseTracker> { |
| 90 public: | 88 public: |
| 91 class Observer { | 89 class Observer { |
| 92 public: | 90 public: |
| 93 virtual void OnDatabaseSizeChanged(const std::string& origin_identifier, | 91 virtual void OnDatabaseSizeChanged(const std::string& origin_identifier, |
| 94 const base::string16& database_name, | 92 const base::string16& database_name, |
| 95 int64 database_size) = 0; | 93 int64 database_size) = 0; |
| 96 virtual void OnDatabaseScheduledForDeletion( | 94 virtual void OnDatabaseScheduledForDeletion( |
| 97 const std::string& origin_identifier, | 95 const std::string& origin_identifier, |
| 98 const base::string16& database_name) = 0; | 96 const base::string16& database_name) = 0; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 175 |
| 178 // Shutdown the database tracker, deleting database files if the tracker is | 176 // Shutdown the database tracker, deleting database files if the tracker is |
| 179 // used for an incognito profile. | 177 // used for an incognito profile. |
| 180 void Shutdown(); | 178 void Shutdown(); |
| 181 // Disables the exit-time deletion of session-only data. | 179 // Disables the exit-time deletion of session-only data. |
| 182 void SetForceKeepSessionState(); | 180 void SetForceKeepSessionState(); |
| 183 | 181 |
| 184 private: | 182 private: |
| 185 friend class base::RefCountedThreadSafe<DatabaseTracker>; | 183 friend class base::RefCountedThreadSafe<DatabaseTracker>; |
| 186 friend class content::DatabaseTracker_TestHelper_Test; | 184 friend class content::DatabaseTracker_TestHelper_Test; |
| 187 friend class content::MockDatabaseTracker; // for testing | 185 friend class content::MockDatabaseTracker; // for testing |
| 188 | 186 |
| 189 typedef std::map<std::string, std::set<base::string16> > DatabaseSet; | 187 typedef std::map<std::string, std::set<base::string16> > DatabaseSet; |
| 190 typedef std::vector<std::pair<net::CompletionCallback, DatabaseSet> > | 188 typedef std::vector<std::pair<net::CompletionCallback, DatabaseSet> > |
| 191 PendingDeletionCallbacks; | 189 PendingDeletionCallbacks; |
| 192 typedef std::map<base::string16, base::File*> FileHandlesMap; | 190 typedef std::map<base::string16, base::File*> FileHandlesMap; |
| 193 typedef std::map<std::string, base::string16> OriginDirectoriesMap; | 191 typedef std::map<std::string, base::string16> OriginDirectoriesMap; |
| 194 | 192 |
| 195 class CachedOriginInfo : public OriginInfo { | 193 class CachedOriginInfo : public OriginInfo { |
| 196 public: | 194 public: |
| 197 CachedOriginInfo() : OriginInfo(std::string(), 0) {} | 195 CachedOriginInfo() : OriginInfo(std::string(), 0) {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 bool UpgradeToCurrentVersion(); | 233 bool UpgradeToCurrentVersion(); |
| 236 void InsertOrUpdateDatabaseDetails(const std::string& origin_identifier, | 234 void InsertOrUpdateDatabaseDetails(const std::string& origin_identifier, |
| 237 const base::string16& database_name, | 235 const base::string16& database_name, |
| 238 const base::string16& database_details, | 236 const base::string16& database_details, |
| 239 int64 estimated_size); | 237 int64 estimated_size); |
| 240 | 238 |
| 241 void ClearAllCachedOriginInfo(); | 239 void ClearAllCachedOriginInfo(); |
| 242 CachedOriginInfo* MaybeGetCachedOriginInfo( | 240 CachedOriginInfo* MaybeGetCachedOriginInfo( |
| 243 const std::string& origin_identifier, | 241 const std::string& origin_identifier, |
| 244 bool create_if_needed); | 242 bool create_if_needed); |
| 245 CachedOriginInfo* GetCachedOriginInfo( | 243 CachedOriginInfo* GetCachedOriginInfo(const std::string& origin_identifier) { |
| 246 const std::string& origin_identifier) { | |
| 247 return MaybeGetCachedOriginInfo(origin_identifier, true); | 244 return MaybeGetCachedOriginInfo(origin_identifier, true); |
| 248 } | 245 } |
| 249 | 246 |
| 250 int64 GetDBFileSize(const std::string& origin_identifier, | 247 int64 GetDBFileSize(const std::string& origin_identifier, |
| 251 const base::string16& database_name); | 248 const base::string16& database_name); |
| 252 int64 SeedOpenDatabaseInfo(const std::string& origin_identifier, | 249 int64 SeedOpenDatabaseInfo(const std::string& origin_identifier, |
| 253 const base::string16& database_name, | 250 const base::string16& database_name, |
| 254 const base::string16& description); | 251 const base::string16& description); |
| 255 int64 UpdateOpenDatabaseInfoAndNotify(const std::string& origin_identifier, | 252 int64 UpdateOpenDatabaseInfoAndNotify(const std::string& origin_identifier, |
| 256 const base::string16& database_name, | 253 const base::string16& database_name, |
| 257 const base::string16* opt_description); | 254 const base::string16* opt_description); |
| 258 int64 UpdateOpenDatabaseSizeAndNotify(const std::string& origin_identifier, | 255 int64 UpdateOpenDatabaseSizeAndNotify(const std::string& origin_identifier, |
| 259 const base::string16& database_name) { | 256 const base::string16& database_name) { |
| 260 return UpdateOpenDatabaseInfoAndNotify( | 257 return UpdateOpenDatabaseInfoAndNotify( |
| 261 origin_identifier, database_name, NULL); | 258 origin_identifier, database_name, NULL); |
| 262 } | 259 } |
| 263 | 260 |
| 264 | |
| 265 void ScheduleDatabaseForDeletion(const std::string& origin_identifier, | 261 void ScheduleDatabaseForDeletion(const std::string& origin_identifier, |
| 266 const base::string16& database_name); | 262 const base::string16& database_name); |
| 267 // Schedule a set of open databases for deletion. If non-null, callback is | 263 // Schedule a set of open databases for deletion. If non-null, callback is |
| 268 // invoked upon completion. | 264 // invoked upon completion. |
| 269 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, | 265 void ScheduleDatabasesForDeletion(const DatabaseSet& databases, |
| 270 const net::CompletionCallback& callback); | 266 const net::CompletionCallback& callback); |
| 271 | 267 |
| 272 // Returns the directory where all DB files for the given origin are stored. | 268 // Returns the directory where all DB files for the given origin are stored. |
| 273 base::string16 GetOriginDirectory(const std::string& origin_identifier); | 269 base::string16 GetOriginDirectory(const std::string& origin_identifier); |
| 274 | 270 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // this map to assign directory names that do not reveal this information. | 306 // this map to assign directory names that do not reveal this information. |
| 311 OriginDirectoriesMap incognito_origin_directories_; | 307 OriginDirectoriesMap incognito_origin_directories_; |
| 312 int incognito_origin_directories_generator_; | 308 int incognito_origin_directories_generator_; |
| 313 | 309 |
| 314 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); | 310 FRIEND_TEST_ALL_PREFIXES(DatabaseTracker, TestHelper); |
| 315 }; | 311 }; |
| 316 | 312 |
| 317 } // namespace webkit_database | 313 } // namespace webkit_database |
| 318 | 314 |
| 319 #endif // WEBKIT_BROWSER_DATABASE_DATABASE_TRACKER_H_ | 315 #endif // WEBKIT_BROWSER_DATABASE_DATABASE_TRACKER_H_ |
| OLD | NEW |