|
Lines 35-46
WebCore/storage/DatabaseTracker.cpp_sec1
|
| 35 |
#include "Database.h" |
35 |
#include "Database.h" |
| 36 |
#include "DatabaseTrackerClient.h" |
36 |
#include "DatabaseTrackerClient.h" |
| 37 |
#include "Document.h" |
37 |
#include "Document.h" |
| 38 |
#include "FileSystem.h" |
|
|
| 39 |
#include "Logging.h" |
38 |
#include "Logging.h" |
| 40 |
#include "OriginQuotaManager.h" |
39 |
#include "OriginQuotaManager.h" |
| 41 |
#include "Page.h" |
40 |
#include "Page.h" |
| 42 |
#include "SecurityOrigin.h" |
41 |
#include "SecurityOrigin.h" |
| 43 |
#include "SecurityOriginHash.h" |
42 |
#include "SecurityOriginHash.h" |
|
|
43 |
#include "SQLiteFileSystem.h" |
| 44 |
#include "SQLiteStatement.h" |
44 |
#include "SQLiteStatement.h" |
| 45 |
#include <wtf/MainThread.h> |
45 |
#include <wtf/MainThread.h> |
| 46 |
#include <wtf/StdLibExtras.h> |
46 |
#include <wtf/StdLibExtras.h> |
|
Lines 69-74
DatabaseTracker::DatabaseTracker()
WebCore/storage/DatabaseTracker.cpp_sec2
|
| 69 |
, m_thread(currentThread()) |
69 |
, m_thread(currentThread()) |
| 70 |
#endif |
70 |
#endif |
| 71 |
{ |
71 |
{ |
|
|
72 |
SQLiteFileSystem::registerSQLiteVFS(); |
| 72 |
} |
73 |
} |
| 73 |
|
74 |
|
| 74 |
void DatabaseTracker::setDatabaseDirectoryPath(const String& path) |
75 |
void DatabaseTracker::setDatabaseDirectoryPath(const String& path) |
|
Lines 87-95
const String& DatabaseTracker::databaseD
WebCore/storage/DatabaseTracker.cpp_sec3
|
| 87 |
String DatabaseTracker::trackerDatabasePath() const |
88 |
String DatabaseTracker::trackerDatabasePath() const |
| 88 |
{ |
89 |
{ |
| 89 |
ASSERT(currentThread() == m_thread); |
90 |
ASSERT(currentThread() == m_thread); |
| 90 |
if (m_databaseDirectoryPath.isEmpty()) |
91 |
return SQLiteFileSystem::appendDatabaseFileNameToPath(m_databaseDirectoryPath, "Databases.db"); |
| 91 |
return String(); |
|
|
| 92 |
return pathByAppendingComponent(m_databaseDirectoryPath, "Databases.db"); |
| 93 |
} |
92 |
} |
| 94 |
|
93 |
|
| 95 |
void DatabaseTracker::openTrackerDatabase(bool createIfDoesNotExist) |
94 |
void DatabaseTracker::openTrackerDatabase(bool createIfDoesNotExist) |
|
Lines 100-112
void DatabaseTracker::openTrackerDatabas
WebCore/storage/DatabaseTracker.cpp_sec4
|
| 100 |
return; |
99 |
return; |
| 101 |
|
100 |
|
| 102 |
String databasePath = trackerDatabasePath(); |
101 |
String databasePath = trackerDatabasePath(); |
| 103 |
if (databasePath.isEmpty()) |
102 |
if (!SQLiteFileSystem::ensureDatabaseFileExists(databasePath, createIfDoesNotExist)) |
| 104 |
return; |
|
|
| 105 |
|
| 106 |
if (!createIfDoesNotExist && !fileExists(databasePath)) |
| 107 |
return; |
103 |
return; |
| 108 |
|
104 |
|
| 109 |
makeAllDirectories(m_databaseDirectoryPath); |
|
|
| 110 |
if (!m_database.open(databasePath)) { |
105 |
if (!m_database.open(databasePath)) { |
| 111 |
// FIXME: What do do here? |
106 |
// FIXME: What do do here? |
| 112 |
return; |
107 |
return; |
|
Lines 190-198
bool DatabaseTracker::hasEntryForDatabas
WebCore/storage/DatabaseTracker.cpp_sec5
|
| 190 |
String DatabaseTracker::originPath(SecurityOrigin* origin) const |
185 |
String DatabaseTracker::originPath(SecurityOrigin* origin) const |
| 191 |
{ |
186 |
{ |
| 192 |
ASSERT(currentThread() == m_thread); |
187 |
ASSERT(currentThread() == m_thread); |
| 193 |
if (m_databaseDirectoryPath.isEmpty()) |
188 |
return SQLiteFileSystem::appendDatabaseFileNameToPath(m_databaseDirectoryPath, origin->databaseIdentifier()); |
| 194 |
return String(); |
|
|
| 195 |
return pathByAppendingComponent(m_databaseDirectoryPath, origin->databaseIdentifier()); |
| 196 |
} |
189 |
} |
| 197 |
|
190 |
|
| 198 |
String DatabaseTracker::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfNotExists) |
191 |
String DatabaseTracker::fullPathForDatabase(SecurityOrigin* origin, const String& name, bool createIfNotExists) |
|
Lines 206-212
String DatabaseTracker::fullPathForDatab
WebCore/storage/DatabaseTracker.cpp_sec6
|
| 206 |
String originPath = this->originPath(origin); |
199 |
String originPath = this->originPath(origin); |
| 207 |
|
200 |
|
| 208 |
// Make sure the path for this SecurityOrigin exists |
201 |
// Make sure the path for this SecurityOrigin exists |
| 209 |
if (createIfNotExists && !makeAllDirectories(originPath)) |
202 |
if (createIfNotExists && !SQLiteFileSystem::ensureDatabaseDirectoryExists(originPath)) |
| 210 |
return String(); |
203 |
return String(); |
| 211 |
|
204 |
|
| 212 |
// See if we have a path for this database yet |
205 |
// See if we have a path for this database yet |
|
Lines 224-230
String DatabaseTracker::fullPathForDatab
WebCore/storage/DatabaseTracker.cpp_sec7
|
| 224 |
int result = statement.step(); |
217 |
int result = statement.step(); |
| 225 |
|
218 |
|
| 226 |
if (result == SQLResultRow) |
219 |
if (result == SQLResultRow) |
| 227 |
return pathByAppendingComponent(originPath, statement.getColumnText(0)); |
220 |
return SQLiteFileSystem::appendDatabaseFileNameToPath(originPath, statement.getColumnText(0)); |
| 228 |
if (!createIfNotExists) |
221 |
if (!createIfNotExists) |
| 229 |
return String(); |
222 |
return String(); |
| 230 |
|
223 |
|
|
Lines 241-262
String DatabaseTracker::fullPathForDatab
WebCore/storage/DatabaseTracker.cpp_sec8
|
| 241 |
return String(); |
234 |
return String(); |
| 242 |
result = sequenceStatement.step(); |
235 |
result = sequenceStatement.step(); |
| 243 |
|
236 |
|
| 244 |
// This has a range of 2^63 and starts at 0 for every time a user resets Safari - |
237 |
String fileName = SQLiteFileSystem::getFileNameForNewDatabase(originPath, origin->databaseIdentifier(), name, &m_database); |
| 245 |
// I can't imagine it'd over overflow |
238 |
if (!addDatabase(origin, name, fileName)) |
| 246 |
int64_t seq = 0; |
|
|
| 247 |
if (result == SQLResultRow) { |
| 248 |
seq = sequenceStatement.getColumnInt64(0); |
| 249 |
} else if (result != SQLResultDone) |
| 250 |
return String(); |
| 251 |
sequenceStatement.finalize(); |
| 252 |
|
| 253 |
String filename; |
| 254 |
do { |
| 255 |
++seq; |
| 256 |
filename = pathByAppendingComponent(originPath, String::format("%016llx.db", seq)); |
| 257 |
} while (fileExists(filename)); |
| 258 |
|
| 259 |
if (!addDatabase(origin, name, String::format("%016llx.db", seq))) |
| 260 |
return String(); |
239 |
return String(); |
| 261 |
|
240 |
|
| 262 |
// If this origin's quota is being tracked (open handle to a database in this origin), add this new database |
241 |
// If this origin's quota is being tracked (open handle to a database in this origin), add this new database |
|
Lines 264-273
String DatabaseTracker::fullPathForDatab
WebCore/storage/DatabaseTracker.cpp_sec9
|
| 264 |
{ |
243 |
{ |
| 265 |
Locker<OriginQuotaManager> locker(originQuotaManager()); |
244 |
Locker<OriginQuotaManager> locker(originQuotaManager()); |
| 266 |
if (originQuotaManager().tracksOrigin(origin)) |
245 |
if (originQuotaManager().tracksOrigin(origin)) |
| 267 |
originQuotaManager().addDatabase(origin, name, filename); |
246 |
originQuotaManager().addDatabase(origin, name, fileName); |
| 268 |
} |
247 |
} |
| 269 |
|
248 |
|
| 270 |
return filename; |
249 |
return fileName; |
| 271 |
} |
250 |
} |
| 272 |
|
251 |
|
| 273 |
void DatabaseTracker::populateOrigins() |
252 |
void DatabaseTracker::populateOrigins() |
|
Lines 423-430
unsigned long long DatabaseTracker::usag
WebCore/storage/DatabaseTracker.cpp_sec10
|
| 423 |
if (path.isEmpty()) |
402 |
if (path.isEmpty()) |
| 424 |
return 0; |
403 |
return 0; |
| 425 |
|
404 |
|
| 426 |
long long size; |
405 |
return SQLiteFileSystem::getDatabaseFileSize(path); |
| 427 |
return getFileSize(path, size) ? size : 0; |
|
|
| 428 |
} |
406 |
} |
| 429 |
|
407 |
|
| 430 |
void DatabaseTracker::addOpenDatabase(Database* database) |
408 |
void DatabaseTracker::addOpenDatabase(Database* database) |
|
Lines 665-671
void DatabaseTracker::deleteOrigin(Secur
WebCore/storage/DatabaseTracker.cpp_sec11
|
| 665 |
return; |
643 |
return; |
| 666 |
} |
644 |
} |
| 667 |
|
645 |
|
| 668 |
deleteEmptyDirectory(originPath(origin)); |
646 |
SQLiteFileSystem::deleteEmptyDatabaseDirectory(originPath(origin)); |
| 669 |
|
647 |
|
| 670 |
RefPtr<SecurityOrigin> originPossiblyLastReference = origin; |
648 |
RefPtr<SecurityOrigin> originPossiblyLastReference = origin; |
| 671 |
{ |
649 |
{ |
|
Lines 679-686
void DatabaseTracker::deleteOrigin(Secur
WebCore/storage/DatabaseTracker.cpp_sec12
|
| 679 |
if (m_quotaMap->isEmpty()) { |
657 |
if (m_quotaMap->isEmpty()) { |
| 680 |
if (m_database.isOpen()) |
658 |
if (m_database.isOpen()) |
| 681 |
m_database.close(); |
659 |
m_database.close(); |
| 682 |
deleteFile(trackerDatabasePath()); |
660 |
SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath()); |
| 683 |
deleteEmptyDirectory(m_databaseDirectoryPath); |
661 |
SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_databaseDirectoryPath); |
| 684 |
} |
662 |
} |
| 685 |
} |
663 |
} |
| 686 |
|
664 |
|
|
Lines 763-769
bool DatabaseTracker::deleteDatabaseFile
WebCore/storage/DatabaseTracker.cpp_sec13
|
| 763 |
for (unsigned i = 0; i < deletedDatabases.size(); ++i) |
741 |
for (unsigned i = 0; i < deletedDatabases.size(); ++i) |
| 764 |
deletedDatabases[i]->markAsDeletedAndClose(); |
742 |
deletedDatabases[i]->markAsDeletedAndClose(); |
| 765 |
|
743 |
|
| 766 |
return deleteFile(fullPath); |
744 |
return SQLiteFileSystem::deleteDatabaseFile(fullPath); |
| 767 |
} |
745 |
} |
| 768 |
|
746 |
|
| 769 |
void DatabaseTracker::setClient(DatabaseTrackerClient* client) |
747 |
void DatabaseTracker::setClient(DatabaseTrackerClient* client) |