#pragma once
#include <WebCore/SQLiteDatabase.h>
#include <WebCore/Timer.h>
#include <wtf/Condition.h>
#include <wtf/HashMap.h>
#include <wtf/text/StringHash.h>
namespace WebCore {
class StorageSyncManager;
}
namespace WebKit {
class StorageAreaImpl;
class StorageAreaSync : public ThreadSafeRefCounted<StorageAreaSync> {
public:
static Ref<StorageAreaSync> create(RefPtr<WebCore::StorageSyncManager>&&, Ref<StorageAreaImpl>&&, const String& databaseIdentifier);
~StorageAreaSync();
void scheduleFinalSync();
void blockUntilImportComplete();
void scheduleItemForSync(const String& key, const String& value);
void scheduleClear();
void scheduleCloseDatabase();
void scheduleSync();
private:
StorageAreaSync(RefPtr<WebCore::StorageSyncManager>&&, Ref<StorageAreaImpl>&&, const String& databaseIdentifier);
WebCore::Timer m_syncTimer;
HashMap<String, String> m_changedItems;
bool m_itemsCleared;
bool m_finalSyncScheduled;
RefPtr<StorageAreaImpl> m_storageArea;
RefPtr<WebCore::StorageSyncManager> m_syncManager;
WebCore::SQLiteDatabase m_database;
public:
void performImport();
void performSync();
void deleteEmptyDatabase();
private:
enum OpenDatabaseParamType {
CreateIfNonExistent,
SkipIfNonExistent
};
void syncTimerFired();
void openDatabase(OpenDatabaseParamType openingStrategy);
void sync(bool clearItems, const HashMap<String, String>& items);
const String m_databaseIdentifier;
Lock m_syncLock;
HashMap<String, String> m_itemsPendingSync;
bool m_clearItemsWhileSyncing;
bool m_syncScheduled;
bool m_syncInProgress;
bool m_databaseOpenFailed;
bool m_syncCloseDatabase;
mutable Lock m_importLock;
Condition m_importCondition;
bool m_importComplete;
void markImported();
void migrateItemTableIfNeeded();
};
}