| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/indexed_db/indexed_db_transaction.h" | 5 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 13 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 14 #include "content/browser/indexed_db/indexed_db_cursor.h" | 14 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 15 #include "content/browser/indexed_db/indexed_db_database.h" | 15 #include "content/browser/indexed_db/indexed_db_database.h" |
| 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | 16 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" |
| 17 #include "content/browser/indexed_db/indexed_db_tracing.h" | 17 #include "content/browser/indexed_db/indexed_db_tracing.h" |
| 18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 18 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 20 #include "third_party/leveldatabase/env_chromium.h" | 20 #include "third_party/leveldatabase/env_chromium.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 namespace { |
| 25 |
| 24 const int64_t kInactivityTimeoutPeriodSeconds = 60; | 26 const int64_t kInactivityTimeoutPeriodSeconds = 60; |
| 25 | 27 |
| 28 // Helper for posting a task to call IndexedDBTransaction::Commit when we know |
| 29 // the transaction had no requests and therefore the commit must succeed. |
| 30 void CommitUnused(scoped_refptr<IndexedDBTransaction> transaction) { |
| 31 leveldb::Status status = transaction->Commit(); |
| 32 DCHECK(status.ok()); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 26 IndexedDBTransaction::TaskQueue::TaskQueue() {} | 37 IndexedDBTransaction::TaskQueue::TaskQueue() {} |
| 27 IndexedDBTransaction::TaskQueue::~TaskQueue() { clear(); } | 38 IndexedDBTransaction::TaskQueue::~TaskQueue() { clear(); } |
| 28 | 39 |
| 29 void IndexedDBTransaction::TaskQueue::clear() { | 40 void IndexedDBTransaction::TaskQueue::clear() { |
| 30 while (!queue_.empty()) | 41 while (!queue_.empty()) |
| 31 queue_.pop(); | 42 queue_.pop(); |
| 32 } | 43 } |
| 33 | 44 |
| 34 IndexedDBTransaction::Operation IndexedDBTransaction::TaskQueue::pop() { | 45 IndexedDBTransaction::Operation IndexedDBTransaction::TaskQueue::pop() { |
| 35 DCHECK(!queue_.empty()); | 46 DCHECK(!queue_.empty()); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 void IndexedDBTransaction::UnregisterOpenCursor(IndexedDBCursor* cursor) { | 208 void IndexedDBTransaction::UnregisterOpenCursor(IndexedDBCursor* cursor) { |
| 198 open_cursors_.erase(cursor); | 209 open_cursors_.erase(cursor); |
| 199 } | 210 } |
| 200 | 211 |
| 201 void IndexedDBTransaction::Start() { | 212 void IndexedDBTransaction::Start() { |
| 202 // TransactionCoordinator has started this transaction. | 213 // TransactionCoordinator has started this transaction. |
| 203 DCHECK_EQ(CREATED, state_); | 214 DCHECK_EQ(CREATED, state_); |
| 204 state_ = STARTED; | 215 state_ = STARTED; |
| 205 diagnostics_.start_time = base::Time::Now(); | 216 diagnostics_.start_time = base::Time::Now(); |
| 206 | 217 |
| 207 if (!used_) | 218 if (!used_) { |
| 219 if (commit_pending_) { |
| 220 // The transaction has never had requests issued against it, but the |
| 221 // front-end previously requested a commit; do the commit now, but not |
| 222 // re-entrantly as that may renter the coordinator. |
| 223 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 224 FROM_HERE, base::Bind(&CommitUnused, make_scoped_refptr(this))); |
| 225 } |
| 208 return; | 226 return; |
| 227 } |
| 209 | 228 |
| 210 RunTasksIfStarted(); | 229 RunTasksIfStarted(); |
| 211 } | 230 } |
| 212 | 231 |
| 213 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { | 232 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { |
| 214 public: | 233 public: |
| 215 explicit BlobWriteCallbackImpl( | 234 explicit BlobWriteCallbackImpl( |
| 216 scoped_refptr<IndexedDBTransaction> transaction) | 235 scoped_refptr<IndexedDBTransaction> transaction) |
| 217 : transaction_(transaction) {} | 236 : transaction_(transaction) {} |
| 218 void Run(bool succeeded) override { | 237 void Run(bool succeeded) override { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 246 // In multiprocess ports, front-end may have requested a commit but | 265 // In multiprocess ports, front-end may have requested a commit but |
| 247 // an abort has already been initiated asynchronously by the | 266 // an abort has already been initiated asynchronously by the |
| 248 // back-end. | 267 // back-end. |
| 249 if (state_ == FINISHED) | 268 if (state_ == FINISHED) |
| 250 return leveldb::Status::OK(); | 269 return leveldb::Status::OK(); |
| 251 DCHECK_NE(state_, COMMITTING); | 270 DCHECK_NE(state_, COMMITTING); |
| 252 | 271 |
| 253 DCHECK(!used_ || state_ == STARTED); | 272 DCHECK(!used_ || state_ == STARTED); |
| 254 commit_pending_ = true; | 273 commit_pending_ = true; |
| 255 | 274 |
| 275 // Front-end has requested a commit, but this transaction is blocked by |
| 276 // other transactions. The commit will be initiated when the transaction |
| 277 // coordinator unblocks this transaction. |
| 278 if (state_ != STARTED) |
| 279 return leveldb::Status::OK(); |
| 280 |
| 256 // Front-end has requested a commit, but there may be tasks like | 281 // Front-end has requested a commit, but there may be tasks like |
| 257 // create_index which are considered synchronous by the front-end | 282 // create_index which are considered synchronous by the front-end |
| 258 // but are processed asynchronously. | 283 // but are processed asynchronously. |
| 259 if (HasPendingTasks()) | 284 if (HasPendingTasks()) |
| 260 return leveldb::Status::OK(); | 285 return leveldb::Status::OK(); |
| 261 | 286 |
| 262 state_ = COMMITTING; | 287 state_ = COMMITTING; |
| 263 | 288 |
| 264 leveldb::Status s; | 289 leveldb::Status s; |
| 265 if (!used_) { | 290 if (!used_) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 439 } |
| 415 | 440 |
| 416 void IndexedDBTransaction::CloseOpenCursors() { | 441 void IndexedDBTransaction::CloseOpenCursors() { |
| 417 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); | 442 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); |
| 418 for (auto* cursor : open_cursors_) | 443 for (auto* cursor : open_cursors_) |
| 419 cursor->Close(); | 444 cursor->Close(); |
| 420 open_cursors_.clear(); | 445 open_cursors_.clear(); |
| 421 } | 446 } |
| 422 | 447 |
| 423 } // namespace content | 448 } // namespace content |
| OLD | NEW |