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

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

Issue 2941353002: Indexed DB: Use BindOnce / OnceCallback / OnceClosure where applicable (Closed)
Patch Set: Created 3 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
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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 void IndexedDBTransaction::ScheduleTask(blink::WebIDBTaskType type, 139 void IndexedDBTransaction::ScheduleTask(blink::WebIDBTaskType type,
140 Operation task) { 140 Operation task) {
141 DCHECK_NE(state_, COMMITTING); 141 DCHECK_NE(state_, COMMITTING);
142 if (state_ == FINISHED) 142 if (state_ == FINISHED)
143 return; 143 return;
144 144
145 timeout_timer_.Stop(); 145 timeout_timer_.Stop();
146 used_ = true; 146 used_ = true;
147 if (type == blink::kWebIDBTaskTypeNormal) { 147 if (type == blink::kWebIDBTaskTypeNormal) {
148 task_queue_.push(task); 148 task_queue_.push(std::move(task));
149 ++diagnostics_.tasks_scheduled; 149 ++diagnostics_.tasks_scheduled;
150 } else { 150 } else {
151 preemptive_task_queue_.push(task); 151 preemptive_task_queue_.push(std::move(task));
152 } 152 }
153 RunTasksIfStarted(); 153 RunTasksIfStarted();
154 } 154 }
155 155
156 void IndexedDBTransaction::ScheduleAbortTask(AbortOperation abort_task) { 156 void IndexedDBTransaction::ScheduleAbortTask(AbortOperation abort_task) {
157 DCHECK_NE(FINISHED, state_); 157 DCHECK_NE(FINISHED, state_);
158 DCHECK(used_); 158 DCHECK(used_);
159 abort_task_stack_.push(std::move(abort_task)); 159 abort_task_stack_.push(std::move(abort_task));
160 } 160 }
161 161
162 void IndexedDBTransaction::RunTasksIfStarted() { 162 void IndexedDBTransaction::RunTasksIfStarted() {
163 DCHECK(used_); 163 DCHECK(used_);
164 164
165 // Not started by the coordinator yet. 165 // Not started by the coordinator yet.
166 if (state_ != STARTED) 166 if (state_ != STARTED)
167 return; 167 return;
168 168
169 // A task is already posted. 169 // A task is already posted.
170 if (should_process_queue_) 170 if (should_process_queue_)
171 return; 171 return;
172 172
173 should_process_queue_ = true; 173 should_process_queue_ = true;
174 base::SequencedTaskRunnerHandle::Get()->PostTask( 174 base::SequencedTaskRunnerHandle::Get()->PostTask(
175 FROM_HERE, base::Bind(&IndexedDBTransaction::ProcessTaskQueue, 175 FROM_HERE, base::BindOnce(&IndexedDBTransaction::ProcessTaskQueue,
176 ptr_factory_.GetWeakPtr())); 176 ptr_factory_.GetWeakPtr()));
177 } 177 }
178 178
179 void IndexedDBTransaction::Abort(const IndexedDBDatabaseError& error) { 179 void IndexedDBTransaction::Abort(const IndexedDBDatabaseError& error) {
180 IDB_TRACE1("IndexedDBTransaction::Abort", "txn.id", id()); 180 IDB_TRACE1("IndexedDBTransaction::Abort", "txn.id", id());
181 DCHECK(!processing_event_queue_); 181 DCHECK(!processing_event_queue_);
182 if (state_ == FINISHED) 182 if (state_ == FINISHED)
183 return; 183 return;
184 184
185 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.TransactionAbortReason", 185 UMA_HISTOGRAM_ENUMERATION("WebCore.IndexedDB.TransactionAbortReason",
186 ExceptionCodeToUmaEnum(error.code()), 186 ExceptionCodeToUmaEnum(error.code()),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 DCHECK_EQ(CREATED, state_); 247 DCHECK_EQ(CREATED, state_);
248 state_ = STARTED; 248 state_ = STARTED;
249 diagnostics_.start_time = base::Time::Now(); 249 diagnostics_.start_time = base::Time::Now();
250 250
251 if (!used_) { 251 if (!used_) {
252 if (commit_pending_) { 252 if (commit_pending_) {
253 // The transaction has never had requests issued against it, but the 253 // The transaction has never had requests issued against it, but the
254 // front-end previously requested a commit; do the commit now, but not 254 // front-end previously requested a commit; do the commit now, but not
255 // re-entrantly as that may renter the coordinator. 255 // re-entrantly as that may renter the coordinator.
256 base::SequencedTaskRunnerHandle::Get()->PostTask( 256 base::SequencedTaskRunnerHandle::Get()->PostTask(
257 FROM_HERE, base::Bind(&CommitUnused, ptr_factory_.GetWeakPtr())); 257 FROM_HERE, base::BindOnce(&CommitUnused, ptr_factory_.GetWeakPtr()));
258 } 258 }
259 return; 259 return;
260 } 260 }
261 261
262 RunTasksIfStarted(); 262 RunTasksIfStarted();
263 } 263 }
264 264
265 void IndexedDBTransaction::GrabSnapshotThenStart() { 265 void IndexedDBTransaction::GrabSnapshotThenStart() {
266 DCHECK(!backing_store_transaction_begun_); 266 DCHECK(!backing_store_transaction_begun_);
267 transaction_->Begin(); 267 transaction_->Begin();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 if (!backing_store_transaction_begun_) { 478 if (!backing_store_transaction_begun_) {
479 transaction_->Begin(); 479 transaction_->Begin();
480 backing_store_transaction_begun_ = true; 480 backing_store_transaction_begun_ = true;
481 } 481 }
482 482
483 TaskQueue* task_queue = 483 TaskQueue* task_queue =
484 pending_preemptive_events_ ? &preemptive_task_queue_ : &task_queue_; 484 pending_preemptive_events_ ? &preemptive_task_queue_ : &task_queue_;
485 while (!task_queue->empty() && state_ != FINISHED) { 485 while (!task_queue->empty() && state_ != FINISHED) {
486 DCHECK_EQ(state_, STARTED); 486 DCHECK_EQ(state_, STARTED);
487 Operation task(task_queue->pop()); 487 Operation task(task_queue->pop());
488 leveldb::Status result = task.Run(this); 488 leveldb::Status result = std::move(task).Run(this);
489 if (!pending_preemptive_events_) { 489 if (!pending_preemptive_events_) {
490 DCHECK(diagnostics_.tasks_completed < diagnostics_.tasks_scheduled); 490 DCHECK(diagnostics_.tasks_completed < diagnostics_.tasks_scheduled);
491 ++diagnostics_.tasks_completed; 491 ++diagnostics_.tasks_completed;
492 } 492 }
493 if (!result.ok()) { 493 if (!result.ok()) {
494 processing_event_queue_ = false; 494 processing_event_queue_ = false;
495 database_->ReportError(result); 495 database_->ReportError(result);
496 return; 496 return;
497 } 497 }
498 498
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 582
583 ::indexed_db::mojom::ObserverChangesPtr* 583 ::indexed_db::mojom::ObserverChangesPtr*
584 IndexedDBTransaction::GetPendingChangesForConnection(int32_t connection_id) { 584 IndexedDBTransaction::GetPendingChangesForConnection(int32_t connection_id) {
585 auto it = connection_changes_map_.find(connection_id); 585 auto it = connection_changes_map_.find(connection_id);
586 if (it != connection_changes_map_.end()) 586 if (it != connection_changes_map_.end())
587 return &it->second; 587 return &it->second;
588 return nullptr; 588 return nullptr;
589 } 589 }
590 590
591 } // namespace content 591 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_transaction.h ('k') | content/browser/indexed_db/indexed_db_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698