| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace blink { | 43 namespace blink { |
| 44 | 44 |
| 45 DatabaseThread::DatabaseThread() | 45 DatabaseThread::DatabaseThread() |
| 46 : transaction_client_(WTF::MakeUnique<SQLTransactionClient>()), | 46 : transaction_client_(WTF::MakeUnique<SQLTransactionClient>()), |
| 47 cleanup_sync_(nullptr), | 47 cleanup_sync_(nullptr), |
| 48 termination_requested_(false) { | 48 termination_requested_(false) { |
| 49 DCHECK(IsMainThread()); | 49 DCHECK(IsMainThread()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 DatabaseThread::~DatabaseThread() { | 52 DatabaseThread::~DatabaseThread() { |
| 53 ASSERT(open_database_set_.IsEmpty()); | 53 DCHECK(open_database_set_.IsEmpty()); |
| 54 ASSERT(!thread_); | 54 DCHECK(!thread_); |
| 55 } | 55 } |
| 56 | 56 |
| 57 DEFINE_TRACE(DatabaseThread) {} | 57 DEFINE_TRACE(DatabaseThread) {} |
| 58 | 58 |
| 59 void DatabaseThread::Start() { | 59 void DatabaseThread::Start() { |
| 60 ASSERT(IsMainThread()); | 60 DCHECK(IsMainThread()); |
| 61 if (thread_) | 61 if (thread_) |
| 62 return; | 62 return; |
| 63 thread_ = WebThreadSupportingGC::Create("WebCore: Database"); | 63 thread_ = WebThreadSupportingGC::Create("WebCore: Database"); |
| 64 thread_->PostTask(BLINK_FROM_HERE, | 64 thread_->PostTask(BLINK_FROM_HERE, |
| 65 CrossThreadBind(&DatabaseThread::SetupDatabaseThread, | 65 CrossThreadBind(&DatabaseThread::SetupDatabaseThread, |
| 66 WrapCrossThreadPersistent(this))); | 66 WrapCrossThreadPersistent(this))); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void DatabaseThread::SetupDatabaseThread() { | 69 void DatabaseThread::SetupDatabaseThread() { |
| 70 thread_->Initialize(); | 70 thread_->Initialize(); |
| 71 transaction_coordinator_ = new SQLTransactionCoordinator(); | 71 transaction_coordinator_ = new SQLTransactionCoordinator(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void DatabaseThread::Terminate() { | 74 void DatabaseThread::Terminate() { |
| 75 ASSERT(IsMainThread()); | 75 DCHECK(IsMainThread()); |
| 76 WaitableEvent sync; | 76 WaitableEvent sync; |
| 77 { | 77 { |
| 78 MutexLocker lock(termination_requested_mutex_); | 78 MutexLocker lock(termination_requested_mutex_); |
| 79 ASSERT(!termination_requested_); | 79 DCHECK(!termination_requested_); |
| 80 termination_requested_ = true; | 80 termination_requested_ = true; |
| 81 cleanup_sync_ = &sync; | 81 cleanup_sync_ = &sync; |
| 82 STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminate"; | 82 STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminate"; |
| 83 thread_->PostTask(BLINK_FROM_HERE, | 83 thread_->PostTask(BLINK_FROM_HERE, |
| 84 CrossThreadBind(&DatabaseThread::CleanupDatabaseThread, | 84 CrossThreadBind(&DatabaseThread::CleanupDatabaseThread, |
| 85 WrapCrossThreadPersistent(this))); | 85 WrapCrossThreadPersistent(this))); |
| 86 } | 86 } |
| 87 sync.Wait(); | 87 sync.Wait(); |
| 88 // The WebThread destructor blocks until all the tasks of the database | 88 // The WebThread destructor blocks until all the tasks of the database |
| 89 // thread are processed. However, it shouldn't block at all because | 89 // thread are processed. However, it shouldn't block at all because |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 WrapCrossThreadPersistent(this))); | 121 WrapCrossThreadPersistent(this))); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void DatabaseThread::CleanupDatabaseThreadCompleted() { | 124 void DatabaseThread::CleanupDatabaseThreadCompleted() { |
| 125 thread_->Shutdown(); | 125 thread_->Shutdown(); |
| 126 if (cleanup_sync_) // Someone wanted to know when we were done cleaning up. | 126 if (cleanup_sync_) // Someone wanted to know when we were done cleaning up. |
| 127 cleanup_sync_->Signal(); | 127 cleanup_sync_->Signal(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void DatabaseThread::RecordDatabaseOpen(Database* database) { | 130 void DatabaseThread::RecordDatabaseOpen(Database* database) { |
| 131 ASSERT(IsDatabaseThread()); | 131 DCHECK(IsDatabaseThread()); |
| 132 ASSERT(database); | 132 DCHECK(database); |
| 133 ASSERT(!open_database_set_.Contains(database)); | 133 DCHECK(!open_database_set_.Contains(database)); |
| 134 MutexLocker lock(termination_requested_mutex_); | 134 MutexLocker lock(termination_requested_mutex_); |
| 135 if (!termination_requested_) | 135 if (!termination_requested_) |
| 136 open_database_set_.insert(database); | 136 open_database_set_.insert(database); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void DatabaseThread::RecordDatabaseClosed(Database* database) { | 139 void DatabaseThread::RecordDatabaseClosed(Database* database) { |
| 140 ASSERT(IsDatabaseThread()); | 140 DCHECK(IsDatabaseThread()); |
| 141 ASSERT(database); | 141 DCHECK(database); |
| 142 #if DCHECK_IS_ON() | 142 #if DCHECK_IS_ON() |
| 143 { | 143 { |
| 144 MutexLocker lock(termination_requested_mutex_); | 144 MutexLocker lock(termination_requested_mutex_); |
| 145 ASSERT(termination_requested_ || open_database_set_.Contains(database)); | 145 DCHECK(termination_requested_ || open_database_set_.Contains(database)); |
| 146 } | 146 } |
| 147 #endif | 147 #endif |
| 148 open_database_set_.erase(database); | 148 open_database_set_.erase(database); |
| 149 } | 149 } |
| 150 | 150 |
| 151 bool DatabaseThread::IsDatabaseOpen(Database* database) { | 151 bool DatabaseThread::IsDatabaseOpen(Database* database) { |
| 152 ASSERT(IsDatabaseThread()); | 152 DCHECK(IsDatabaseThread()); |
| 153 ASSERT(database); | 153 DCHECK(database); |
| 154 MutexLocker lock(termination_requested_mutex_); | 154 MutexLocker lock(termination_requested_mutex_); |
| 155 return !termination_requested_ && open_database_set_.Contains(database); | 155 return !termination_requested_ && open_database_set_.Contains(database); |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool DatabaseThread::IsDatabaseThread() const { | 158 bool DatabaseThread::IsDatabaseThread() const { |
| 159 // This function is called only from the main thread or the database | 159 // This function is called only from the main thread or the database |
| 160 // thread. If we are not in the main thread, we are in the database thread. | 160 // thread. If we are not in the main thread, we are in the database thread. |
| 161 return !IsMainThread(); | 161 return !IsMainThread(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void DatabaseThread::ScheduleTask(std::unique_ptr<DatabaseTask> task) { | 164 void DatabaseThread::ScheduleTask(std::unique_ptr<DatabaseTask> task) { |
| 165 ASSERT(thread_); | 165 DCHECK(thread_); |
| 166 #if DCHECK_IS_ON() | 166 #if DCHECK_IS_ON() |
| 167 { | 167 { |
| 168 MutexLocker lock(termination_requested_mutex_); | 168 MutexLocker lock(termination_requested_mutex_); |
| 169 ASSERT(!termination_requested_); | 169 DCHECK(!termination_requested_); |
| 170 } | 170 } |
| 171 #endif | 171 #endif |
| 172 // WebThread takes ownership of the task. | 172 // WebThread takes ownership of the task. |
| 173 thread_->PostTask(BLINK_FROM_HERE, | 173 thread_->PostTask(BLINK_FROM_HERE, |
| 174 CrossThreadBind(&DatabaseTask::Run, std::move(task))); | 174 CrossThreadBind(&DatabaseTask::Run, std::move(task))); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace blink | 177 } // namespace blink |
| OLD | NEW |