summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webdatabase/DatabaseTracker.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/Modules/webdatabase/DatabaseTracker.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/DatabaseTracker.h')
-rw-r--r--Source/WebCore/Modules/webdatabase/DatabaseTracker.h182
1 files changed, 91 insertions, 91 deletions
diff --git a/Source/WebCore/Modules/webdatabase/DatabaseTracker.h b/Source/WebCore/Modules/webdatabase/DatabaseTracker.h
index acea6988f..af6cb5bf3 100644
--- a/Source/WebCore/Modules/webdatabase/DatabaseTracker.h
+++ b/Source/WebCore/Modules/webdatabase/DatabaseTracker.h
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,35 +26,38 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef DatabaseTracker_h
-#define DatabaseTracker_h
-
-#if ENABLE(SQL_DATABASE)
+#pragma once
#include "DatabaseDetails.h"
-#include "DatabaseError.h"
+#include "ExceptionOr.h"
#include "SQLiteDatabase.h"
+#include "SecurityOriginData.h"
#include "SecurityOriginHash.h"
+#include <wtf/HashCountedSet.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
-#include <wtf/OwnPtr.h>
#include <wtf/text/StringHash.h>
-#include <wtf/text/WTFString.h>
namespace WebCore {
-class DatabaseBackendBase;
-class DatabaseBackendContext;
+class Database;
+class DatabaseContext;
class DatabaseManagerClient;
class OriginLock;
class SecurityOrigin;
+struct SecurityOriginData;
+
+enum class CurrentQueryBehavior { Interrupt, RunToCompletion };
class DatabaseTracker {
WTF_MAKE_NONCOPYABLE(DatabaseTracker); WTF_MAKE_FAST_ALLOCATED;
public:
+ // FIXME: This is a hack so we can easily delete databases from the UI process in WebKit2.
+ WEBCORE_EXPORT static std::unique_ptr<DatabaseTracker> trackerWithDatabasePath(const String& databasePath);
+
static void initializeTracker(const String& databasePath);
- static DatabaseTracker& tracker();
+ WEBCORE_EXPORT static DatabaseTracker& singleton();
// This singleton will potentially be used from multiple worker threads and the page's context thread simultaneously. To keep this safe, it's
// currently using 4 locks. In order to avoid deadlock when taking multiple locks, you must take them in the correct order:
// m_databaseGuard before quotaManager if both locks are needed.
@@ -62,72 +65,63 @@ public:
// m_databaseGuard and m_openDatabaseMapGuard currently don't overlap.
// notificationMutex() is currently independent of the other locks.
- bool canEstablishDatabase(DatabaseBackendContext*, const String& name, unsigned long estimatedSize, DatabaseError&);
- bool retryCanEstablishDatabase(DatabaseBackendContext*, const String& name, unsigned long estimatedSize, DatabaseError&);
-
- void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize);
- String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
-
- void addOpenDatabase(DatabaseBackendBase*);
- void removeOpenDatabase(DatabaseBackendBase*);
- void getOpenDatabases(SecurityOrigin*, const String& name, HashSet<RefPtr<DatabaseBackendBase>>* databases);
+ ExceptionOr<void> canEstablishDatabase(DatabaseContext&, const String& name, unsigned estimatedSize);
+ ExceptionOr<void> retryCanEstablishDatabase(DatabaseContext&, const String& name, unsigned estimatedSize);
- unsigned long long getMaxSizeForDatabase(const DatabaseBackendBase*);
+ void setDatabaseDetails(const SecurityOriginData&, const String& name, const String& displayName, unsigned estimatedSize);
+ String fullPathForDatabase(const SecurityOriginData&, const String& name, bool createIfDoesNotExist);
- void interruptAllDatabasesForContext(const DatabaseBackendContext*);
+ void addOpenDatabase(Database&);
+ void removeOpenDatabase(Database&);
-private:
- explicit DatabaseTracker(const String& databasePath);
+ unsigned long long maximumSize(Database&);
- bool hasAdequateQuotaForOrigin(SecurityOrigin*, unsigned long estimatedSize, DatabaseError&);
+ WEBCORE_EXPORT void closeAllDatabases(CurrentQueryBehavior = CurrentQueryBehavior::RunToCompletion);
-public:
- void setDatabaseDirectoryPath(const String&);
- String databaseDirectoryPath() const;
+ WEBCORE_EXPORT Vector<SecurityOriginData> origins();
+ WEBCORE_EXPORT Vector<String> databaseNames(const SecurityOriginData&);
- void origins(Vector<RefPtr<SecurityOrigin>>& result);
- bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
+ DatabaseDetails detailsForNameAndOrigin(const String&, const SecurityOriginData&);
- DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
+ WEBCORE_EXPORT unsigned long long usage(const SecurityOriginData&);
+ WEBCORE_EXPORT unsigned long long quota(const SecurityOriginData&);
+ WEBCORE_EXPORT void setQuota(const SecurityOriginData&, unsigned long long);
+ RefPtr<OriginLock> originLockFor(const SecurityOriginData&);
- unsigned long long usageForOrigin(SecurityOrigin*);
- unsigned long long quotaForOrigin(SecurityOrigin*);
- void setQuota(SecurityOrigin*, unsigned long long);
- PassRefPtr<OriginLock> originLockFor(SecurityOrigin*);
-
- void deleteAllDatabases();
- bool deleteOrigin(SecurityOrigin*);
- bool deleteDatabase(SecurityOrigin*, const String& name);
+ WEBCORE_EXPORT void deleteAllDatabasesImmediately();
+ WEBCORE_EXPORT void deleteDatabasesModifiedSince(std::chrono::system_clock::time_point);
+ WEBCORE_EXPORT bool deleteOrigin(const SecurityOriginData&);
+ WEBCORE_EXPORT bool deleteDatabase(const SecurityOriginData&, const String& name);
#if PLATFORM(IOS)
- void removeDeletedOpenedDatabases();
- static bool deleteDatabaseFileIfEmpty(const String&);
+ WEBCORE_EXPORT void removeDeletedOpenedDatabases();
+ WEBCORE_EXPORT static bool deleteDatabaseFileIfEmpty(const String&);
// MobileSafari will grab this mutex on the main thread before dispatching the task to
// clean up zero byte database files. Any operations to open new database will have to
// wait for that task to finish by waiting on this mutex.
- static Mutex& openDatabaseMutex();
-
- static void emptyDatabaseFilesRemovalTaskWillBeScheduled();
- static void emptyDatabaseFilesRemovalTaskDidFinish();
+ static Lock& openDatabaseMutex();
- void setDatabasesPaused(bool);
+ WEBCORE_EXPORT static void emptyDatabaseFilesRemovalTaskWillBeScheduled();
+ WEBCORE_EXPORT static void emptyDatabaseFilesRemovalTaskDidFinish();
#endif
void setClient(DatabaseManagerClient*);
// From a secondary thread, must be thread safe with its data
- void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
+ void scheduleNotifyDatabaseChanged(const SecurityOriginData&, const String& name);
- bool hasEntryForOrigin(SecurityOrigin*);
-
- void doneCreatingDatabase(DatabaseBackendBase*);
+ void doneCreatingDatabase(Database&);
private:
- bool hasEntryForOriginNoLock(SecurityOrigin* origin);
- String fullPathForDatabaseNoLock(SecurityOrigin*, const String& name, bool createIfDoesNotExist);
- bool databaseNamesForOriginNoLock(SecurityOrigin* origin, Vector<String>& resultVector);
- unsigned long long quotaForOriginNoLock(SecurityOrigin* origin);
+ explicit DatabaseTracker(const String& databasePath);
+
+ ExceptionOr<void> hasAdequateQuotaForOrigin(const SecurityOriginData&, unsigned estimatedSize);
+
+ bool hasEntryForOriginNoLock(const SecurityOriginData&);
+ String fullPathForDatabaseNoLock(const SecurityOriginData&, const String& name, bool createIfDoesNotExist);
+ Vector<String> databaseNamesNoLock(const SecurityOriginData&);
+ unsigned long long quotaNoLock(const SecurityOriginData&);
String trackerDatabasePath() const;
@@ -137,59 +131,65 @@ private:
};
void openTrackerDatabase(TrackerCreationAction);
- String originPath(SecurityOrigin*) const;
+ String originPath(const SecurityOriginData&) const;
+
+ bool hasEntryForDatabase(const SecurityOriginData&, const String& databaseIdentifier);
- bool hasEntryForDatabase(SecurityOrigin*, const String& databaseIdentifier);
+ bool addDatabase(const SecurityOriginData&, const String& name, const String& path);
- bool addDatabase(SecurityOrigin*, const String& name, const String& path);
+ enum class DeletionMode {
+ Immediate,
+#if PLATFORM(IOS)
+ // Deferred deletion is currently only supported on iOS
+ // (see removeDeletedOpenedDatabases etc, above).
+ Deferred,
+ Default = Deferred
+#else
+ Default = Immediate
+#endif
+ };
- bool deleteDatabaseFile(SecurityOrigin*, const String& name);
+ bool deleteOrigin(const SecurityOriginData&, DeletionMode);
+ bool deleteDatabaseFile(const SecurityOriginData&, const String& name, DeletionMode);
- void deleteOriginLockFor(SecurityOrigin*);
+ void deleteOriginLockFor(const SecurityOriginData&);
- typedef HashSet<DatabaseBackendBase*> DatabaseSet;
- typedef HashMap<String, DatabaseSet*> DatabaseNameMap;
- typedef HashMap<RefPtr<SecurityOrigin>, DatabaseNameMap*> DatabaseOriginMap;
+ using DatabaseSet = HashSet<Database*>;
+ using DatabaseNameMap = HashMap<String, DatabaseSet*>;
+ using DatabaseOriginMap = HashMap<SecurityOriginData, DatabaseNameMap*>;
- Mutex m_openDatabaseMapGuard;
- mutable OwnPtr<DatabaseOriginMap> m_openDatabaseMap;
+ Lock m_openDatabaseMapGuard;
+ mutable std::unique_ptr<DatabaseOriginMap> m_openDatabaseMap;
// This lock protects m_database, m_originLockMap, m_databaseDirectoryPath, m_originsBeingDeleted, m_beingCreated, and m_beingDeleted.
- Mutex m_databaseGuard;
+ Lock m_databaseGuard;
SQLiteDatabase m_database;
- typedef HashMap<String, RefPtr<OriginLock>> OriginLockMap;
+ using OriginLockMap = HashMap<String, RefPtr<OriginLock>>;
OriginLockMap m_originLockMap;
String m_databaseDirectoryPath;
- DatabaseManagerClient* m_client;
-
- typedef HashMap<String, long> NameCountMap;
- typedef HashMap<RefPtr<SecurityOrigin>, NameCountMap*, SecurityOriginHash> CreateSet;
- CreateSet m_beingCreated;
- typedef HashSet<String> NameSet;
- HashMap<RefPtr<SecurityOrigin>, NameSet*> m_beingDeleted;
- HashSet<RefPtr<SecurityOrigin>> m_originsBeingDeleted;
- bool isDeletingDatabaseOrOriginFor(SecurityOrigin*, const String& name);
- void recordCreatingDatabase(SecurityOrigin*, const String& name);
- void doneCreatingDatabase(SecurityOrigin*, const String& name);
- bool creatingDatabase(SecurityOrigin*, const String& name);
- bool canDeleteDatabase(SecurityOrigin*, const String& name);
- void recordDeletingDatabase(SecurityOrigin*, const String& name);
- void doneDeletingDatabase(SecurityOrigin*, const String& name);
- bool isDeletingDatabase(SecurityOrigin*, const String& name);
- bool canDeleteOrigin(SecurityOrigin*);
- bool isDeletingOrigin(SecurityOrigin*);
- void recordDeletingOrigin(SecurityOrigin*);
- void doneDeletingOrigin(SecurityOrigin*);
+ DatabaseManagerClient* m_client { nullptr };
+
+ HashMap<SecurityOriginData, std::unique_ptr<HashCountedSet<String>>> m_beingCreated;
+ HashMap<SecurityOriginData, std::unique_ptr<HashSet<String>>> m_beingDeleted;
+ HashSet<SecurityOriginData> m_originsBeingDeleted;
+ bool isDeletingDatabaseOrOriginFor(const SecurityOriginData&, const String& name);
+ void recordCreatingDatabase(const SecurityOriginData&, const String& name);
+ void doneCreatingDatabase(const SecurityOriginData&, const String& name);
+ bool creatingDatabase(const SecurityOriginData&, const String& name);
+ bool canDeleteDatabase(const SecurityOriginData&, const String& name);
+ void recordDeletingDatabase(const SecurityOriginData&, const String& name);
+ void doneDeletingDatabase(const SecurityOriginData&, const String& name);
+ bool isDeletingDatabase(const SecurityOriginData&, const String& name);
+ bool canDeleteOrigin(const SecurityOriginData&);
+ bool isDeletingOrigin(const SecurityOriginData&);
+ void recordDeletingOrigin(const SecurityOriginData&);
+ void doneDeletingOrigin(const SecurityOriginData&);
static void scheduleForNotification();
- static void notifyDatabasesChanged(void*);
+ static void notifyDatabasesChanged();
};
} // namespace WebCore
-
-#endif // ENABLE(SQL_DATABASE)
-
-#endif // DatabaseTracker_h