OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // In the case of failure to open the database, the factory methods will | 85 // In the case of failure to open the database, the factory methods will |
86 // simply discard the newly instantiated database backend when they return. | 86 // simply discard the newly instantiated database backend when they return. |
87 // The ref counting mechanims will automatically destruct the un-added | 87 // The ref counting mechanims will automatically destruct the un-added |
88 // (and un-returned) databases instances. | 88 // (and un-returned) databases instances. |
89 | 89 |
90 namespace blink { | 90 namespace blink { |
91 | 91 |
92 // Defines static local variable after making sure that guid lock is held. | 92 // Defines static local variable after making sure that guid lock is held. |
93 // (We can't use DEFINE_STATIC_LOCAL for this because it asserts thread | 93 // (We can't use DEFINE_STATIC_LOCAL for this because it asserts thread |
94 // safety, which is externally guaranteed by the guideMutex lock) | 94 // safety, which is externally guaranteed by the guideMutex lock) |
| 95 #if DCHECK_IS_ON() |
95 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ | 96 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ |
96 ASSERT(GuidMutex().Locked()); \ | 97 DCHECK(GuidMutex().Locked()); \ |
97 static type& name = *new type arguments | 98 static type& name = *new type arguments |
| 99 #else |
| 100 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ |
| 101 static type& name = *new type arguments |
| 102 #endif |
98 | 103 |
99 static const char kVersionKey[] = "WebKitDatabaseVersionKey"; | 104 static const char kVersionKey[] = "WebKitDatabaseVersionKey"; |
100 static const char kInfoTableName[] = "__WebKitDatabaseInfoTable__"; | 105 static const char kInfoTableName[] = "__WebKitDatabaseInfoTable__"; |
101 | 106 |
102 static String FormatErrorMessage(const char* message, | 107 static String FormatErrorMessage(const char* message, |
103 int sqlite_error_code, | 108 int sqlite_error_code, |
104 const char* sqlite_error_message) { | 109 const char* sqlite_error_message) { |
105 return String::Format("%s (%d %s)", message, sqlite_error_code, | 110 return String::Format("%s (%d %s)", message, sqlite_error_code, |
106 sqlite_error_message); | 111 sqlite_error_message); |
107 } | 112 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 171 |
167 typedef HashMap<DatabaseGuid, String> GuidVersionMap; | 172 typedef HashMap<DatabaseGuid, String> GuidVersionMap; |
168 static GuidVersionMap& GuidToVersionMap() { | 173 static GuidVersionMap& GuidToVersionMap() { |
169 DEFINE_STATIC_LOCAL_WITH_LOCK(GuidVersionMap, map, ()); | 174 DEFINE_STATIC_LOCAL_WITH_LOCK(GuidVersionMap, map, ()); |
170 return map; | 175 return map; |
171 } | 176 } |
172 | 177 |
173 // NOTE: Caller must lock guidMutex(). | 178 // NOTE: Caller must lock guidMutex(). |
174 static inline void UpdateGuidVersionMap(DatabaseGuid guid, String new_version) { | 179 static inline void UpdateGuidVersionMap(DatabaseGuid guid, String new_version) { |
175 // Ensure the the mutex is locked. | 180 // Ensure the the mutex is locked. |
176 ASSERT(GuidMutex().Locked()); | 181 #if DCHECK_IS_ON() |
| 182 DCHECK(GuidMutex().Locked()); |
| 183 #endif |
177 | 184 |
178 // Note: It is not safe to put an empty string into the guidToVersionMap() | 185 // Note: It is not safe to put an empty string into the guidToVersionMap() |
179 // map. That's because the map is cross-thread, but empty strings are | 186 // map. That's because the map is cross-thread, but empty strings are |
180 // per-thread. The copy() function makes a version of the string you can | 187 // per-thread. The copy() function makes a version of the string you can |
181 // use on the current thread, but we need a string we can keep in a | 188 // use on the current thread, but we need a string we can keep in a |
182 // cross-thread data structure. | 189 // cross-thread data structure. |
183 // FIXME: This is a quite-awkward restriction to have to program with. | 190 // FIXME: This is a quite-awkward restriction to have to program with. |
184 | 191 |
185 // Map null string to empty string (see comment above). | 192 // Map null string to empty string (see comment above). |
186 GuidToVersionMap().Set( | 193 GuidToVersionMap().Set( |
187 guid, new_version.IsEmpty() ? String() : new_version.IsolatedCopy()); | 194 guid, new_version.IsEmpty() ? String() : new_version.IsolatedCopy()); |
188 } | 195 } |
189 | 196 |
190 static HashCountedSet<DatabaseGuid>& GuidCount() { | 197 static HashCountedSet<DatabaseGuid>& GuidCount() { |
191 DEFINE_STATIC_LOCAL_WITH_LOCK(HashCountedSet<DatabaseGuid>, guid_count, ()); | 198 DEFINE_STATIC_LOCAL_WITH_LOCK(HashCountedSet<DatabaseGuid>, guid_count, ()); |
192 return guid_count; | 199 return guid_count; |
193 } | 200 } |
194 | 201 |
195 static DatabaseGuid GuidForOriginAndName(const String& origin, | 202 static DatabaseGuid GuidForOriginAndName(const String& origin, |
196 const String& name) { | 203 const String& name) { |
197 // Ensure the the mutex is locked. | 204 // Ensure the the mutex is locked. |
198 ASSERT(GuidMutex().Locked()); | 205 #if DCHECK_IS_ON() |
| 206 DCHECK(GuidMutex().Locked()); |
| 207 #endif |
199 | 208 |
200 String string_id = origin + "/" + name; | 209 String string_id = origin + "/" + name; |
201 | 210 |
202 typedef HashMap<String, int> IDGuidMap; | 211 typedef HashMap<String, int> IDGuidMap; |
203 DEFINE_STATIC_LOCAL_WITH_LOCK(IDGuidMap, string_identifier_to_guid_map, ()); | 212 DEFINE_STATIC_LOCAL_WITH_LOCK(IDGuidMap, string_identifier_to_guid_map, ()); |
204 DatabaseGuid guid = string_identifier_to_guid_map.at(string_id); | 213 DatabaseGuid guid = string_identifier_to_guid_map.at(string_id); |
205 if (!guid) { | 214 if (!guid) { |
206 static int current_new_guid = 1; | 215 static int current_new_guid = 1; |
207 guid = current_new_guid++; | 216 guid = current_new_guid++; |
208 string_identifier_to_guid_map.Set(string_id, guid); | 217 string_identifier_to_guid_map.Set(string_id, guid); |
(...skipping 30 matching lines...) Expand all Loading... |
239 MutexLocker locker(GuidMutex()); | 248 MutexLocker locker(GuidMutex()); |
240 guid_ = GuidForOriginAndName(GetSecurityOrigin()->ToString(), name); | 249 guid_ = GuidForOriginAndName(GetSecurityOrigin()->ToString(), name); |
241 GuidCount().insert(guid_); | 250 GuidCount().insert(guid_); |
242 } | 251 } |
243 | 252 |
244 filename_ = DatabaseManager::Manager().FullPathForDatabase( | 253 filename_ = DatabaseManager::Manager().FullPathForDatabase( |
245 GetSecurityOrigin(), name_); | 254 GetSecurityOrigin(), name_); |
246 | 255 |
247 database_thread_security_origin_ = | 256 database_thread_security_origin_ = |
248 context_thread_security_origin_->IsolatedCopy(); | 257 context_thread_security_origin_->IsolatedCopy(); |
249 ASSERT(database_context_->GetDatabaseThread()); | 258 DCHECK(database_context_->GetDatabaseThread()); |
250 ASSERT(database_context_->IsContextThread()); | 259 DCHECK(database_context_->IsContextThread()); |
251 database_task_runner_ = | 260 database_task_runner_ = |
252 TaskRunnerHelper::Get(TaskType::kDatabaseAccess, GetExecutionContext()); | 261 TaskRunnerHelper::Get(TaskType::kDatabaseAccess, GetExecutionContext()); |
253 } | 262 } |
254 | 263 |
255 Database::~Database() { | 264 Database::~Database() { |
256 // SQLite is "multi-thread safe", but each database handle can only be used | 265 // SQLite is "multi-thread safe", but each database handle can only be used |
257 // on a single thread at a time. | 266 // on a single thread at a time. |
258 // | 267 // |
259 // For Database, we open the SQLite database on the DatabaseThread, and | 268 // For Database, we open the SQLite database on the DatabaseThread, and |
260 // hence we should also close it on that same thread. This means that the | 269 // hence we should also close it on that same thread. This means that the |
261 // SQLite database need to be closed by another mechanism (see | 270 // SQLite database need to be closed by another mechanism (see |
262 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite | 271 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite |
263 // database should have already been closed. | 272 // database should have already been closed. |
264 | 273 |
265 ASSERT(!opened_); | 274 DCHECK(!opened_); |
266 } | 275 } |
267 | 276 |
268 DEFINE_TRACE(Database) { | 277 DEFINE_TRACE(Database) { |
269 visitor->Trace(database_context_); | 278 visitor->Trace(database_context_); |
270 visitor->Trace(sqlite_database_); | 279 visitor->Trace(sqlite_database_); |
271 visitor->Trace(database_authorizer_); | 280 visitor->Trace(database_authorizer_); |
272 } | 281 } |
273 | 282 |
274 bool Database::OpenAndVerifyVersion(bool set_version_in_new_database, | 283 bool Database::OpenAndVerifyVersion(bool set_version_in_new_database, |
275 DatabaseError& error, | 284 DatabaseError& error, |
276 String& error_message) { | 285 String& error_message) { |
277 WaitableEvent event; | 286 WaitableEvent event; |
278 if (!GetDatabaseContext()->DatabaseThreadAvailable()) | 287 if (!GetDatabaseContext()->DatabaseThreadAvailable()) |
279 return false; | 288 return false; |
280 | 289 |
281 DatabaseTracker::Tracker().PrepareToOpenDatabase(this); | 290 DatabaseTracker::Tracker().PrepareToOpenDatabase(this); |
282 bool success = false; | 291 bool success = false; |
283 std::unique_ptr<DatabaseOpenTask> task = DatabaseOpenTask::Create( | 292 std::unique_ptr<DatabaseOpenTask> task = DatabaseOpenTask::Create( |
284 this, set_version_in_new_database, &event, error, error_message, success); | 293 this, set_version_in_new_database, &event, error, error_message, success); |
285 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask(std::move(task)); | 294 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask(std::move(task)); |
286 event.Wait(); | 295 event.Wait(); |
287 | 296 |
288 return success; | 297 return success; |
289 } | 298 } |
290 | 299 |
291 void Database::Close() { | 300 void Database::Close() { |
292 ASSERT(GetDatabaseContext()->GetDatabaseThread()); | 301 DCHECK(GetDatabaseContext()->GetDatabaseThread()); |
293 ASSERT(GetDatabaseContext()->GetDatabaseThread()->IsDatabaseThread()); | 302 DCHECK(GetDatabaseContext()->GetDatabaseThread()->IsDatabaseThread()); |
294 | 303 |
295 { | 304 { |
296 MutexLocker locker(transaction_in_progress_mutex_); | 305 MutexLocker locker(transaction_in_progress_mutex_); |
297 | 306 |
298 // Clean up transactions that have not been scheduled yet: | 307 // Clean up transactions that have not been scheduled yet: |
299 // Transaction phase 1 cleanup. See comment on "What happens if a | 308 // Transaction phase 1 cleanup. See comment on "What happens if a |
300 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. | 309 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. |
301 SQLTransactionBackend* transaction = nullptr; | 310 SQLTransactionBackend* transaction = nullptr; |
302 while (!transaction_queue_.IsEmpty()) { | 311 while (!transaction_queue_.IsEmpty()) { |
303 transaction = transaction_queue_.TakeFirst(); | 312 transaction = transaction_queue_.TakeFirst(); |
(...skipping 29 matching lines...) Expand all Loading... |
333 return transaction_backend; | 342 return transaction_backend; |
334 } | 343 } |
335 | 344 |
336 void Database::InProgressTransactionCompleted() { | 345 void Database::InProgressTransactionCompleted() { |
337 MutexLocker locker(transaction_in_progress_mutex_); | 346 MutexLocker locker(transaction_in_progress_mutex_); |
338 transaction_in_progress_ = false; | 347 transaction_in_progress_ = false; |
339 ScheduleTransaction(); | 348 ScheduleTransaction(); |
340 } | 349 } |
341 | 350 |
342 void Database::ScheduleTransaction() { | 351 void Database::ScheduleTransaction() { |
343 ASSERT(!transaction_in_progress_mutex_.TryLock()); // Locked by caller. | 352 DCHECK(!transaction_in_progress_mutex_.TryLock()); // Locked by caller. |
344 SQLTransactionBackend* transaction = nullptr; | 353 SQLTransactionBackend* transaction = nullptr; |
345 | 354 |
346 if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty()) | 355 if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty()) |
347 transaction = transaction_queue_.TakeFirst(); | 356 transaction = transaction_queue_.TakeFirst(); |
348 | 357 |
349 if (transaction && GetDatabaseContext()->DatabaseThreadAvailable()) { | 358 if (transaction && GetDatabaseContext()->DatabaseThreadAvailable()) { |
350 std::unique_ptr<DatabaseTransactionTask> task = | 359 std::unique_ptr<DatabaseTransactionTask> task = |
351 DatabaseTransactionTask::Create(transaction); | 360 DatabaseTransactionTask::Create(transaction); |
352 STORAGE_DVLOG(1) << "Scheduling DatabaseTransactionTask " << task.get() | 361 STORAGE_DVLOG(1) << "Scheduling DatabaseTransactionTask " << task.get() |
353 << " for transaction " << task->Transaction(); | 362 << " for transaction " << task->Transaction(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if (!opened_) | 395 if (!opened_) |
387 return; | 396 return; |
388 | 397 |
389 ReleaseStore(&opened_, 0); | 398 ReleaseStore(&opened_, 0); |
390 sqlite_database_.Close(); | 399 sqlite_database_.Close(); |
391 // See comment at the top this file regarding calling removeOpenDatabase(). | 400 // See comment at the top this file regarding calling removeOpenDatabase(). |
392 DatabaseTracker::Tracker().RemoveOpenDatabase(this); | 401 DatabaseTracker::Tracker().RemoveOpenDatabase(this); |
393 { | 402 { |
394 MutexLocker locker(GuidMutex()); | 403 MutexLocker locker(GuidMutex()); |
395 | 404 |
396 ASSERT(GuidCount().Contains(guid_)); | 405 DCHECK(GuidCount().Contains(guid_)); |
397 if (GuidCount().erase(guid_)) { | 406 if (GuidCount().erase(guid_)) { |
398 GuidToVersionMap().erase(guid_); | 407 GuidToVersionMap().erase(guid_); |
399 } | 408 } |
400 } | 409 } |
401 } | 410 } |
402 | 411 |
403 String Database::version() const { | 412 String Database::version() const { |
404 // Note: In multi-process browsers the cached value may be accurate, but we | 413 // Note: In multi-process browsers the cached value may be accurate, but we |
405 // cannot read the actual version from the database without potentially | 414 // cannot read the actual version from the database without potentially |
406 // inducing a deadlock. | 415 // inducing a deadlock. |
(...skipping 17 matching lines...) Expand all Loading... |
424 private: | 433 private: |
425 CrossThreadPersistent<Database> database_; | 434 CrossThreadPersistent<Database> database_; |
426 bool open_succeeded_; | 435 bool open_succeeded_; |
427 }; | 436 }; |
428 | 437 |
429 bool Database::PerformOpenAndVerify(bool should_set_version_in_new_database, | 438 bool Database::PerformOpenAndVerify(bool should_set_version_in_new_database, |
430 DatabaseError& error, | 439 DatabaseError& error, |
431 String& error_message) { | 440 String& error_message) { |
432 double call_start_time = WTF::MonotonicallyIncreasingTime(); | 441 double call_start_time = WTF::MonotonicallyIncreasingTime(); |
433 DoneCreatingDatabaseOnExitCaller on_exit_caller(this); | 442 DoneCreatingDatabaseOnExitCaller on_exit_caller(this); |
434 ASSERT(error_message.IsEmpty()); | 443 DCHECK(error_message.IsEmpty()); |
435 ASSERT(error == DatabaseError::kNone); // Better not have any errors already. | 444 DCHECK_EQ(error, |
| 445 DatabaseError::kNone); // Better not have any errors already. |
436 // Presumed failure. We'll clear it if we succeed below. | 446 // Presumed failure. We'll clear it if we succeed below. |
437 error = DatabaseError::kInvalidDatabaseState; | 447 error = DatabaseError::kInvalidDatabaseState; |
438 | 448 |
439 const int kMaxSqliteBusyWaitTime = 30000; | 449 const int kMaxSqliteBusyWaitTime = 30000; |
440 | 450 |
441 if (!sqlite_database_.Open(filename_)) { | 451 if (!sqlite_database_.Open(filename_)) { |
442 ReportOpenDatabaseResult( | 452 ReportOpenDatabaseResult( |
443 1, kInvalidStateError, sqlite_database_.LastError(), | 453 1, kInvalidStateError, sqlite_database_.LastError(), |
444 WTF::MonotonicallyIncreasingTime() - call_start_time); | 454 WTF::MonotonicallyIncreasingTime() - call_start_time); |
445 error_message = FormatErrorMessage("unable to open database", | 455 error_message = FormatErrorMessage("unable to open database", |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 ReportOpenDatabaseResult( | 578 ReportOpenDatabaseResult( |
569 6, kInvalidStateError, 0, | 579 6, kInvalidStateError, 0, |
570 WTF::MonotonicallyIncreasingTime() - call_start_time); | 580 WTF::MonotonicallyIncreasingTime() - call_start_time); |
571 error_message = | 581 error_message = |
572 "unable to open database, version mismatch, '" + expected_version_ + | 582 "unable to open database, version mismatch, '" + expected_version_ + |
573 "' does not match the currentVersion of '" + current_version + "'"; | 583 "' does not match the currentVersion of '" + current_version + "'"; |
574 sqlite_database_.Close(); | 584 sqlite_database_.Close(); |
575 return false; | 585 return false; |
576 } | 586 } |
577 | 587 |
578 ASSERT(database_authorizer_); | 588 DCHECK(database_authorizer_); |
579 sqlite_database_.SetAuthorizer(database_authorizer_.Get()); | 589 sqlite_database_.SetAuthorizer(database_authorizer_.Get()); |
580 | 590 |
581 // See comment at the top this file regarding calling addOpenDatabase(). | 591 // See comment at the top this file regarding calling addOpenDatabase(). |
582 DatabaseTracker::Tracker().AddOpenDatabase(this); | 592 DatabaseTracker::Tracker().AddOpenDatabase(this); |
583 opened_ = 1; | 593 opened_ = 1; |
584 | 594 |
585 // Declare success: | 595 // Declare success: |
586 error = DatabaseError::kNone; // Clear the presumed error from above. | 596 error = DatabaseError::kNone; // Clear the presumed error from above. |
587 on_exit_caller.SetOpenSucceeded(); | 597 on_exit_caller.SetOpenSucceeded(); |
588 | 598 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 return GuidToVersionMap().at(guid_).IsolatedCopy(); | 684 return GuidToVersionMap().at(guid_).IsolatedCopy(); |
675 } | 685 } |
676 | 686 |
677 void Database::SetCachedVersion(const String& actual_version) { | 687 void Database::SetCachedVersion(const String& actual_version) { |
678 // Update the in memory database version map. | 688 // Update the in memory database version map. |
679 MutexLocker locker(GuidMutex()); | 689 MutexLocker locker(GuidMutex()); |
680 UpdateGuidVersionMap(guid_, actual_version); | 690 UpdateGuidVersionMap(guid_, actual_version); |
681 } | 691 } |
682 | 692 |
683 bool Database::GetActualVersionForTransaction(String& actual_version) { | 693 bool Database::GetActualVersionForTransaction(String& actual_version) { |
684 ASSERT(sqlite_database_.TransactionInProgress()); | 694 DCHECK(sqlite_database_.TransactionInProgress()); |
685 // Note: In multi-process browsers the cached value may be inaccurate. So we | 695 // Note: In multi-process browsers the cached value may be inaccurate. So we |
686 // retrieve the value from the database and update the cached value here. | 696 // retrieve the value from the database and update the cached value here. |
687 return GetVersionFromDatabase(actual_version, true); | 697 return GetVersionFromDatabase(actual_version, true); |
688 } | 698 } |
689 | 699 |
690 void Database::DisableAuthorizer() { | 700 void Database::DisableAuthorizer() { |
691 ASSERT(database_authorizer_); | 701 DCHECK(database_authorizer_); |
692 database_authorizer_->Disable(); | 702 database_authorizer_->Disable(); |
693 } | 703 } |
694 | 704 |
695 void Database::EnableAuthorizer() { | 705 void Database::EnableAuthorizer() { |
696 ASSERT(database_authorizer_); | 706 DCHECK(database_authorizer_); |
697 database_authorizer_->Enable(); | 707 database_authorizer_->Enable(); |
698 } | 708 } |
699 | 709 |
700 void Database::SetAuthorizerPermissions(int permissions) { | 710 void Database::SetAuthorizerPermissions(int permissions) { |
701 ASSERT(database_authorizer_); | 711 DCHECK(database_authorizer_); |
702 database_authorizer_->SetPermissions(permissions); | 712 database_authorizer_->SetPermissions(permissions); |
703 } | 713 } |
704 | 714 |
705 bool Database::LastActionChangedDatabase() { | 715 bool Database::LastActionChangedDatabase() { |
706 ASSERT(database_authorizer_); | 716 DCHECK(database_authorizer_); |
707 return database_authorizer_->LastActionChangedDatabase(); | 717 return database_authorizer_->LastActionChangedDatabase(); |
708 } | 718 } |
709 | 719 |
710 bool Database::LastActionWasInsert() { | 720 bool Database::LastActionWasInsert() { |
711 ASSERT(database_authorizer_); | 721 DCHECK(database_authorizer_); |
712 return database_authorizer_->LastActionWasInsert(); | 722 return database_authorizer_->LastActionWasInsert(); |
713 } | 723 } |
714 | 724 |
715 void Database::ResetDeletes() { | 725 void Database::ResetDeletes() { |
716 ASSERT(database_authorizer_); | 726 DCHECK(database_authorizer_); |
717 database_authorizer_->ResetDeletes(); | 727 database_authorizer_->ResetDeletes(); |
718 } | 728 } |
719 | 729 |
720 bool Database::HadDeletes() { | 730 bool Database::HadDeletes() { |
721 ASSERT(database_authorizer_); | 731 DCHECK(database_authorizer_); |
722 return database_authorizer_->HadDeletes(); | 732 return database_authorizer_->HadDeletes(); |
723 } | 733 } |
724 | 734 |
725 void Database::ResetAuthorizer() { | 735 void Database::ResetAuthorizer() { |
726 if (database_authorizer_) | 736 if (database_authorizer_) |
727 database_authorizer_->Reset(); | 737 database_authorizer_->Reset(); |
728 } | 738 } |
729 | 739 |
730 unsigned long long Database::MaximumSize() const { | 740 unsigned long long Database::MaximumSize() const { |
731 return DatabaseTracker::Tracker().GetMaxSizeForDatabase(this); | 741 return DatabaseTracker::Tracker().GetMaxSizeForDatabase(this); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 void Database::LogErrorMessage(const String& message) { | 817 void Database::LogErrorMessage(const String& message) { |
808 GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create( | 818 GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create( |
809 kStorageMessageSource, kErrorMessageLevel, message)); | 819 kStorageMessageSource, kErrorMessageLevel, message)); |
810 } | 820 } |
811 | 821 |
812 ExecutionContext* Database::GetExecutionContext() const { | 822 ExecutionContext* Database::GetExecutionContext() const { |
813 return GetDatabaseContext()->GetExecutionContext(); | 823 return GetDatabaseContext()->GetExecutionContext(); |
814 } | 824 } |
815 | 825 |
816 void Database::CloseImmediately() { | 826 void Database::CloseImmediately() { |
817 ASSERT(GetExecutionContext()->IsContextThread()); | 827 DCHECK(GetExecutionContext()->IsContextThread()); |
818 if (GetDatabaseContext()->DatabaseThreadAvailable() && Opened()) { | 828 if (GetDatabaseContext()->DatabaseThreadAvailable() && Opened()) { |
819 LogErrorMessage("forcibly closing database"); | 829 LogErrorMessage("forcibly closing database"); |
820 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask( | 830 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask( |
821 DatabaseCloseTask::Create(this, 0)); | 831 DatabaseCloseTask::Create(this, 0)); |
822 } | 832 } |
823 } | 833 } |
824 | 834 |
825 void Database::changeVersion(const String& old_version, | 835 void Database::changeVersion(const String& old_version, |
826 const String& new_version, | 836 const String& new_version, |
827 SQLTransactionCallback* callback, | 837 SQLTransactionCallback* callback, |
(...skipping 22 matching lines...) Expand all Loading... |
850 } | 860 } |
851 | 861 |
852 void Database::RunTransaction(SQLTransactionCallback* callback, | 862 void Database::RunTransaction(SQLTransactionCallback* callback, |
853 SQLTransactionErrorCallback* error_callback, | 863 SQLTransactionErrorCallback* error_callback, |
854 VoidCallback* success_callback, | 864 VoidCallback* success_callback, |
855 bool read_only, | 865 bool read_only, |
856 const ChangeVersionData* change_version_data) { | 866 const ChangeVersionData* change_version_data) { |
857 if (!GetExecutionContext()) | 867 if (!GetExecutionContext()) |
858 return; | 868 return; |
859 | 869 |
860 ASSERT(GetExecutionContext()->IsContextThread()); | 870 DCHECK(GetExecutionContext()->IsContextThread()); |
861 // FIXME: Rather than passing errorCallback to SQLTransaction and then | 871 // FIXME: Rather than passing errorCallback to SQLTransaction and then |
862 // sometimes firing it ourselves, this code should probably be pushed down | 872 // sometimes firing it ourselves, this code should probably be pushed down |
863 // into Database so that we only create the SQLTransaction if we're | 873 // into Database so that we only create the SQLTransaction if we're |
864 // actually going to run it. | 874 // actually going to run it. |
865 #if DCHECK_IS_ON() | 875 #if DCHECK_IS_ON() |
866 SQLTransactionErrorCallback* original_error_callback = error_callback; | 876 SQLTransactionErrorCallback* original_error_callback = error_callback; |
867 #endif | 877 #endif |
868 SQLTransaction* transaction = SQLTransaction::Create( | 878 SQLTransaction* transaction = SQLTransaction::Create( |
869 this, callback, success_callback, error_callback, read_only); | 879 this, callback, success_callback, error_callback, read_only); |
870 SQLTransactionBackend* transaction_backend = | 880 SQLTransactionBackend* transaction_backend = |
871 RunTransaction(transaction, read_only, change_version_data); | 881 RunTransaction(transaction, read_only, change_version_data); |
872 if (!transaction_backend) { | 882 if (!transaction_backend) { |
873 SQLTransactionErrorCallback* callback = transaction->ReleaseErrorCallback(); | 883 SQLTransactionErrorCallback* callback = transaction->ReleaseErrorCallback(); |
874 ASSERT(callback == original_error_callback); | 884 #if DCHECK_IS_ON() |
| 885 DCHECK_EQ(callback, original_error_callback); |
| 886 #endif |
875 if (callback) { | 887 if (callback) { |
876 std::unique_ptr<SQLErrorData> error = SQLErrorData::Create( | 888 std::unique_ptr<SQLErrorData> error = SQLErrorData::Create( |
877 SQLError::kUnknownErr, "database has been closed"); | 889 SQLError::kUnknownErr, "database has been closed"); |
878 GetDatabaseTaskRunner()->PostTask( | 890 GetDatabaseTaskRunner()->PostTask( |
879 BLINK_FROM_HERE, | 891 BLINK_FROM_HERE, |
880 WTF::Bind(&CallTransactionErrorCallback, WrapPersistent(callback), | 892 WTF::Bind(&CallTransactionErrorCallback, WrapPersistent(callback), |
881 WTF::Passed(std::move(error)))); | 893 WTF::Passed(std::move(error)))); |
882 } | 894 } |
883 } | 895 } |
884 } | 896 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 | 962 |
951 bool Database::Opened() { | 963 bool Database::Opened() { |
952 return static_cast<bool>(AcquireLoad(&opened_)); | 964 return static_cast<bool>(AcquireLoad(&opened_)); |
953 } | 965 } |
954 | 966 |
955 WebTaskRunner* Database::GetDatabaseTaskRunner() const { | 967 WebTaskRunner* Database::GetDatabaseTaskRunner() const { |
956 return database_task_runner_.Get(); | 968 return database_task_runner_.Get(); |
957 } | 969 } |
958 | 970 |
959 } // namespace blink | 971 } // namespace blink |
OLD | NEW |