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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
15 #include "content/browser/indexed_db/indexed_db_backing_store.h" | 17 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 18 #include "content/browser/indexed_db/indexed_db_change_handler.h" |
16 #include "content/browser/indexed_db/indexed_db_cursor.h" | 19 #include "content/browser/indexed_db/indexed_db_cursor.h" |
17 #include "content/browser/indexed_db/indexed_db_database.h" | 20 #include "content/browser/indexed_db/indexed_db_database.h" |
18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" | |
19 #include "content/browser/indexed_db/indexed_db_observation.h" | 21 #include "content/browser/indexed_db/indexed_db_observation.h" |
20 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 22 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
21 #include "content/browser/indexed_db/indexed_db_tracing.h" | 23 #include "content/browser/indexed_db/indexed_db_tracing.h" |
22 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" | 24 #include "content/browser/indexed_db/indexed_db_transaction_coordinator.h" |
23 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 25 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
24 #include "third_party/leveldatabase/env_chromium.h" | 26 #include "third_party/leveldatabase/env_chromium.h" |
25 | 27 |
26 namespace content { | 28 namespace content { |
27 | 29 |
28 namespace { | 30 namespace { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 object_store_ids_(object_store_ids), | 80 object_store_ids_(object_store_ids), |
79 mode_(mode), | 81 mode_(mode), |
80 used_(false), | 82 used_(false), |
81 state_(CREATED), | 83 state_(CREATED), |
82 commit_pending_(false), | 84 commit_pending_(false), |
83 connection_(std::move(connection)), | 85 connection_(std::move(connection)), |
84 transaction_(backing_store_transaction), | 86 transaction_(backing_store_transaction), |
85 backing_store_transaction_begun_(false), | 87 backing_store_transaction_begun_(false), |
86 should_process_queue_(false), | 88 should_process_queue_(false), |
87 pending_preemptive_events_(0) { | 89 pending_preemptive_events_(0) { |
88 callbacks_ = connection_->callbacks(); | 90 change_handler_ = connection_->change_handler(); |
89 database_ = connection_->database(); | 91 database_ = connection_->database(); |
90 | 92 |
91 database_->transaction_coordinator().DidCreateTransaction(this); | 93 database_->transaction_coordinator().DidCreateTransaction(this); |
92 | 94 |
93 diagnostics_.tasks_scheduled = 0; | 95 diagnostics_.tasks_scheduled = 0; |
94 diagnostics_.tasks_completed = 0; | 96 diagnostics_.tasks_completed = 0; |
95 diagnostics_.creation_time = base::Time::Now(); | 97 diagnostics_.creation_time = base::Time::Now(); |
96 } | 98 } |
97 | 99 |
98 IndexedDBTransaction::~IndexedDBTransaction() { | 100 IndexedDBTransaction::~IndexedDBTransaction() { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 transaction_->Reset(); | 186 transaction_->Reset(); |
185 | 187 |
186 // Transactions must also be marked as completed before the | 188 // Transactions must also be marked as completed before the |
187 // front-end is notified, as the transaction completion unblocks | 189 // front-end is notified, as the transaction completion unblocks |
188 // operations like closing connections. | 190 // operations like closing connections. |
189 database_->transaction_coordinator().DidFinishTransaction(this); | 191 database_->transaction_coordinator().DidFinishTransaction(this); |
190 #ifndef NDEBUG | 192 #ifndef NDEBUG |
191 DCHECK(!database_->transaction_coordinator().IsActive(this)); | 193 DCHECK(!database_->transaction_coordinator().IsActive(this)); |
192 #endif | 194 #endif |
193 | 195 |
194 if (callbacks_.get()) | 196 if (change_handler_.get()) |
195 callbacks_->OnAbort(id_, error); | 197 change_handler_->OnAbort(id_, error); |
196 | 198 |
197 database_->TransactionFinished(this, false); | 199 database_->TransactionFinished(this, false); |
198 | 200 |
199 database_ = NULL; | 201 database_ = NULL; |
200 connection_ = nullptr; | 202 connection_ = nullptr; |
201 pending_observers_.clear(); | 203 pending_observers_.clear(); |
202 } | 204 } |
203 | 205 |
204 bool IndexedDBTransaction::IsTaskQueueEmpty() const { | 206 bool IndexedDBTransaction::IsTaskQueueEmpty() const { |
205 return preemptive_task_queue_.empty() && task_queue_.empty(); | 207 return preemptive_task_queue_.empty() && task_queue_.empty(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 // SendObservations must be called before OnComplete to ensure consistency | 354 // SendObservations must be called before OnComplete to ensure consistency |
353 // of callbacks at renderer. | 355 // of callbacks at renderer. |
354 if (!connection_changes_map_.empty()) { | 356 if (!connection_changes_map_.empty()) { |
355 database_->SendObservations(std::move(connection_changes_map_)); | 357 database_->SendObservations(std::move(connection_changes_map_)); |
356 connection_changes_map_.clear(); | 358 connection_changes_map_.clear(); |
357 } | 359 } |
358 { | 360 { |
359 IDB_TRACE1( | 361 IDB_TRACE1( |
360 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", | 362 "IndexedDBTransaction::CommitPhaseTwo.TransactionCompleteCallbacks", |
361 "txn.id", id()); | 363 "txn.id", id()); |
362 callbacks_->OnComplete(id_); | 364 change_handler_->OnComplete(id_); |
363 } | 365 } |
364 if (!pending_observers_.empty() && connection_) { | 366 if (!pending_observers_.empty() && connection_) { |
365 connection_->ActivatePendingObservers(std::move(pending_observers_)); | 367 connection_->ActivatePendingObservers(std::move(pending_observers_)); |
366 pending_observers_.clear(); | 368 pending_observers_.clear(); |
367 } | 369 } |
368 | 370 |
369 database_->TransactionFinished(this, true); | 371 database_->TransactionFinished(this, true); |
370 } else { | 372 } else { |
371 while (!abort_task_stack_.empty()) | 373 while (!abort_task_stack_.empty()) |
372 abort_task_stack_.pop().Run(NULL); | 374 abort_task_stack_.pop().Run(NULL); |
373 | 375 |
374 IndexedDBDatabaseError error; | 376 IndexedDBDatabaseError error; |
375 if (leveldb_env::IndicatesDiskFull(s)) { | 377 if (leveldb_env::IndicatesDiskFull(s)) { |
376 error = IndexedDBDatabaseError( | 378 error = IndexedDBDatabaseError( |
377 blink::WebIDBDatabaseExceptionQuotaError, | 379 blink::WebIDBDatabaseExceptionQuotaError, |
378 "Encountered disk full while committing transaction."); | 380 "Encountered disk full while committing transaction."); |
379 } else { | 381 } else { |
380 error = IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, | 382 error = IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionUnknownError, |
381 "Internal error committing transaction."); | 383 "Internal error committing transaction."); |
382 } | 384 } |
383 callbacks_->OnAbort(id_, error); | 385 change_handler_->OnAbort(id_, error); |
384 | 386 |
385 database_->TransactionFinished(this, false); | 387 database_->TransactionFinished(this, false); |
386 database_->TransactionCommitFailed(s); | 388 database_->TransactionCommitFailed(s); |
387 } | 389 } |
388 | 390 |
389 database_ = NULL; | 391 database_ = NULL; |
390 return s; | 392 return s; |
391 } | 393 } |
392 | 394 |
393 void IndexedDBTransaction::ProcessTaskQueue() { | 395 void IndexedDBTransaction::ProcessTaskQueue() { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 500 |
499 void IndexedDBTransaction::RecordObserverForLastObservation( | 501 void IndexedDBTransaction::RecordObserverForLastObservation( |
500 int32_t connection_id, | 502 int32_t connection_id, |
501 int32_t observer_id) { | 503 int32_t observer_id) { |
502 auto it = connection_changes_map_.find(connection_id); | 504 auto it = connection_changes_map_.find(connection_id); |
503 DCHECK(it != connection_changes_map_.end()); | 505 DCHECK(it != connection_changes_map_.end()); |
504 it->second->RecordObserverForLastObservation(observer_id); | 506 it->second->RecordObserverForLastObservation(observer_id); |
505 } | 507 } |
506 | 508 |
507 } // namespace content | 509 } // namespace content |
OLD | NEW |