Remove excessive headers from WebCore/{Modules,animation,crypto,domjit}
[WebKit-https.git] / Source / WebCore / Modules / webdatabase / DatabaseManager.h
index eab1f47..97db0eb 100644 (file)
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef DatabaseManager_h
-#define DatabaseManager_h
+#pragma once
 
-#if ENABLE(SQL_DATABASE)
-
-#include "AbstractDatabaseServer.h"
-#include "DatabaseBasicTypes.h"
-#include "DatabaseError.h"
+#include "DatabaseDetails.h"
+#include "ExceptionOr.h"
 #include <wtf/Assertions.h>
-#include <wtf/HashMap.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/Threading.h>
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
 
 namespace WebCore {
 
-class AbstractDatabaseServer;
 class Database;
 class DatabaseCallback;
 class DatabaseContext;
 class DatabaseManagerClient;
-class DatabaseSync;
 class DatabaseTaskSynchronizer;
+class Exception;
 class SecurityOrigin;
 class ScriptExecutionContext;
+struct SecurityOriginData;
 
 class DatabaseManager {
-    WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_NONCOPYABLE(DatabaseManager);
+    friend class WTF::NeverDestroyed<DatabaseManager>;
 public:
-    static DatabaseManager& manager();
+    WEBCORE_EXPORT static DatabaseManager& singleton();
 
-    void initialize(const String& databasePath);
-    void setClient(DatabaseManagerClient*);
-    String databaseDirectoryPath() const;
-    void setDatabaseDirectoryPath(const String&);
+    WEBCORE_EXPORT void initialize(const String& databasePath);
+    WEBCORE_EXPORT void setClient(DatabaseManagerClient*);
 
     bool isAvailable();
-    void setIsAvailable(bool);
+    WEBCORE_EXPORT void setIsAvailable(bool);
 
     // This gets a DatabaseContext for the specified ScriptExecutionContext.
     // If one doesn't already exist, it will create a new one.
-    PassRefPtr<DatabaseContext> databaseContextFor(ScriptExecutionContext*);
-
-    // These 2 methods are for DatabaseContext (un)registration, and should only
-    // be called by the DatabaseContext constructor and destructor.
-    void registerDatabaseContext(DatabaseContext*);
-    void unregisterDatabaseContext(DatabaseContext*);
-
-#if !ASSERT_DISABLED
-    void didConstructDatabaseContext();
-    void didDestructDatabaseContext();
-#else
-    void didConstructDatabaseContext() { }
-    void didDestructDatabaseContext() { }
-#endif
-
-    PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, DatabaseError&);
-    PassRefPtr<DatabaseSync> openDatabaseSync(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, DatabaseError&);
-
-    bool hasOpenDatabases(ScriptExecutionContext*);
-    void stopDatabases(ScriptExecutionContext*, DatabaseTaskSynchronizer*);
-
-    String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
+    Ref<DatabaseContext> databaseContext(ScriptExecutionContext&);
 
-#if !PLATFORM(CHROMIUM)
-    bool hasEntryForOrigin(SecurityOrigin*);
-    void origins(Vector<RefPtr<SecurityOrigin> >& result);
-    bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
-    DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
+    ExceptionOr<Ref<Database>> openDatabase(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, RefPtr<DatabaseCallback>&&);
 
-    unsigned long long usageForOrigin(SecurityOrigin*);
-    unsigned long long quotaForOrigin(SecurityOrigin*);
+    WEBCORE_EXPORT bool hasOpenDatabases(ScriptExecutionContext&);
+    void stopDatabases(ScriptExecutionContext&, DatabaseTaskSynchronizer*);
 
-    void setQuota(SecurityOrigin*, unsigned long long);
+    String fullPathForDatabase(SecurityOrigin&, const String& name, bool createIfDoesNotExist = true);
 
-    void deleteAllDatabases();
-    bool deleteOrigin(SecurityOrigin*);
-    bool deleteDatabase(SecurityOrigin*, const String& name);
+    WEBCORE_EXPORT DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin&);
 
-    // From a secondary thread, must be thread safe with its data
-    void scheduleNotifyDatabaseChanged(SecurityOrigin*, const String& name);
-
-    void databaseChanged(DatabaseBackend*);
+private:
+    DatabaseManager() = default;
+    ~DatabaseManager() = delete;
 
-#else // PLATFORM(CHROMIUM)
-    void closeDatabasesImmediately(const String& originIdentifier, const String& name);
-#endif // PLATFORM(CHROMIUM)
+    enum OpenAttempt { FirstTryToOpenDatabase, RetryOpenDatabase };
+    ExceptionOr<Ref<Database>> openDatabaseBackend(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase);
+    ExceptionOr<Ref<Database>> tryToOpenDatabaseBackend(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, bool setVersionInNewDatabase, OpenAttempt);
 
-    void interruptAllDatabasesForContext(ScriptExecutionContext*);
+    class ProposedDatabase;
+    void addProposedDatabase(ProposedDatabase&);
+    void removeProposedDatabase(ProposedDatabase&);
 
-    bool canEstablishDatabase(ScriptExecutionContext*, const String& name, const String& displayName, unsigned long estimatedSize);
+    static void logErrorMessage(ScriptExecutionContext&, const String& message);
 
-    void setDatabaseDetails(SecurityOrigin*, const String& name, const String& displayName, unsigned long estimatedSize);
-    unsigned long long getMaxSizeForDatabase(const DatabaseBackend*);
+    DatabaseManagerClient* m_client { nullptr };
+    bool m_databaseIsAvailable { true };
 
-private:
-    DatabaseManager();
-    ~DatabaseManager() { }
-
-    // This gets a DatabaseContext for the specified ScriptExecutionContext if
-    // it already exist previously. Otherwise, it returns 0.
-    PassRefPtr<DatabaseContext> existingDatabaseContextFor(ScriptExecutionContext*);
-
-    AbstractDatabaseServer* m_server;
-    DatabaseManagerClient* m_client;
-    bool m_databaseIsAvailable;
-
-    // Access to the following fields require locking m_contextMapLock:
-    typedef HashMap<ScriptExecutionContext*, DatabaseContext*> ContextMap;
-    ContextMap m_contextMap;
-#if !ASSERT_DISABLED
-    int m_databaseContextRegisteredCount;
-    int m_databaseContextInstanceCount;
-#endif
-    Mutex m_contextMapLock;
+    Lock m_proposedDatabasesMutex;
+    HashSet<ProposedDatabase*> m_proposedDatabases;
 };
 
 } // namespace WebCore
-
-#endif // ENABLE(SQL_DATABASE)
-
-#endif // DatabaseManager_h