#ifndef DatabaseTracker_h
#define DatabaseTracker_h
#if ENABLE(DATABASE)
#include "PlatformString.h"
#if !PLATFORM(CHROMIUM)
#include "DatabaseDetails.h"
#include "SQLiteDatabase.h"
#include "StringHash.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#endif // !PLATFORM(CHROMIUM)
namespace WebCore {
class Database;
class ScriptExecutionContext;
class SecurityOrigin;
#if !PLATFORM(CHROMIUM)
class DatabaseTrackerClient;
class OriginQuotaManager;
struct SecurityOriginHash;
struct SecurityOriginTraits;
#endif // !PLATFORM(CHROMIUM)
class DatabaseTracker : public Noncopyable {
public:
static DatabaseTracker& tracker();
bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize);
void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize);
String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
void addOpenDatabase(Database*);
void removeOpenDatabase(Database*);
unsigned long long getMaxSizeForDatabase(const Database*);
static void decrementTransactionInProgressCount();
static void incrementTransactionInProgressCount();
private:
DatabaseTracker();
#if !PLATFORM(CHROMIUM)
public:
void setDatabaseDirectoryPath(const String&);
const String& databaseDirectoryPath() const;
void origins(Vector<RefPtr<SecurityOrigin> >& result);
bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
unsigned long long usageForDatabase(const String&, SecurityOrigin*);
unsigned long long usageForOrigin(SecurityOrigin*);
unsigned long long quotaForOrigin(SecurityOrigin*);
void setQuota(SecurityOrigin*, unsigned long long);
void deleteAllDatabases();
bool deleteOrigin(SecurityOrigin*);
bool deleteDatabase(SecurityOrigin*, const String& name);
void originsDidChange();
void removeDeletedOpenedDatabases();
static bool deleteDatabaseFileIfEmpty(const String&);
static Mutex& openDatabaseMutex();
static void emptyDatabaseFilesRemovalTaskWillBeScheduled();
static void emptyDatabaseFilesRemovalTaskDidFinish();
void setDatabasesPaused(bool);
void setClient(DatabaseTrackerClient*);
void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
OriginQuotaManager& originQuotaManager();
bool hasEntryForOrigin(SecurityOrigin*);
private:
String trackerDatabasePath() const;
void openTrackerDatabase(bool createIfDoesNotExist);
String originPath(SecurityOrigin*) const;
bool hasEntryForDatabase(SecurityOrigin*, const String& databaseIdentifier);
bool addDatabase(SecurityOrigin*, const String& name, const String& path);
void populateOrigins();
bool deleteDatabaseFile(SecurityOrigin*, const String& name);
SQLiteDatabase m_database;
typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHash> QuotaMap;
Mutex m_quotaMapGuard;
mutable OwnPtr<QuotaMap> m_quotaMap;
typedef HashSet<Database*> DatabaseSet;
typedef HashMap<String, DatabaseSet*> DatabaseNameMap;
typedef HashMap<RefPtr<SecurityOrigin>, DatabaseNameMap*, SecurityOriginHash> DatabaseOriginMap;
Mutex m_openDatabaseMapGuard;
mutable OwnPtr<DatabaseOriginMap> m_openDatabaseMap;
OwnPtr<OriginQuotaManager> m_quotaManager;
String m_databaseDirectoryPath;
DatabaseTrackerClient* m_client;
std::pair<SecurityOrigin*, DatabaseDetails>* m_proposedDatabase;
#ifndef NDEBUG
ThreadIdentifier m_thread;
#endif
static void scheduleForNotification();
static void notifyDatabasesChanged(void*);
#endif // !PLATFORM(CHROMIUM)
};
}
#endif // ENABLE(DATABASE)
#endif // DatabaseTracker_h