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

Side by Side Diff: content/browser/indexed_db/indexed_db_transaction.cc

Issue 2083203002: IndexedDB: Ensure transactions without requests commit in the same order (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/storage/indexeddb/empty-transaction-order.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 191 }
192 192
193 void IndexedDBTransaction::RegisterOpenCursor(IndexedDBCursor* cursor) { 193 void IndexedDBTransaction::RegisterOpenCursor(IndexedDBCursor* cursor) {
194 open_cursors_.insert(cursor); 194 open_cursors_.insert(cursor);
195 } 195 }
196 196
197 void IndexedDBTransaction::UnregisterOpenCursor(IndexedDBCursor* cursor) { 197 void IndexedDBTransaction::UnregisterOpenCursor(IndexedDBCursor* cursor) {
198 open_cursors_.erase(cursor); 198 open_cursors_.erase(cursor);
199 } 199 }
200 200
201 namespace {
202 void CommitUnused(scoped_refptr<IndexedDBTransaction> transaction) {
cmumford 2016/06/22 16:53:37 Do you want an anonymous namespace inside of the "
jsbell 2016/06/22 18:53:04 Yeah, we mostly put anon/helpers at the top, so mo
203 leveldb::Status status = transaction->Commit();
204 DCHECK(status.ok());
205 }
206 } // namespace
207
201 void IndexedDBTransaction::Start() { 208 void IndexedDBTransaction::Start() {
202 // TransactionCoordinator has started this transaction. 209 // TransactionCoordinator has started this transaction.
203 DCHECK_EQ(CREATED, state_); 210 DCHECK_EQ(CREATED, state_);
204 state_ = STARTED; 211 state_ = STARTED;
205 diagnostics_.start_time = base::Time::Now(); 212 diagnostics_.start_time = base::Time::Now();
206 213
207 if (!used_) 214 if (!used_) {
215 if (commit_pending_) {
216 // The transaction has never had requests issued against it,
217 // but the front-end requested a commit initiate the commit
cmumford 2016/06/22 16:53:37 Nit: oddly worded "commit initiate the commit".
jsbell 2016/06/22 18:53:04 Fixed, thx.
218 // but not re-entrantly as that may renter the coordinator.
219 base::ThreadTaskRunnerHandle::Get()->PostTask(
220 FROM_HERE, base::Bind(&CommitUnused, make_scoped_refptr(this)));
221 }
208 return; 222 return;
223 }
209 224
210 RunTasksIfStarted(); 225 RunTasksIfStarted();
211 } 226 }
212 227
213 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback { 228 class BlobWriteCallbackImpl : public IndexedDBBackingStore::BlobWriteCallback {
214 public: 229 public:
215 explicit BlobWriteCallbackImpl( 230 explicit BlobWriteCallbackImpl(
216 scoped_refptr<IndexedDBTransaction> transaction) 231 scoped_refptr<IndexedDBTransaction> transaction)
217 : transaction_(transaction) {} 232 : transaction_(transaction) {}
218 void Run(bool succeeded) override { 233 void Run(bool succeeded) override {
(...skipping 27 matching lines...) Expand all
246 // In multiprocess ports, front-end may have requested a commit but 261 // In multiprocess ports, front-end may have requested a commit but
247 // an abort has already been initiated asynchronously by the 262 // an abort has already been initiated asynchronously by the
248 // back-end. 263 // back-end.
249 if (state_ == FINISHED) 264 if (state_ == FINISHED)
250 return leveldb::Status::OK(); 265 return leveldb::Status::OK();
251 DCHECK_NE(state_, COMMITTING); 266 DCHECK_NE(state_, COMMITTING);
252 267
253 DCHECK(!used_ || state_ == STARTED); 268 DCHECK(!used_ || state_ == STARTED);
254 commit_pending_ = true; 269 commit_pending_ = true;
255 270
271 if (state_ != STARTED)
cmumford 2016/06/22 16:53:37 Nit: Possibly worthy of a short comment - your cal
jsbell 2016/06/22 18:53:04 Done.
272 return leveldb::Status::OK();
273
256 // Front-end has requested a commit, but there may be tasks like 274 // Front-end has requested a commit, but there may be tasks like
257 // create_index which are considered synchronous by the front-end 275 // create_index which are considered synchronous by the front-end
258 // but are processed asynchronously. 276 // but are processed asynchronously.
259 if (HasPendingTasks()) 277 if (HasPendingTasks())
260 return leveldb::Status::OK(); 278 return leveldb::Status::OK();
261 279
262 state_ = COMMITTING; 280 state_ = COMMITTING;
263 281
264 leveldb::Status s; 282 leveldb::Status s;
265 if (!used_) { 283 if (!used_) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 432 }
415 433
416 void IndexedDBTransaction::CloseOpenCursors() { 434 void IndexedDBTransaction::CloseOpenCursors() {
417 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id()); 435 IDB_TRACE1("IndexedDBTransaction::CloseOpenCursors", "txn.id", id());
418 for (auto* cursor : open_cursors_) 436 for (auto* cursor : open_cursors_)
419 cursor->Close(); 437 cursor->Close();
420 open_cursors_.clear(); 438 open_cursors_.clear();
421 } 439 }
422 440
423 } // namespace content 441 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/storage/indexeddb/empty-transaction-order.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698