| 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 "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "mojo/common/common_type_converters.h" | 10 #include "mojo/common/common_type_converters.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 leveldb::mojom::BatchedOperationPtr item = | 328 leveldb::mojom::BatchedOperationPtr item = |
| 329 leveldb::mojom::BatchedOperation::New(); | 329 leveldb::mojom::BatchedOperation::New(); |
| 330 item->type = leveldb::mojom::BatchOperationType::DELETE_PREFIXED_KEY; | 330 item->type = leveldb::mojom::BatchOperationType::DELETE_PREFIXED_KEY; |
| 331 item->key = mojo::Array<uint8_t>::From(std::string(prefix_)); | 331 item->key = mojo::Array<uint8_t>::From(std::string(prefix_)); |
| 332 operations.push_back(std::move(item)); | 332 operations.push_back(std::move(item)); |
| 333 } | 333 } |
| 334 for (auto& it : commit_batch_->changed_values) { | 334 for (auto& it : commit_batch_->changed_values) { |
| 335 leveldb::mojom::BatchedOperationPtr item = | 335 leveldb::mojom::BatchedOperationPtr item = |
| 336 leveldb::mojom::BatchedOperation::New(); | 336 leveldb::mojom::BatchedOperation::New(); |
| 337 item->key = it.first.Clone(); | 337 item->key = it.first.Clone(); |
| 338 if (item->value.is_null()) { | 338 if (it.second.is_null()) { |
| 339 item->type = leveldb::mojom::BatchOperationType::DELETE_KEY; | 339 item->type = leveldb::mojom::BatchOperationType::DELETE_KEY; |
| 340 } else { | 340 } else { |
| 341 item->type = leveldb::mojom::BatchOperationType::PUT_KEY; | 341 item->type = leveldb::mojom::BatchOperationType::PUT_KEY; |
| 342 item->value = std::move(it.second); | 342 item->value = std::move(it.second); |
| 343 } | 343 } |
| 344 operations.push_back(std::move(item)); | 344 operations.push_back(std::move(item)); |
| 345 } | 345 } |
| 346 commit_batch_.reset(); | 346 commit_batch_.reset(); |
| 347 | 347 |
| 348 ++commit_batches_in_flight_; | 348 ++commit_batches_in_flight_; |
| 349 | 349 |
| 350 // TODO(michaeln): Currently there is no guarantee LevelDBDatabaseImp::Write | 350 // TODO(michaeln): Currently there is no guarantee LevelDBDatabaseImp::Write |
| 351 // will run during a clean shutdown. We need that to avoid dataloss. | 351 // will run during a clean shutdown. We need that to avoid dataloss. |
| 352 database_->Write(std::move(operations), | 352 database_->Write(std::move(operations), |
| 353 base::Bind(&LevelDBWrapperImpl::OnCommitComplete, | 353 base::Bind(&LevelDBWrapperImpl::OnCommitComplete, |
| 354 weak_ptr_factory_.GetWeakPtr())); | 354 weak_ptr_factory_.GetWeakPtr())); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { | 357 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { |
| 358 // TODO(michaeln): What if it fails, uma here or in the DB class? | 358 // TODO(michaeln): What if it fails, uma here or in the DB class? |
| 359 --commit_batches_in_flight_; | 359 --commit_batches_in_flight_; |
| 360 StartCommitTimer(); | 360 StartCommitTimer(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 } // namespace content | 363 } // namespace content |
| OLD | NEW |