Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/Database.cpp

Issue 2813433002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in modules/webdatabase (Closed)
Patch Set: rebase and assert -> dcheck Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \ 95 #define DEFINE_STATIC_LOCAL_WITH_LOCK(type, name, arguments) \
96 ASSERT(GuidMutex().Locked()); \ 96 DCHECK(GuidMutex().Locked()); \
97 static type& name = *new type arguments 97 static type& name = *new type arguments
98 98
99 static const char kVersionKey[] = "WebKitDatabaseVersionKey"; 99 static const char kVersionKey[] = "WebKitDatabaseVersionKey";
100 static const char kInfoTableName[] = "__WebKitDatabaseInfoTable__"; 100 static const char kInfoTableName[] = "__WebKitDatabaseInfoTable__";
101 101
102 static String FormatErrorMessage(const char* message, 102 static String FormatErrorMessage(const char* message,
103 int sqlite_error_code, 103 int sqlite_error_code,
104 const char* sqlite_error_message) { 104 const char* sqlite_error_message) {
105 return String::Format("%s (%d %s)", message, sqlite_error_code, 105 return String::Format("%s (%d %s)", message, sqlite_error_code,
106 sqlite_error_message); 106 sqlite_error_message);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 typedef HashMap<DatabaseGuid, String> GuidVersionMap; 167 typedef HashMap<DatabaseGuid, String> GuidVersionMap;
168 static GuidVersionMap& GuidToVersionMap() { 168 static GuidVersionMap& GuidToVersionMap() {
169 DEFINE_STATIC_LOCAL_WITH_LOCK(GuidVersionMap, map, ()); 169 DEFINE_STATIC_LOCAL_WITH_LOCK(GuidVersionMap, map, ());
170 return map; 170 return map;
171 } 171 }
172 172
173 // NOTE: Caller must lock guidMutex(). 173 // NOTE: Caller must lock guidMutex().
174 static inline void UpdateGuidVersionMap(DatabaseGuid guid, String new_version) { 174 static inline void UpdateGuidVersionMap(DatabaseGuid guid, String new_version) {
175 // Ensure the the mutex is locked. 175 // Ensure the the mutex is locked.
176 ASSERT(GuidMutex().Locked()); 176 DCHECK(GuidMutex().Locked());
177 177
178 // Note: It is not safe to put an empty string into the guidToVersionMap() 178 // 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 179 // 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 180 // 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 181 // use on the current thread, but we need a string we can keep in a
182 // cross-thread data structure. 182 // cross-thread data structure.
183 // FIXME: This is a quite-awkward restriction to have to program with. 183 // FIXME: This is a quite-awkward restriction to have to program with.
184 184
185 // Map null string to empty string (see comment above). 185 // Map null string to empty string (see comment above).
186 GuidToVersionMap().Set( 186 GuidToVersionMap().Set(
187 guid, new_version.IsEmpty() ? String() : new_version.IsolatedCopy()); 187 guid, new_version.IsEmpty() ? String() : new_version.IsolatedCopy());
188 } 188 }
189 189
190 static HashCountedSet<DatabaseGuid>& GuidCount() { 190 static HashCountedSet<DatabaseGuid>& GuidCount() {
191 DEFINE_STATIC_LOCAL_WITH_LOCK(HashCountedSet<DatabaseGuid>, guid_count, ()); 191 DEFINE_STATIC_LOCAL_WITH_LOCK(HashCountedSet<DatabaseGuid>, guid_count, ());
192 return guid_count; 192 return guid_count;
193 } 193 }
194 194
195 static DatabaseGuid GuidForOriginAndName(const String& origin, 195 static DatabaseGuid GuidForOriginAndName(const String& origin,
196 const String& name) { 196 const String& name) {
197 // Ensure the the mutex is locked. 197 // Ensure the the mutex is locked.
198 ASSERT(GuidMutex().Locked()); 198 DCHECK(GuidMutex().Locked());
199 199
200 String string_id = origin + "/" + name; 200 String string_id = origin + "/" + name;
201 201
202 typedef HashMap<String, int> IDGuidMap; 202 typedef HashMap<String, int> IDGuidMap;
203 DEFINE_STATIC_LOCAL_WITH_LOCK(IDGuidMap, string_identifier_to_guid_map, ()); 203 DEFINE_STATIC_LOCAL_WITH_LOCK(IDGuidMap, string_identifier_to_guid_map, ());
204 DatabaseGuid guid = string_identifier_to_guid_map.at(string_id); 204 DatabaseGuid guid = string_identifier_to_guid_map.at(string_id);
205 if (!guid) { 205 if (!guid) {
206 static int current_new_guid = 1; 206 static int current_new_guid = 1;
207 guid = current_new_guid++; 207 guid = current_new_guid++;
208 string_identifier_to_guid_map.Set(string_id, guid); 208 string_identifier_to_guid_map.Set(string_id, guid);
(...skipping 30 matching lines...) Expand all
239 MutexLocker locker(GuidMutex()); 239 MutexLocker locker(GuidMutex());
240 guid_ = GuidForOriginAndName(GetSecurityOrigin()->ToString(), name); 240 guid_ = GuidForOriginAndName(GetSecurityOrigin()->ToString(), name);
241 GuidCount().insert(guid_); 241 GuidCount().insert(guid_);
242 } 242 }
243 243
244 filename_ = DatabaseManager::Manager().FullPathForDatabase( 244 filename_ = DatabaseManager::Manager().FullPathForDatabase(
245 GetSecurityOrigin(), name_); 245 GetSecurityOrigin(), name_);
246 246
247 database_thread_security_origin_ = 247 database_thread_security_origin_ =
248 context_thread_security_origin_->IsolatedCopy(); 248 context_thread_security_origin_->IsolatedCopy();
249 ASSERT(database_context_->GetDatabaseThread()); 249 DCHECK(database_context_->GetDatabaseThread());
250 ASSERT(database_context_->IsContextThread()); 250 DCHECK(database_context_->IsContextThread());
251 database_task_runner_ = 251 database_task_runner_ =
252 TaskRunnerHelper::Get(TaskType::kDatabaseAccess, GetExecutionContext()); 252 TaskRunnerHelper::Get(TaskType::kDatabaseAccess, GetExecutionContext());
253 } 253 }
254 254
255 Database::~Database() { 255 Database::~Database() {
256 // SQLite is "multi-thread safe", but each database handle can only be used 256 // SQLite is "multi-thread safe", but each database handle can only be used
257 // on a single thread at a time. 257 // on a single thread at a time.
258 // 258 //
259 // For Database, we open the SQLite database on the DatabaseThread, and 259 // 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 260 // 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 261 // SQLite database need to be closed by another mechanism (see
262 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite 262 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite
263 // database should have already been closed. 263 // database should have already been closed.
264 264
265 ASSERT(!opened_); 265 DCHECK(!opened_);
266 } 266 }
267 267
268 DEFINE_TRACE(Database) { 268 DEFINE_TRACE(Database) {
269 visitor->Trace(database_context_); 269 visitor->Trace(database_context_);
270 visitor->Trace(sqlite_database_); 270 visitor->Trace(sqlite_database_);
271 visitor->Trace(database_authorizer_); 271 visitor->Trace(database_authorizer_);
272 } 272 }
273 273
274 bool Database::OpenAndVerifyVersion(bool set_version_in_new_database, 274 bool Database::OpenAndVerifyVersion(bool set_version_in_new_database,
275 DatabaseError& error, 275 DatabaseError& error,
276 String& error_message) { 276 String& error_message) {
277 WaitableEvent event; 277 WaitableEvent event;
278 if (!GetDatabaseContext()->DatabaseThreadAvailable()) 278 if (!GetDatabaseContext()->DatabaseThreadAvailable())
279 return false; 279 return false;
280 280
281 DatabaseTracker::Tracker().PrepareToOpenDatabase(this); 281 DatabaseTracker::Tracker().PrepareToOpenDatabase(this);
282 bool success = false; 282 bool success = false;
283 std::unique_ptr<DatabaseOpenTask> task = DatabaseOpenTask::Create( 283 std::unique_ptr<DatabaseOpenTask> task = DatabaseOpenTask::Create(
284 this, set_version_in_new_database, &event, error, error_message, success); 284 this, set_version_in_new_database, &event, error, error_message, success);
285 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask(std::move(task)); 285 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask(std::move(task));
286 event.Wait(); 286 event.Wait();
287 287
288 return success; 288 return success;
289 } 289 }
290 290
291 void Database::Close() { 291 void Database::Close() {
292 ASSERT(GetDatabaseContext()->GetDatabaseThread()); 292 DCHECK(GetDatabaseContext()->GetDatabaseThread());
293 ASSERT(GetDatabaseContext()->GetDatabaseThread()->IsDatabaseThread()); 293 DCHECK(GetDatabaseContext()->GetDatabaseThread()->IsDatabaseThread());
294 294
295 { 295 {
296 MutexLocker locker(transaction_in_progress_mutex_); 296 MutexLocker locker(transaction_in_progress_mutex_);
297 297
298 // Clean up transactions that have not been scheduled yet: 298 // Clean up transactions that have not been scheduled yet:
299 // Transaction phase 1 cleanup. See comment on "What happens if a 299 // Transaction phase 1 cleanup. See comment on "What happens if a
300 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. 300 // transaction is interrupted?" at the top of SQLTransactionBackend.cpp.
301 SQLTransactionBackend* transaction = nullptr; 301 SQLTransactionBackend* transaction = nullptr;
302 while (!transaction_queue_.IsEmpty()) { 302 while (!transaction_queue_.IsEmpty()) {
303 transaction = transaction_queue_.TakeFirst(); 303 transaction = transaction_queue_.TakeFirst();
(...skipping 29 matching lines...) Expand all
333 return transaction_backend; 333 return transaction_backend;
334 } 334 }
335 335
336 void Database::InProgressTransactionCompleted() { 336 void Database::InProgressTransactionCompleted() {
337 MutexLocker locker(transaction_in_progress_mutex_); 337 MutexLocker locker(transaction_in_progress_mutex_);
338 transaction_in_progress_ = false; 338 transaction_in_progress_ = false;
339 ScheduleTransaction(); 339 ScheduleTransaction();
340 } 340 }
341 341
342 void Database::ScheduleTransaction() { 342 void Database::ScheduleTransaction() {
343 ASSERT(!transaction_in_progress_mutex_.TryLock()); // Locked by caller. 343 DCHECK(!transaction_in_progress_mutex_.TryLock()); // Locked by caller.
344 SQLTransactionBackend* transaction = nullptr; 344 SQLTransactionBackend* transaction = nullptr;
345 345
346 if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty()) 346 if (is_transaction_queue_enabled_ && !transaction_queue_.IsEmpty())
347 transaction = transaction_queue_.TakeFirst(); 347 transaction = transaction_queue_.TakeFirst();
348 348
349 if (transaction && GetDatabaseContext()->DatabaseThreadAvailable()) { 349 if (transaction && GetDatabaseContext()->DatabaseThreadAvailable()) {
350 std::unique_ptr<DatabaseTransactionTask> task = 350 std::unique_ptr<DatabaseTransactionTask> task =
351 DatabaseTransactionTask::Create(transaction); 351 DatabaseTransactionTask::Create(transaction);
352 STORAGE_DVLOG(1) << "Scheduling DatabaseTransactionTask " << task.get() 352 STORAGE_DVLOG(1) << "Scheduling DatabaseTransactionTask " << task.get()
353 << " for transaction " << task->Transaction(); 353 << " for transaction " << task->Transaction();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if (!opened_) 386 if (!opened_)
387 return; 387 return;
388 388
389 ReleaseStore(&opened_, 0); 389 ReleaseStore(&opened_, 0);
390 sqlite_database_.Close(); 390 sqlite_database_.Close();
391 // See comment at the top this file regarding calling removeOpenDatabase(). 391 // See comment at the top this file regarding calling removeOpenDatabase().
392 DatabaseTracker::Tracker().RemoveOpenDatabase(this); 392 DatabaseTracker::Tracker().RemoveOpenDatabase(this);
393 { 393 {
394 MutexLocker locker(GuidMutex()); 394 MutexLocker locker(GuidMutex());
395 395
396 ASSERT(GuidCount().Contains(guid_)); 396 DCHECK(GuidCount().Contains(guid_));
397 if (GuidCount().erase(guid_)) { 397 if (GuidCount().erase(guid_)) {
398 GuidToVersionMap().erase(guid_); 398 GuidToVersionMap().erase(guid_);
399 } 399 }
400 } 400 }
401 } 401 }
402 402
403 String Database::version() const { 403 String Database::version() const {
404 // Note: In multi-process browsers the cached value may be accurate, but we 404 // Note: In multi-process browsers the cached value may be accurate, but we
405 // cannot read the actual version from the database without potentially 405 // cannot read the actual version from the database without potentially
406 // inducing a deadlock. 406 // inducing a deadlock.
(...skipping 17 matching lines...) Expand all
424 private: 424 private:
425 CrossThreadPersistent<Database> database_; 425 CrossThreadPersistent<Database> database_;
426 bool open_succeeded_; 426 bool open_succeeded_;
427 }; 427 };
428 428
429 bool Database::PerformOpenAndVerify(bool should_set_version_in_new_database, 429 bool Database::PerformOpenAndVerify(bool should_set_version_in_new_database,
430 DatabaseError& error, 430 DatabaseError& error,
431 String& error_message) { 431 String& error_message) {
432 double call_start_time = WTF::MonotonicallyIncreasingTime(); 432 double call_start_time = WTF::MonotonicallyIncreasingTime();
433 DoneCreatingDatabaseOnExitCaller on_exit_caller(this); 433 DoneCreatingDatabaseOnExitCaller on_exit_caller(this);
434 ASSERT(error_message.IsEmpty()); 434 DCHECK(error_message.IsEmpty());
435 ASSERT(error == DatabaseError::kNone); // Better not have any errors already. 435 DCHECK_EQ(error,
436 DatabaseError::kNone); // Better not have any errors already.
436 // Presumed failure. We'll clear it if we succeed below. 437 // Presumed failure. We'll clear it if we succeed below.
437 error = DatabaseError::kInvalidDatabaseState; 438 error = DatabaseError::kInvalidDatabaseState;
438 439
439 const int kMaxSqliteBusyWaitTime = 30000; 440 const int kMaxSqliteBusyWaitTime = 30000;
440 441
441 if (!sqlite_database_.Open(filename_)) { 442 if (!sqlite_database_.Open(filename_)) {
442 ReportOpenDatabaseResult( 443 ReportOpenDatabaseResult(
443 1, kInvalidStateError, sqlite_database_.LastError(), 444 1, kInvalidStateError, sqlite_database_.LastError(),
444 WTF::MonotonicallyIncreasingTime() - call_start_time); 445 WTF::MonotonicallyIncreasingTime() - call_start_time);
445 error_message = FormatErrorMessage("unable to open database", 446 error_message = FormatErrorMessage("unable to open database",
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 ReportOpenDatabaseResult( 569 ReportOpenDatabaseResult(
569 6, kInvalidStateError, 0, 570 6, kInvalidStateError, 0,
570 WTF::MonotonicallyIncreasingTime() - call_start_time); 571 WTF::MonotonicallyIncreasingTime() - call_start_time);
571 error_message = 572 error_message =
572 "unable to open database, version mismatch, '" + expected_version_ + 573 "unable to open database, version mismatch, '" + expected_version_ +
573 "' does not match the currentVersion of '" + current_version + "'"; 574 "' does not match the currentVersion of '" + current_version + "'";
574 sqlite_database_.Close(); 575 sqlite_database_.Close();
575 return false; 576 return false;
576 } 577 }
577 578
578 ASSERT(database_authorizer_); 579 DCHECK(database_authorizer_);
579 sqlite_database_.SetAuthorizer(database_authorizer_.Get()); 580 sqlite_database_.SetAuthorizer(database_authorizer_.Get());
580 581
581 // See comment at the top this file regarding calling addOpenDatabase(). 582 // See comment at the top this file regarding calling addOpenDatabase().
582 DatabaseTracker::Tracker().AddOpenDatabase(this); 583 DatabaseTracker::Tracker().AddOpenDatabase(this);
583 opened_ = 1; 584 opened_ = 1;
584 585
585 // Declare success: 586 // Declare success:
586 error = DatabaseError::kNone; // Clear the presumed error from above. 587 error = DatabaseError::kNone; // Clear the presumed error from above.
587 on_exit_caller.SetOpenSucceeded(); 588 on_exit_caller.SetOpenSucceeded();
588 589
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 return GuidToVersionMap().at(guid_).IsolatedCopy(); 675 return GuidToVersionMap().at(guid_).IsolatedCopy();
675 } 676 }
676 677
677 void Database::SetCachedVersion(const String& actual_version) { 678 void Database::SetCachedVersion(const String& actual_version) {
678 // Update the in memory database version map. 679 // Update the in memory database version map.
679 MutexLocker locker(GuidMutex()); 680 MutexLocker locker(GuidMutex());
680 UpdateGuidVersionMap(guid_, actual_version); 681 UpdateGuidVersionMap(guid_, actual_version);
681 } 682 }
682 683
683 bool Database::GetActualVersionForTransaction(String& actual_version) { 684 bool Database::GetActualVersionForTransaction(String& actual_version) {
684 ASSERT(sqlite_database_.TransactionInProgress()); 685 DCHECK(sqlite_database_.TransactionInProgress());
685 // Note: In multi-process browsers the cached value may be inaccurate. So we 686 // 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. 687 // retrieve the value from the database and update the cached value here.
687 return GetVersionFromDatabase(actual_version, true); 688 return GetVersionFromDatabase(actual_version, true);
688 } 689 }
689 690
690 void Database::DisableAuthorizer() { 691 void Database::DisableAuthorizer() {
691 ASSERT(database_authorizer_); 692 DCHECK(database_authorizer_);
692 database_authorizer_->Disable(); 693 database_authorizer_->Disable();
693 } 694 }
694 695
695 void Database::EnableAuthorizer() { 696 void Database::EnableAuthorizer() {
696 ASSERT(database_authorizer_); 697 DCHECK(database_authorizer_);
697 database_authorizer_->Enable(); 698 database_authorizer_->Enable();
698 } 699 }
699 700
700 void Database::SetAuthorizerPermissions(int permissions) { 701 void Database::SetAuthorizerPermissions(int permissions) {
701 ASSERT(database_authorizer_); 702 DCHECK(database_authorizer_);
702 database_authorizer_->SetPermissions(permissions); 703 database_authorizer_->SetPermissions(permissions);
703 } 704 }
704 705
705 bool Database::LastActionChangedDatabase() { 706 bool Database::LastActionChangedDatabase() {
706 ASSERT(database_authorizer_); 707 DCHECK(database_authorizer_);
707 return database_authorizer_->LastActionChangedDatabase(); 708 return database_authorizer_->LastActionChangedDatabase();
708 } 709 }
709 710
710 bool Database::LastActionWasInsert() { 711 bool Database::LastActionWasInsert() {
711 ASSERT(database_authorizer_); 712 DCHECK(database_authorizer_);
712 return database_authorizer_->LastActionWasInsert(); 713 return database_authorizer_->LastActionWasInsert();
713 } 714 }
714 715
715 void Database::ResetDeletes() { 716 void Database::ResetDeletes() {
716 ASSERT(database_authorizer_); 717 DCHECK(database_authorizer_);
717 database_authorizer_->ResetDeletes(); 718 database_authorizer_->ResetDeletes();
718 } 719 }
719 720
720 bool Database::HadDeletes() { 721 bool Database::HadDeletes() {
721 ASSERT(database_authorizer_); 722 DCHECK(database_authorizer_);
722 return database_authorizer_->HadDeletes(); 723 return database_authorizer_->HadDeletes();
723 } 724 }
724 725
725 void Database::ResetAuthorizer() { 726 void Database::ResetAuthorizer() {
726 if (database_authorizer_) 727 if (database_authorizer_)
727 database_authorizer_->Reset(); 728 database_authorizer_->Reset();
728 } 729 }
729 730
730 unsigned long long Database::MaximumSize() const { 731 unsigned long long Database::MaximumSize() const {
731 return DatabaseTracker::Tracker().GetMaxSizeForDatabase(this); 732 return DatabaseTracker::Tracker().GetMaxSizeForDatabase(this);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 void Database::LogErrorMessage(const String& message) { 808 void Database::LogErrorMessage(const String& message) {
808 GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create( 809 GetExecutionContext()->AddConsoleMessage(ConsoleMessage::Create(
809 kStorageMessageSource, kErrorMessageLevel, message)); 810 kStorageMessageSource, kErrorMessageLevel, message));
810 } 811 }
811 812
812 ExecutionContext* Database::GetExecutionContext() const { 813 ExecutionContext* Database::GetExecutionContext() const {
813 return GetDatabaseContext()->GetExecutionContext(); 814 return GetDatabaseContext()->GetExecutionContext();
814 } 815 }
815 816
816 void Database::CloseImmediately() { 817 void Database::CloseImmediately() {
817 ASSERT(GetExecutionContext()->IsContextThread()); 818 DCHECK(GetExecutionContext()->IsContextThread());
818 if (GetDatabaseContext()->DatabaseThreadAvailable() && Opened()) { 819 if (GetDatabaseContext()->DatabaseThreadAvailable() && Opened()) {
819 LogErrorMessage("forcibly closing database"); 820 LogErrorMessage("forcibly closing database");
820 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask( 821 GetDatabaseContext()->GetDatabaseThread()->ScheduleTask(
821 DatabaseCloseTask::Create(this, 0)); 822 DatabaseCloseTask::Create(this, 0));
822 } 823 }
823 } 824 }
824 825
825 void Database::changeVersion(const String& old_version, 826 void Database::changeVersion(const String& old_version,
826 const String& new_version, 827 const String& new_version,
827 SQLTransactionCallback* callback, 828 SQLTransactionCallback* callback,
(...skipping 22 matching lines...) Expand all
850 } 851 }
851 852
852 void Database::RunTransaction(SQLTransactionCallback* callback, 853 void Database::RunTransaction(SQLTransactionCallback* callback,
853 SQLTransactionErrorCallback* error_callback, 854 SQLTransactionErrorCallback* error_callback,
854 VoidCallback* success_callback, 855 VoidCallback* success_callback,
855 bool read_only, 856 bool read_only,
856 const ChangeVersionData* change_version_data) { 857 const ChangeVersionData* change_version_data) {
857 if (!GetExecutionContext()) 858 if (!GetExecutionContext())
858 return; 859 return;
859 860
860 ASSERT(GetExecutionContext()->IsContextThread()); 861 DCHECK(GetExecutionContext()->IsContextThread());
861 // FIXME: Rather than passing errorCallback to SQLTransaction and then 862 // FIXME: Rather than passing errorCallback to SQLTransaction and then
862 // sometimes firing it ourselves, this code should probably be pushed down 863 // sometimes firing it ourselves, this code should probably be pushed down
863 // into Database so that we only create the SQLTransaction if we're 864 // into Database so that we only create the SQLTransaction if we're
864 // actually going to run it. 865 // actually going to run it.
865 #if DCHECK_IS_ON() 866 #if DCHECK_IS_ON()
866 SQLTransactionErrorCallback* original_error_callback = error_callback; 867 SQLTransactionErrorCallback* original_error_callback = error_callback;
867 #endif 868 #endif
868 SQLTransaction* transaction = SQLTransaction::Create( 869 SQLTransaction* transaction = SQLTransaction::Create(
869 this, callback, success_callback, error_callback, read_only); 870 this, callback, success_callback, error_callback, read_only);
870 SQLTransactionBackend* transaction_backend = 871 SQLTransactionBackend* transaction_backend =
871 RunTransaction(transaction, read_only, change_version_data); 872 RunTransaction(transaction, read_only, change_version_data);
872 if (!transaction_backend) { 873 if (!transaction_backend) {
873 SQLTransactionErrorCallback* callback = transaction->ReleaseErrorCallback(); 874 SQLTransactionErrorCallback* callback = transaction->ReleaseErrorCallback();
874 ASSERT(callback == original_error_callback); 875 DCHECK_EQ(callback, original_error_callback);
875 if (callback) { 876 if (callback) {
876 std::unique_ptr<SQLErrorData> error = SQLErrorData::Create( 877 std::unique_ptr<SQLErrorData> error = SQLErrorData::Create(
877 SQLError::kUnknownErr, "database has been closed"); 878 SQLError::kUnknownErr, "database has been closed");
878 GetDatabaseTaskRunner()->PostTask( 879 GetDatabaseTaskRunner()->PostTask(
879 BLINK_FROM_HERE, 880 BLINK_FROM_HERE,
880 WTF::Bind(&CallTransactionErrorCallback, WrapPersistent(callback), 881 WTF::Bind(&CallTransactionErrorCallback, WrapPersistent(callback),
881 WTF::Passed(std::move(error)))); 882 WTF::Passed(std::move(error))));
882 } 883 }
883 } 884 }
884 } 885 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 951
951 bool Database::Opened() { 952 bool Database::Opened() {
952 return static_cast<bool>(AcquireLoad(&opened_)); 953 return static_cast<bool>(AcquireLoad(&opened_));
953 } 954 }
954 955
955 WebTaskRunner* Database::GetDatabaseTaskRunner() const { 956 WebTaskRunner* Database::GetDatabaseTaskRunner() const {
956 return database_task_runner_.Get(); 957 return database_task_runner_.Get();
957 } 958 }
958 959
959 } // namespace blink 960 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698