193ebc3b49f59219435dc10210967548483b9af0
[WebKit-https.git] / Source / WebCore / Modules / webdatabase / DatabaseManager.cpp
1 /*
2  * Copyright (C) 2012 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #include "config.h"
27 #include "DatabaseManager.h"
28
29 #if ENABLE(SQL_DATABASE)
30
31 #include "AbstractDatabase.h"
32 #include "DatabaseContext.h"
33 #include "DatabaseTracker.h"
34 #include <wtf/UnusedParam.h>
35
36 #if USE(PLATFORM_STRATEGIES)
37 #include "DatabaseStrategy.h"
38 #include "PlatformStrategies.h"
39 #else
40 #include "DBBackendServer.h"
41 #endif
42
43 namespace WebCore {
44
45 DatabaseManager& DatabaseManager::manager()
46 {
47     static DatabaseManager* dbManager = 0;
48     if (!dbManager)
49         dbManager = new DatabaseManager();
50
51     return *dbManager;
52 }
53
54 DatabaseManager::DatabaseManager()
55 {
56 #if USE(PLATFORM_STRATEGIES)
57     m_server = platformStrategies()->databaseStrategy()->getDatabaseServer();
58 #else
59     m_server = new DBBackend::Server;
60 #endif
61     ASSERT(m_server); // We should always have a server to work with.
62 }
63
64 void DatabaseManager::initialize(const String& databasePath)
65 {
66 #if !PLATFORM(CHROMIUM)
67     DatabaseTracker::initializeTracker(databasePath);
68 #else
69     UNUSED_PARAM(databasePath);
70 #endif
71 }
72
73 #if !PLATFORM(CHROMIUM)
74 void DatabaseManager::setClient(DatabaseManagerClient* client)
75 {
76     DatabaseTracker::tracker().setClient(client);
77 }
78
79 String DatabaseManager::databaseDirectoryPath() const
80 {
81     return DatabaseTracker::tracker().databaseDirectoryPath();
82 }
83
84 void DatabaseManager::setDatabaseDirectoryPath(const String& path)
85 {
86     DatabaseTracker::tracker().setDatabaseDirectoryPath(path);
87 }
88 #endif
89
90 bool DatabaseManager::isAvailable()
91 {
92     return AbstractDatabase::isAvailable();
93 }
94
95 void DatabaseManager::setIsAvailable(bool available)
96 {
97     AbstractDatabase::setIsAvailable(available);
98 }
99
100 bool DatabaseManager::hasOpenDatabases(ScriptExecutionContext* context)
101 {
102     return DatabaseContext::hasOpenDatabases(context);
103 }
104
105 void DatabaseManager::stopDatabases(ScriptExecutionContext* context, DatabaseTaskSynchronizer* synchronizer)
106 {
107     DatabaseContext::stopDatabases(context, synchronizer);
108 }
109
110 String DatabaseManager::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfDoesNotExist)
111 {
112     return DatabaseTracker::tracker().fullPathForDatabase(origin, name, createIfDoesNotExist);
113 }
114
115 #if !PLATFORM(CHROMIUM)
116 bool DatabaseManager::hasEntryForOrigin(SecurityOrigin* origin)
117 {
118     return DatabaseTracker::tracker().hasEntryForOrigin(origin);
119 }
120
121 void DatabaseManager::origins(Vector<RefPtr<SecurityOrigin> >& result)
122 {
123     DatabaseTracker::tracker().origins(result);
124 }
125
126 bool DatabaseManager::databaseNamesForOrigin(SecurityOrigin* origin, Vector<String>& result)
127 {
128     return DatabaseTracker::tracker().databaseNamesForOrigin(origin, result);
129 }
130
131 DatabaseDetails DatabaseManager::detailsForNameAndOrigin(const String& name, SecurityOrigin* origin)
132 {
133     return DatabaseTracker::tracker().detailsForNameAndOrigin(name, origin);
134 }
135
136 unsigned long long DatabaseManager::usageForOrigin(SecurityOrigin* origin)
137 {
138     return DatabaseTracker::tracker().usageForOrigin(origin);
139 }
140
141 unsigned long long DatabaseManager::quotaForOrigin(SecurityOrigin* origin)
142 {
143     return DatabaseTracker::tracker().quotaForOrigin(origin);
144 }
145
146 void DatabaseManager::setQuota(SecurityOrigin* origin, unsigned long long quotaSize)
147 {
148     DatabaseTracker::tracker().setQuota(origin, quotaSize);
149 }
150
151 void DatabaseManager::deleteAllDatabases()
152 {
153     DatabaseTracker::tracker().deleteAllDatabases();
154 }
155
156 bool DatabaseManager::deleteOrigin(SecurityOrigin* origin)
157 {
158     return DatabaseTracker::tracker().deleteOrigin(origin);
159 }
160
161 bool DatabaseManager::deleteDatabase(SecurityOrigin* origin, const String& name)
162 {
163     return DatabaseTracker::tracker().deleteDatabase(origin, name);
164 }
165
166 #else // PLATFORM(CHROMIUM)
167 void DatabaseManager::closeDatabasesImmediately(const String& originIdentifier, const String& name)
168 {
169     DatabaseTracker::tracker().closeDatabasesImmediately(originIdentifier, name);
170 }
171 #endif // PLATFORM(CHROMIUM)
172
173 void DatabaseManager::interruptAllDatabasesForContext(const ScriptExecutionContext* context)
174 {
175     DatabaseTracker::tracker().interruptAllDatabasesForContext(context);
176 }
177
178 } // namespace WebCore
179
180 #endif // ENABLE(SQL_DATABASE)