| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/leveldb_wrapper_impl.h" | 5 #include "content/browser/leveldb_wrapper_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "components/leveldb/public/cpp/util.h" | 9 #include "components/leveldb/public/cpp/util.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 void LevelDBWrapperImpl::CommitChanges() { | 330 void LevelDBWrapperImpl::CommitChanges() { |
| 331 DCHECK(database_); | 331 DCHECK(database_); |
| 332 DCHECK(map_); | 332 DCHECK(map_); |
| 333 if (!commit_batch_) | 333 if (!commit_batch_) |
| 334 return; | 334 return; |
| 335 | 335 |
| 336 commit_rate_limiter_.add_samples(1); | 336 commit_rate_limiter_.add_samples(1); |
| 337 | 337 |
| 338 // Commit all our changes in a single batch. | 338 // Commit all our changes in a single batch. |
| 339 std::vector<leveldb::mojom::BatchedOperationPtr> operations = | 339 std::vector<leveldb::mojom::BatchedOperationPtr> operations = |
| 340 prepare_to_commit_callback_.Run(); | 340 prepare_to_commit_callback_.Run(*this); |
| 341 if (commit_batch_->clear_all_first) { | 341 if (commit_batch_->clear_all_first) { |
| 342 leveldb::mojom::BatchedOperationPtr item = | 342 leveldb::mojom::BatchedOperationPtr item = |
| 343 leveldb::mojom::BatchedOperation::New(); | 343 leveldb::mojom::BatchedOperation::New(); |
| 344 item->type = leveldb::mojom::BatchOperationType::DELETE_PREFIXED_KEY; | 344 item->type = leveldb::mojom::BatchOperationType::DELETE_PREFIXED_KEY; |
| 345 item->key = prefix_; | 345 item->key = prefix_; |
| 346 operations.push_back(std::move(item)); | 346 operations.push_back(std::move(item)); |
| 347 } | 347 } |
| 348 size_t data_size = 0; | 348 size_t data_size = 0; |
| 349 for (const auto& key: commit_batch_->changed_keys) { | 349 for (const auto& key: commit_batch_->changed_keys) { |
| 350 data_size += key.size(); | 350 data_size += key.size(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 376 weak_ptr_factory_.GetWeakPtr())); | 376 weak_ptr_factory_.GetWeakPtr())); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { | 379 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { |
| 380 // TODO(michaeln): What if it fails, uma here or in the DB class? | 380 // TODO(michaeln): What if it fails, uma here or in the DB class? |
| 381 --commit_batches_in_flight_; | 381 --commit_batches_in_flight_; |
| 382 StartCommitTimer(); | 382 StartCommitTimer(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace content | 385 } // namespace content |
| OLD | NEW |