OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 return guid; | 195 return guid; |
196 } | 196 } |
197 | 197 |
198 // static | 198 // static |
199 const char* DatabaseBackendBase::databaseInfoTableName() | 199 const char* DatabaseBackendBase::databaseInfoTableName() |
200 { | 200 { |
201 return infoTableName; | 201 return infoTableName; |
202 } | 202 } |
203 | 203 |
204 DatabaseBackendBase::DatabaseBackendBase(DatabaseContext* databaseContext, const
String& name, | 204 DatabaseBackendBase::DatabaseBackendBase(DatabaseContext* databaseContext, const
String& name, |
205 const String& expectedVersion, const String& displayName, unsigned long esti
matedSize, DatabaseType databaseType) | 205 const String& expectedVersion, const String& displayName, unsigned long esti
matedSize) |
206 : m_databaseContext(databaseContext) | 206 : m_databaseContext(databaseContext) |
207 , m_name(name.isolatedCopy()) | 207 , m_name(name.isolatedCopy()) |
208 , m_expectedVersion(expectedVersion.isolatedCopy()) | 208 , m_expectedVersion(expectedVersion.isolatedCopy()) |
209 , m_displayName(displayName.isolatedCopy()) | 209 , m_displayName(displayName.isolatedCopy()) |
210 , m_estimatedSize(estimatedSize) | 210 , m_estimatedSize(estimatedSize) |
211 , m_guid(0) | 211 , m_guid(0) |
212 , m_opened(false) | 212 , m_opened(false) |
213 , m_new(false) | 213 , m_new(false) |
214 , m_isSyncDatabase(databaseType == DatabaseType::Sync) | |
215 { | 214 { |
216 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate
dCopy(); | 215 m_contextThreadSecurityOrigin = m_databaseContext->securityOrigin()->isolate
dCopy(); |
217 | 216 |
218 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); | 217 m_databaseAuthorizer = DatabaseAuthorizer::create(infoTableName); |
219 | 218 |
220 if (m_name.isNull()) | 219 if (m_name.isNull()) |
221 m_name = ""; | 220 m_name = ""; |
222 | 221 |
223 { | 222 { |
224 SafePointAwareMutexLocker locker(guidMutex()); | 223 SafePointAwareMutexLocker locker(guidMutex()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 visitor->trace(m_databaseAuthorizer); | 255 visitor->trace(m_databaseAuthorizer); |
257 } | 256 } |
258 | 257 |
259 void DatabaseBackendBase::closeDatabase() | 258 void DatabaseBackendBase::closeDatabase() |
260 { | 259 { |
261 if (!m_opened) | 260 if (!m_opened) |
262 return; | 261 return; |
263 | 262 |
264 m_sqliteDatabase.close(); | 263 m_sqliteDatabase.close(); |
265 m_opened = false; | 264 m_opened = false; |
266 databaseContext()->didCloseDatabase(*this); | |
267 // See comment at the top this file regarding calling removeOpenDatabase(). | 265 // See comment at the top this file regarding calling removeOpenDatabase(). |
268 DatabaseTracker::tracker().removeOpenDatabase(this); | 266 DatabaseTracker::tracker().removeOpenDatabase(this); |
269 { | 267 { |
270 SafePointAwareMutexLocker locker(guidMutex()); | 268 SafePointAwareMutexLocker locker(guidMutex()); |
271 | 269 |
272 HashSet<DatabaseBackendBase*>* hashSet = guidToDatabaseMap().get(m_guid)
; | 270 HashSet<DatabaseBackendBase*>* hashSet = guidToDatabaseMap().get(m_guid)
; |
273 ASSERT(hashSet); | 271 ASSERT(hashSet); |
274 ASSERT(hashSet->contains(this)); | 272 ASSERT(hashSet->contains(this)); |
275 hashSet->remove(this); | 273 hashSet->remove(this); |
276 if (hashSet->isEmpty()) { | 274 if (hashSet->isEmpty()) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if ((!m_new || shouldSetVersionInNewDatabase) && m_expectedVersion.length()
&& m_expectedVersion != currentVersion) { | 409 if ((!m_new || shouldSetVersionInNewDatabase) && m_expectedVersion.length()
&& m_expectedVersion != currentVersion) { |
412 reportOpenDatabaseResult(6, InvalidStateError, 0); | 410 reportOpenDatabaseResult(6, InvalidStateError, 0); |
413 errorMessage = "unable to open database, version mismatch, '" + m_expect
edVersion + "' does not match the currentVersion of '" + currentVersion + "'"; | 411 errorMessage = "unable to open database, version mismatch, '" + m_expect
edVersion + "' does not match the currentVersion of '" + currentVersion + "'"; |
414 m_sqliteDatabase.close(); | 412 m_sqliteDatabase.close(); |
415 return false; | 413 return false; |
416 } | 414 } |
417 | 415 |
418 ASSERT(m_databaseAuthorizer); | 416 ASSERT(m_databaseAuthorizer); |
419 m_sqliteDatabase.setAuthorizer(m_databaseAuthorizer.get()); | 417 m_sqliteDatabase.setAuthorizer(m_databaseAuthorizer.get()); |
420 | 418 |
421 databaseContext()->didOpenDatabase(*this); | |
422 // See comment at the top this file regarding calling addOpenDatabase(). | 419 // See comment at the top this file regarding calling addOpenDatabase(). |
423 DatabaseTracker::tracker().addOpenDatabase(this); | 420 DatabaseTracker::tracker().addOpenDatabase(this); |
424 m_opened = true; | 421 m_opened = true; |
425 | 422 |
426 // Declare success: | 423 // Declare success: |
427 error = DatabaseError::None; // Clear the presumed error from above. | 424 error = DatabaseError::None; // Clear the presumed error from above. |
428 onExitCaller.setOpenSucceeded(); | 425 onExitCaller.setOpenSucceeded(); |
429 | 426 |
430 if (m_new && !shouldSetVersionInNewDatabase) | 427 if (m_new && !shouldSetVersionInNewDatabase) |
431 m_expectedVersion = ""; // The caller provided a creationCallback which
will set the expected version. | 428 m_expectedVersion = ""; // The caller provided a creationCallback which
will set the expected version. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 int64_t freeSpaceSize = m_sqliteDatabase.freeSpaceSize(); | 581 int64_t freeSpaceSize = m_sqliteDatabase.freeSpaceSize(); |
585 int64_t totalSize = m_sqliteDatabase.totalSize(); | 582 int64_t totalSize = m_sqliteDatabase.totalSize(); |
586 if (totalSize <= 10 * freeSpaceSize) { | 583 if (totalSize <= 10 * freeSpaceSize) { |
587 int result = m_sqliteDatabase.runIncrementalVacuumCommand(); | 584 int result = m_sqliteDatabase.runIncrementalVacuumCommand(); |
588 reportVacuumDatabaseResult(result); | 585 reportVacuumDatabaseResult(result); |
589 if (result != SQLResultOk) | 586 if (result != SQLResultOk) |
590 logErrorMessage(formatErrorMessage("error vacuuming database", resul
t, m_sqliteDatabase.lastErrorMsg())); | 587 logErrorMessage(formatErrorMessage("error vacuuming database", resul
t, m_sqliteDatabase.lastErrorMsg())); |
591 } | 588 } |
592 } | 589 } |
593 | 590 |
594 void DatabaseBackendBase::interrupt() | |
595 { | |
596 m_sqliteDatabase.interrupt(); | |
597 } | |
598 | |
599 bool DatabaseBackendBase::isInterrupted() | |
600 { | |
601 MutexLocker locker(m_sqliteDatabase.databaseMutex()); | |
602 return m_sqliteDatabase.isInterrupted(); | |
603 } | |
604 | |
605 // These are used to generate histograms of errors seen with websql. | 591 // These are used to generate histograms of errors seen with websql. |
606 // See about:histograms in chromium. | 592 // See about:histograms in chromium. |
607 void DatabaseBackendBase::reportOpenDatabaseResult(int errorSite, int webSqlErro
rCode, int sqliteErrorCode) | 593 void DatabaseBackendBase::reportOpenDatabaseResult(int errorSite, int webSqlErro
rCode, int sqliteErrorCode) |
608 { | 594 { |
609 if (Platform::current()->databaseObserver()) { | 595 if (Platform::current()->databaseObserver()) { |
610 Platform::current()->databaseObserver()->reportOpenDatabaseResult( | 596 Platform::current()->databaseObserver()->reportOpenDatabaseResult( |
611 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 597 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
612 stringIdentifier(), isSyncDatabase(), | 598 stringIdentifier(), false, |
613 errorSite, webSqlErrorCode, sqliteErrorCode); | 599 errorSite, webSqlErrorCode, sqliteErrorCode); |
614 } | 600 } |
615 } | 601 } |
616 | 602 |
617 void DatabaseBackendBase::reportChangeVersionResult(int errorSite, int webSqlErr
orCode, int sqliteErrorCode) | 603 void DatabaseBackendBase::reportChangeVersionResult(int errorSite, int webSqlErr
orCode, int sqliteErrorCode) |
618 { | 604 { |
619 if (Platform::current()->databaseObserver()) { | 605 if (Platform::current()->databaseObserver()) { |
620 Platform::current()->databaseObserver()->reportChangeVersionResult( | 606 Platform::current()->databaseObserver()->reportChangeVersionResult( |
621 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 607 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
622 stringIdentifier(), isSyncDatabase(), | 608 stringIdentifier(), false, |
623 errorSite, webSqlErrorCode, sqliteErrorCode); | 609 errorSite, webSqlErrorCode, sqliteErrorCode); |
624 } | 610 } |
625 } | 611 } |
626 | 612 |
627 void DatabaseBackendBase::reportStartTransactionResult(int errorSite, int webSql
ErrorCode, int sqliteErrorCode) | 613 void DatabaseBackendBase::reportStartTransactionResult(int errorSite, int webSql
ErrorCode, int sqliteErrorCode) |
628 { | 614 { |
629 if (Platform::current()->databaseObserver()) { | 615 if (Platform::current()->databaseObserver()) { |
630 Platform::current()->databaseObserver()->reportStartTransactionResult( | 616 Platform::current()->databaseObserver()->reportStartTransactionResult( |
631 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 617 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
632 stringIdentifier(), isSyncDatabase(), | 618 stringIdentifier(), false, |
633 errorSite, webSqlErrorCode, sqliteErrorCode); | 619 errorSite, webSqlErrorCode, sqliteErrorCode); |
634 } | 620 } |
635 } | 621 } |
636 | 622 |
637 void DatabaseBackendBase::reportCommitTransactionResult(int errorSite, int webSq
lErrorCode, int sqliteErrorCode) | 623 void DatabaseBackendBase::reportCommitTransactionResult(int errorSite, int webSq
lErrorCode, int sqliteErrorCode) |
638 { | 624 { |
639 if (Platform::current()->databaseObserver()) { | 625 if (Platform::current()->databaseObserver()) { |
640 Platform::current()->databaseObserver()->reportCommitTransactionResult( | 626 Platform::current()->databaseObserver()->reportCommitTransactionResult( |
641 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 627 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
642 stringIdentifier(), isSyncDatabase(), | 628 stringIdentifier(), false, |
643 errorSite, webSqlErrorCode, sqliteErrorCode); | 629 errorSite, webSqlErrorCode, sqliteErrorCode); |
644 } | 630 } |
645 } | 631 } |
646 | 632 |
647 void DatabaseBackendBase::reportExecuteStatementResult(int errorSite, int webSql
ErrorCode, int sqliteErrorCode) | 633 void DatabaseBackendBase::reportExecuteStatementResult(int errorSite, int webSql
ErrorCode, int sqliteErrorCode) |
648 { | 634 { |
649 if (Platform::current()->databaseObserver()) { | 635 if (Platform::current()->databaseObserver()) { |
650 Platform::current()->databaseObserver()->reportExecuteStatementResult( | 636 Platform::current()->databaseObserver()->reportExecuteStatementResult( |
651 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 637 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
652 stringIdentifier(), isSyncDatabase(), | 638 stringIdentifier(), false, |
653 errorSite, webSqlErrorCode, sqliteErrorCode); | 639 errorSite, webSqlErrorCode, sqliteErrorCode); |
654 } | 640 } |
655 } | 641 } |
656 | 642 |
657 void DatabaseBackendBase::reportVacuumDatabaseResult(int sqliteErrorCode) | 643 void DatabaseBackendBase::reportVacuumDatabaseResult(int sqliteErrorCode) |
658 { | 644 { |
659 if (Platform::current()->databaseObserver()) { | 645 if (Platform::current()->databaseObserver()) { |
660 Platform::current()->databaseObserver()->reportVacuumDatabaseResult( | 646 Platform::current()->databaseObserver()->reportVacuumDatabaseResult( |
661 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), | 647 createDatabaseIdentifierFromSecurityOrigin(securityOrigin()), |
662 stringIdentifier(), isSyncDatabase(), sqliteErrorCode); | 648 stringIdentifier(), false, sqliteErrorCode); |
663 } | 649 } |
664 } | 650 } |
665 | 651 |
666 void DatabaseBackendBase::logErrorMessage(const String& message) | 652 void DatabaseBackendBase::logErrorMessage(const String& message) |
667 { | 653 { |
668 executionContext()->addConsoleMessage(ConsoleMessage::create(StorageMessageS
ource, ErrorMessageLevel, message)); | 654 executionContext()->addConsoleMessage(ConsoleMessage::create(StorageMessageS
ource, ErrorMessageLevel, message)); |
669 } | 655 } |
670 | 656 |
671 ExecutionContext* DatabaseBackendBase::executionContext() const | 657 ExecutionContext* DatabaseBackendBase::executionContext() const |
672 { | 658 { |
673 return databaseContext()->executionContext(); | 659 return databaseContext()->executionContext(); |
674 } | 660 } |
675 | 661 |
676 } // namespace blink | 662 } // namespace blink |
OLD | NEW |