| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 LevelDBWrapperImpl::~LevelDBWrapperImpl() { | 72 LevelDBWrapperImpl::~LevelDBWrapperImpl() { |
| 73 if (commit_batch_) | 73 if (commit_batch_) |
| 74 CommitChanges(); | 74 CommitChanges(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void LevelDBWrapperImpl::Bind(mojom::LevelDBWrapperRequest request) { | 77 void LevelDBWrapperImpl::Bind(mojom::LevelDBWrapperRequest request) { |
| 78 bindings_.AddBinding(this, std::move(request)); | 78 bindings_.AddBinding(this, std::move(request)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void LevelDBWrapperImpl::AddObserver(mojom::LevelDBObserverPtr observer) { | |
| 82 observers_.AddPtr(std::move(observer)); | |
| 83 } | |
| 84 | |
| 85 void LevelDBWrapperImpl::EnableAggressiveCommitDelay() { | 81 void LevelDBWrapperImpl::EnableAggressiveCommitDelay() { |
| 86 s_aggressive_flushing_enabled_ = true; | 82 s_aggressive_flushing_enabled_ = true; |
| 87 } | 83 } |
| 88 | 84 |
| 85 void LevelDBWrapperImpl::AddObserver( |
| 86 mojom::LevelDBObserverAssociatedPtrInfo observer) { |
| 87 mojom::LevelDBObserverAssociatedPtr observer_ptr; |
| 88 observer_ptr.Bind(std::move(observer)); |
| 89 observers_.AddPtr(std::move(observer_ptr)); |
| 90 } |
| 91 |
| 89 void LevelDBWrapperImpl::Put(const std::vector<uint8_t>& key, | 92 void LevelDBWrapperImpl::Put(const std::vector<uint8_t>& key, |
| 90 const std::vector<uint8_t>& value, | 93 const std::vector<uint8_t>& value, |
| 91 const std::string& source, | 94 const std::string& source, |
| 92 const PutCallback& callback) { | 95 const PutCallback& callback) { |
| 93 if (!map_) { | 96 if (!map_) { |
| 94 LoadMap(base::Bind(&LevelDBWrapperImpl::Put, base::Unretained(this), key, | 97 LoadMap(base::Bind(&LevelDBWrapperImpl::Put, base::Unretained(this), key, |
| 95 value, source, callback)); | 98 value, source, callback)); |
| 96 return; | 99 return; |
| 97 } | 100 } |
| 98 | 101 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 weak_ptr_factory_.GetWeakPtr())); | 362 weak_ptr_factory_.GetWeakPtr())); |
| 360 } | 363 } |
| 361 | 364 |
| 362 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { | 365 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { |
| 363 // TODO(michaeln): What if it fails, uma here or in the DB class? | 366 // TODO(michaeln): What if it fails, uma here or in the DB class? |
| 364 --commit_batches_in_flight_; | 367 --commit_batches_in_flight_; |
| 365 StartCommitTimer(); | 368 StartCommitTimer(); |
| 366 } | 369 } |
| 367 | 370 |
| 368 } // namespace content | 371 } // namespace content |
| OLD | NEW |