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