Chromium Code Reviews| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 } | 209 } |
| 210 | 210 |
| 211 auto found = map_->find(key); | 211 auto found = map_->find(key); |
| 212 if (found == map_->end()) { | 212 if (found == map_->end()) { |
| 213 callback.Run(false, std::vector<uint8_t>()); | 213 callback.Run(false, std::vector<uint8_t>()); |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 callback.Run(true, found->second); | 216 callback.Run(true, found->second); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void LevelDBWrapperImpl::GetAll(const std::string& source, | 219 void LevelDBWrapperImpl::GetAll( |
| 220 const GetAllCallback& callback) { | 220 mojom::LevelDBWrapperGetAllCallbackAssociatedPtrInfo complete_callback, |
| 221 const GetAllCallback& callback) { | |
| 221 if (!map_) { | 222 if (!map_) { |
| 222 LoadMap( | 223 LoadMap(base::Bind(&LevelDBWrapperImpl::GetAll, base::Unretained(this), |
| 223 base::Bind(&LevelDBWrapperImpl::GetAll, base::Unretained(this), | 224 base::Passed(std::move(complete_callback)), callback)); |
|
dcheng
2016/12/22 07:21:47
Nit: base::Passed(&complete_callback)
Marijn Kruisselbrink
2016/12/22 17:12:19
I find the std::move version of base::Passed more
| |
| 224 source, callback)); | |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 | 227 |
| 228 std::vector<mojom::KeyValuePtr> all; | 228 std::vector<mojom::KeyValuePtr> all; |
| 229 for (const auto& it : (*map_)) { | 229 for (const auto& it : (*map_)) { |
| 230 mojom::KeyValuePtr kv = mojom::KeyValue::New(); | 230 mojom::KeyValuePtr kv = mojom::KeyValue::New(); |
| 231 kv->key = it.first; | 231 kv->key = it.first; |
| 232 kv->value = it.second; | 232 kv->value = it.second; |
| 233 all.push_back(std::move(kv)); | 233 all.push_back(std::move(kv)); |
| 234 } | 234 } |
| 235 callback.Run(leveldb::mojom::DatabaseError::OK, std::move(all)); | 235 callback.Run(leveldb::mojom::DatabaseError::OK, std::move(all)); |
| 236 observers_.ForAllPtrs( | 236 if (complete_callback.is_valid()) { |
| 237 [source](mojom::LevelDBObserver* observer) { | 237 mojom::LevelDBWrapperGetAllCallbackAssociatedPtr complete_ptr; |
| 238 observer->GetAllComplete(source); | 238 complete_ptr.Bind(std::move(complete_callback)); |
| 239 }); | 239 complete_ptr->Complete(true); |
| 240 } | |
| 240 } | 241 } |
| 241 | 242 |
| 242 void LevelDBWrapperImpl::OnConnectionError() { | 243 void LevelDBWrapperImpl::OnConnectionError() { |
| 243 if (!bindings_.empty()) | 244 if (!bindings_.empty()) |
| 244 return; | 245 return; |
| 245 no_bindings_callback_.Run(); | 246 no_bindings_callback_.Run(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 void LevelDBWrapperImpl::LoadMap(const base::Closure& completion_callback) { | 249 void LevelDBWrapperImpl::LoadMap(const base::Closure& completion_callback) { |
| 249 DCHECK(!map_); | 250 DCHECK(!map_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 weak_ptr_factory_.GetWeakPtr())); | 365 weak_ptr_factory_.GetWeakPtr())); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { | 368 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { |
| 368 // TODO(michaeln): What if it fails, uma here or in the DB class? | 369 // TODO(michaeln): What if it fails, uma here or in the DB class? |
| 369 --commit_batches_in_flight_; | 370 --commit_batches_in_flight_; |
| 370 StartCommitTimer(); | 371 StartCommitTimer(); |
| 371 } | 372 } |
| 372 | 373 |
| 373 } // namespace content | 374 } // namespace content |
| OLD | NEW |