| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_ | |
| 6 #define WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_ | |
| 7 | |
| 8 #include "base/containers/hash_tables.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/files/scoped_temp_dir.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/platform_file.h" | |
| 13 #include "base/strings/string16.h" | |
| 14 #include "base/synchronization/lock.h" | |
| 15 #include "base/threading/thread.h" | |
| 16 #include "third_party/WebKit/public/web/WebDatabaseObserver.h" | |
| 17 #include "webkit/browser/database/database_tracker.h" | |
| 18 #include "webkit/common/database/database_connections.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class MessageLoopProxy; | |
| 22 class WaitableEvent; | |
| 23 } | |
| 24 | |
| 25 class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer, | |
| 26 public WebKit::WebDatabaseObserver { | |
| 27 public: | |
| 28 static SimpleDatabaseSystem* GetInstance(); | |
| 29 | |
| 30 SimpleDatabaseSystem(); | |
| 31 virtual ~SimpleDatabaseSystem(); | |
| 32 | |
| 33 // WebDatabaseObserver implementation, these are called on the script | |
| 34 // execution context thread on which the database is opened. This may be | |
| 35 // the main thread or background WebWorker threads. | |
| 36 virtual void databaseOpened(const WebKit::WebDatabase& database); | |
| 37 virtual void databaseModified(const WebKit::WebDatabase& database); | |
| 38 virtual void databaseClosed(const WebKit::WebDatabase& database); | |
| 39 | |
| 40 // SQLite VFS related methods, these are called on webcore's | |
| 41 // background database threads via the WebKitPlatformSupport impl. | |
| 42 base::PlatformFile OpenFile(const base::string16& vfs_file_name, | |
| 43 int desired_flags); | |
| 44 int DeleteFile(const base::string16& vfs_file_name, bool sync_dir); | |
| 45 uint32 GetFileAttributes(const base::string16& vfs_file_name); | |
| 46 int64 GetFileSize(const base::string16& vfs_file_name); | |
| 47 int64 GetSpaceAvailable(const std::string& origin_identifier); | |
| 48 | |
| 49 // For use by testRunner, called on the main thread. | |
| 50 void ClearAllDatabases(); | |
| 51 void SetDatabaseQuota(int64 quota); | |
| 52 | |
| 53 private: | |
| 54 // Used by our WebDatabaseObserver impl, only called on the db_thread | |
| 55 void DatabaseOpened(const std::string& origin_identifier, | |
| 56 const base::string16& database_name, | |
| 57 const base::string16& description, | |
| 58 int64 estimated_size); | |
| 59 void DatabaseModified(const std::string& origin_identifier, | |
| 60 const base::string16& database_name); | |
| 61 void DatabaseClosed(const std::string& origin_identifier, | |
| 62 const base::string16& database_name); | |
| 63 | |
| 64 // DatabaseTracker::Observer implementation | |
| 65 virtual void OnDatabaseSizeChanged(const std::string& origin_identifier, | |
| 66 const base::string16& database_name, | |
| 67 int64 database_size) OVERRIDE; | |
| 68 virtual void OnDatabaseScheduledForDeletion( | |
| 69 const std::string& origin_identifier, | |
| 70 const base::string16& database_name) OVERRIDE; | |
| 71 | |
| 72 // Used by our public SQLite VFS methods, only called on the db_thread. | |
| 73 void VfsOpenFile(const base::string16& vfs_file_name, int desired_flags, | |
| 74 base::PlatformFile* result, base::WaitableEvent* done_event); | |
| 75 void VfsDeleteFile(const base::string16& vfs_file_name, bool sync_dir, | |
| 76 int* result, base::WaitableEvent* done_event); | |
| 77 void VfsGetFileAttributes(const base::string16& vfs_file_name, | |
| 78 uint32* result, base::WaitableEvent* done_event); | |
| 79 void VfsGetFileSize(const base::string16& vfs_file_name, | |
| 80 int64* result, base::WaitableEvent* done_event); | |
| 81 void VfsGetSpaceAvailable(const std::string& origin_identifier, | |
| 82 int64* result, base::WaitableEvent* done_event); | |
| 83 | |
| 84 base::FilePath GetFullFilePathForVfsFile(const base::string16& vfs_file_name); | |
| 85 | |
| 86 void ResetTracker(); | |
| 87 void ThreadCleanup(base::WaitableEvent* done_event); | |
| 88 | |
| 89 // Where the tracker database file and per origin database files reside. | |
| 90 base::ScopedTempDir temp_dir_; | |
| 91 | |
| 92 // All access to the db_tracker (except for its construction) and | |
| 93 // vfs operations are serialized on a background thread. | |
| 94 base::Thread db_thread_; | |
| 95 scoped_refptr<base::MessageLoopProxy> db_thread_proxy_; | |
| 96 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; | |
| 97 int64 quota_per_origin_; | |
| 98 | |
| 99 // Data members to support waiting for all connections to be closed. | |
| 100 scoped_refptr<webkit_database::DatabaseConnectionsWrapper> open_connections_; | |
| 101 | |
| 102 static SimpleDatabaseSystem* instance_; | |
| 103 }; | |
| 104 | |
| 105 #endif // WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_ | |
| OLD | NEW |