Remove excessive headers from WebCore/{Modules,animation,crypto,domjit}
[WebKit-https.git] / Source / WebCore / Modules / webdatabase / DatabaseManager.h
index b7d3812..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
-
-#if ENABLE(SQL_DATABASE)
+#pragma once
 
 #include "DatabaseDetails.h"
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
+#include "ExceptionOr.h"
+#include <wtf/Assertions.h>
+#include <wtf/HashSet.h>
+#include <wtf/Lock.h>
 
 namespace WebCore {
 
-class AbstractDatabaseServer;
+class Database;
+class DatabaseCallback;
+class DatabaseContext;
 class DatabaseManagerClient;
 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);
-#if !PLATFORM(CHROMIUM)
-    void setClient(DatabaseManagerClient*);
-    String databaseDirectoryPath() const;
-    void setDatabaseDirectoryPath(const String&);
-#endif
+    WEBCORE_EXPORT void initialize(const String& databasePath);
+    WEBCORE_EXPORT void setClient(DatabaseManagerClient*);
 
     bool isAvailable();
-    void setIsAvailable(bool);
+    WEBCORE_EXPORT void setIsAvailable(bool);
 
-    bool hasOpenDatabases(ScriptExecutionContext*);
-    // When the database cleanup is done, cleanupSync will be signalled.
-    void stopDatabases(ScriptExecutionContext*, DatabaseTaskSynchronizer*);
+    // This gets a DatabaseContext for the specified ScriptExecutionContext.
+    // If one doesn't already exist, it will create a new one.
+    Ref<DatabaseContext> databaseContext(ScriptExecutionContext&);
 
-    String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
+    ExceptionOr<Ref<Database>> openDatabase(ScriptExecutionContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize, RefPtr<DatabaseCallback>&&);
 
-#if !PLATFORM(CHROMIUM)
-    bool hasEntryForOrigin(SecurityOrigin*);
-    void origins(Vector<RefPtr<SecurityOrigin> >& result);
-    bool databaseNamesForOrigin(SecurityOrigin*, Vector<String>& result);
-    DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin*);
+    WEBCORE_EXPORT bool hasOpenDatabases(ScriptExecutionContext&);
+    void stopDatabases(ScriptExecutionContext&, DatabaseTaskSynchronizer*);
 
-    unsigned long long usageForOrigin(SecurityOrigin*);
-    unsigned long long quotaForOrigin(SecurityOrigin*);
+    String fullPathForDatabase(SecurityOrigin&, const String& name, bool createIfDoesNotExist = true);
 
-    void setQuota(SecurityOrigin*, unsigned long long);
+    WEBCORE_EXPORT DatabaseDetails detailsForNameAndOrigin(const String&, SecurityOrigin&);
 
-    void deleteAllDatabases();
-    bool deleteOrigin(SecurityOrigin*);
-    bool deleteDatabase(SecurityOrigin*, const String& name);
+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(const ScriptExecutionContext*);
+    class ProposedDatabase;
+    void addProposedDatabase(ProposedDatabase&);
+    void removeProposedDatabase(ProposedDatabase&);
 
-private:
-    DatabaseManager();
-    ~DatabaseManager() { }
+    static void logErrorMessage(ScriptExecutionContext&, const String& message);
 
-    AbstractDatabaseServer* m_server;
+    DatabaseManagerClient* m_client { nullptr };
+    bool m_databaseIsAvailable { true };
+
+    Lock m_proposedDatabasesMutex;
+    HashSet<ProposedDatabase*> m_proposedDatabases;
 };
 
 } // namespace WebCore
-
-#endif // ENABLE(SQL_DATABASE)
-
-#endif // DatabaseManager_h