Move base Java utils to base/test/android/javatests.
[chromium-blink-merge.git] / webkit / support / simple_database_system.h
blobf04a5fa2cc78a9e026974e36acd1fac0f7d95b08
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.
5 #ifndef WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_
6 #define WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_
8 #include "base/file_path.h"
9 #include "base/hash_tables.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/platform_file.h"
12 #include "base/scoped_temp_dir.h"
13 #include "base/string16.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDatabaseObserver.h"
17 #include "webkit/database/database_connections.h"
18 #include "webkit/database/database_tracker.h"
20 namespace base {
21 class MessageLoopProxy;
22 class WaitableEvent;
25 class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer,
26 public WebKit::WebDatabaseObserver {
27 public:
28 static SimpleDatabaseSystem* GetInstance();
30 SimpleDatabaseSystem();
31 virtual ~SimpleDatabaseSystem();
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);
40 // SQLite VFS related methods, these are called on webcore's
41 // background database threads via the WebKitPlatformSupport impl.
42 base::PlatformFile OpenFile(const string16& vfs_file_name, int desired_flags);
43 int DeleteFile(const string16& vfs_file_name, bool sync_dir);
44 uint32 GetFileAttributes(const string16& vfs_file_name);
45 int64 GetFileSize(const string16& vfs_file_name);
46 int64 GetSpaceAvailable(const string16& origin_identifier);
48 // For use by testRunner, called on the main thread.
49 void ClearAllDatabases();
50 void SetDatabaseQuota(int64 quota);
52 private:
53 // Used by our WebDatabaseObserver impl, only called on the db_thread
54 void DatabaseOpened(const string16& origin_identifier,
55 const string16& database_name,
56 const string16& description,
57 int64 estimated_size);
58 void DatabaseModified(const string16& origin_identifier,
59 const string16& database_name);
60 void DatabaseClosed(const string16& origin_identifier,
61 const string16& database_name);
63 // DatabaseTracker::Observer implementation
64 virtual void OnDatabaseSizeChanged(const string16& origin_identifier,
65 const string16& database_name,
66 int64 database_size) OVERRIDE;
67 virtual void OnDatabaseScheduledForDeletion(
68 const string16& origin_identifier,
69 const string16& database_name) OVERRIDE;
71 // Used by our public SQLite VFS methods, only called on the db_thread.
72 void VfsOpenFile(const string16& vfs_file_name, int desired_flags,
73 base::PlatformFile* result, base::WaitableEvent* done_event);
74 void VfsDeleteFile(const string16& vfs_file_name, bool sync_dir,
75 int* result, base::WaitableEvent* done_event);
76 void VfsGetFileAttributes(const string16& vfs_file_name,
77 uint32* result, base::WaitableEvent* done_event);
78 void VfsGetFileSize(const string16& vfs_file_name,
79 int64* result, base::WaitableEvent* done_event);
80 void VfsGetSpaceAvailable(const string16& origin_identifier,
81 int64* result, base::WaitableEvent* done_event);
83 FilePath GetFullFilePathForVfsFile(const string16& vfs_file_name);
85 void ResetTracker();
86 void ThreadCleanup(base::WaitableEvent* done_event);
88 // Where the tracker database file and per origin database files reside.
89 ScopedTempDir temp_dir_;
91 // All access to the db_tracker (except for its construction) and
92 // vfs operations are serialized on a background thread.
93 base::Thread db_thread_;
94 scoped_refptr<base::MessageLoopProxy> db_thread_proxy_;
95 scoped_refptr<webkit_database::DatabaseTracker> db_tracker_;
96 int64 quota_per_origin_;
98 // Data members to support waiting for all connections to be closed.
99 scoped_refptr<webkit_database::DatabaseConnectionsWrapper> open_connections_;
101 static SimpleDatabaseSystem* instance_;
104 #endif // WEBKIT_SUPPORT_SIMPLE_DATABASE_SYSTEM_H_