summaryrefslogtreecommitdiffstats
path: root/webkit/support/simple_database_system.h
diff options
context:
space:
mode:
authormichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 20:40:35 +0000
committermichaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-01 20:40:35 +0000
commit1d4dbdeaa23f3459fb710c8b2fe4d444266d952a (patch)
tree94064bd57faaba18d1ee7a9fe514628f58a6be55 /webkit/support/simple_database_system.h
parent228d0659a51d0581c743b5b81921d43c7fd81e35 (diff)
downloadchromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.zip
chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.gz
chromium_src-1d4dbdeaa23f3459fb710c8b2fe4d444266d952a.tar.bz2
Changes to WebDatabaseObserverImpl and SimpleDatabaseSystem required to have a chance of working properly with v8 isolates. With isolates the database related interfaces will be called on multiple threads and the previous impl was not put together with that in mind.
BUG=none TEST=existing tests pass (no way to test with isolates yet) Review URL: http://codereview.chromium.org/6677088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80218 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/support/simple_database_system.h')
-rw-r--r--webkit/support/simple_database_system.h73
1 files changed, 46 insertions, 27 deletions
diff --git a/webkit/support/simple_database_system.h b/webkit/support/simple_database_system.h
index 63cc892..02bb66a 100644
--- a/webkit/support/simple_database_system.h
+++ b/webkit/support/simple_database_system.h
@@ -12,24 +12,45 @@
#include "base/platform_file.h"
#include "base/string16.h"
#include "base/synchronization/lock.h"
+#include "base/task.h"
+#include "base/threading/thread.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabaseObserver.h"
#include "webkit/database/database_connections.h"
#include "webkit/database/database_tracker.h"
+namespace base {
+class MessageLoopProxy;
+class WaitableEvent;
+}
+
class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
public WebKit::WebDatabaseObserver {
public:
static SimpleDatabaseSystem* GetInstance();
+
SimpleDatabaseSystem();
~SimpleDatabaseSystem();
- // VFS functions
+ // WebDatabaseObserver implementation, these are called on the script
+ // execution context thread on which the database is opened. This may be
+ // the main thread or background WebWorker threads.
+ virtual void databaseOpened(const WebKit::WebDatabase& database);
+ virtual void databaseModified(const WebKit::WebDatabase& database);
+ virtual void databaseClosed(const WebKit::WebDatabase& database);
+
+ // SQLite VFS related methods, these are called on webcore's
+ // background database threads via the WebKitClient impl.
base::PlatformFile OpenFile(const string16& vfs_file_name, int desired_flags);
int DeleteFile(const string16& vfs_file_name, bool sync_dir);
- long GetFileAttributes(const string16& vfs_file_name);
- long long GetFileSize(const string16& vfs_file_name);
+ uint32 GetFileAttributes(const string16& vfs_file_name);
+ int64 GetFileSize(const string16& vfs_file_name);
- // database tracker functions
+ // For use by LayoutTestController, called on the main thread.
+ void ClearAllDatabases();
+ void SetDatabaseQuota(int64 quota);
+
+ private:
+ // Used by our WebDatabaseObserver impl, only called on the db_thread
void DatabaseOpened(const string16& origin_identifier,
const string16& database_name,
const string16& description,
@@ -47,38 +68,36 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
virtual void OnDatabaseScheduledForDeletion(const string16& origin_identifier,
const string16& database_name);
- // WebDatabaseObserver implementation
- virtual void databaseOpened(const WebKit::WebDatabase& database);
- virtual void databaseModified(const WebKit::WebDatabase& database);
- virtual void databaseClosed(const WebKit::WebDatabase& database);
-
- void ClearAllDatabases();
- void SetDatabaseQuota(int64 quota);
+ // Used by our public SQLite VFS methods, only called on the db_thread.
+ void VfsOpenFile(const string16& vfs_file_name, int desired_flags,
+ base::PlatformFile* result, base::WaitableEvent* done_event);
+ void VfsDeleteFile(const string16& vfs_file_name, bool sync_dir,
+ int* result, base::WaitableEvent* done_event);
+ void VfsGetFileAttributes(const string16& vfs_file_name,
+ uint32* result, base::WaitableEvent* done_event);
+ void VfsGetFileSize(const string16& vfs_file_name,
+ int64* result, base::WaitableEvent* done_event);
- private:
- // The calls that come from the database tracker run on the main thread.
- // Therefore, we can only call DatabaseUtil::GetFullFilePathForVfsFile()
- // on the main thread. However, the VFS calls run on the DB thread and
- // they need to crack VFS file paths. To resolve this problem, we store
- // a map of vfs_file_names to file_paths. The map is updated on the main
- // thread on each DatabaseOpened() call that comes from the database
- // tracker, and is read on the DB thread by each VFS call.
- void SetFullFilePathsForVfsFile(const string16& origin_identifier,
- const string16& database_name);
FilePath GetFullFilePathForVfsFile(const string16& vfs_file_name);
- static SimpleDatabaseSystem* instance_;
-
- bool waiting_for_dbs_to_close_;
+ void ResetTracker();
+ void ThreadCleanup(base::WaitableEvent* done_event);
+ // Where the tracker database file and per origin database files reside.
ScopedTempDir temp_dir_;
+ // All access to the db_tracker (except for its construction) and
+ // vfs operations are serialized on a background thread.
+ base::Thread db_thread_;
+ scoped_refptr<base::MessageLoopProxy> db_thread_proxy_;
scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
- base::Lock file_names_lock_;
- base::hash_map<string16, FilePath> file_names_;
+ // Data members to support waiting for all connections to be closed.
+ scoped_refptr<webkit_database::DatabaseConnectionsWrapper> open_connections_;
- webkit_database::DatabaseConnections database_connections_;
+ static SimpleDatabaseSystem* instance_;
};
+DISABLE_RUNNABLE_METHOD_REFCOUNT(SimpleDatabaseSystem);
+
#endif // WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_