| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return; | 236 return; |
| 237 no_bindings_callback_.Run(); | 237 no_bindings_callback_.Run(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void LevelDBWrapperImpl::LoadMap(const base::Closure& completion_callback) { | 240 void LevelDBWrapperImpl::LoadMap(const base::Closure& completion_callback) { |
| 241 DCHECK(!map_); | 241 DCHECK(!map_); |
| 242 on_load_complete_tasks_.push_back(completion_callback); | 242 on_load_complete_tasks_.push_back(completion_callback); |
| 243 if (on_load_complete_tasks_.size() > 1) | 243 if (on_load_complete_tasks_.size() > 1) |
| 244 return; | 244 return; |
| 245 | 245 |
| 246 if (!database_) { |
| 247 OnLoadComplete(leveldb::mojom::DatabaseError::IO_ERROR, |
| 248 std::vector<leveldb::mojom::KeyValuePtr>()); |
| 249 return; |
| 250 } |
| 251 |
| 246 // TODO(michaeln): Import from sqlite localstorage db. | 252 // TODO(michaeln): Import from sqlite localstorage db. |
| 247 database_->GetPrefixed(prefix_, | 253 database_->GetPrefixed(prefix_, |
| 248 base::Bind(&LevelDBWrapperImpl::OnLoadComplete, | 254 base::Bind(&LevelDBWrapperImpl::OnLoadComplete, |
| 249 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 250 } | 256 } |
| 251 | 257 |
| 252 void LevelDBWrapperImpl::OnLoadComplete( | 258 void LevelDBWrapperImpl::OnLoadComplete( |
| 253 leveldb::mojom::DatabaseError status, | 259 leveldb::mojom::DatabaseError status, |
| 254 std::vector<leveldb::mojom::KeyValuePtr> data) { | 260 std::vector<leveldb::mojom::KeyValuePtr> data) { |
| 255 DCHECK(!map_); | 261 DCHECK(!map_); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 weak_ptr_factory_.GetWeakPtr())); | 373 weak_ptr_factory_.GetWeakPtr())); |
| 368 } | 374 } |
| 369 | 375 |
| 370 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { | 376 void LevelDBWrapperImpl::OnCommitComplete(leveldb::mojom::DatabaseError error) { |
| 371 // TODO(michaeln): What if it fails, uma here or in the DB class? | 377 // TODO(michaeln): What if it fails, uma here or in the DB class? |
| 372 --commit_batches_in_flight_; | 378 --commit_batches_in_flight_; |
| 373 StartCommitTimer(); | 379 StartCommitTimer(); |
| 374 } | 380 } |
| 375 | 381 |
| 376 } // namespace content | 382 } // namespace content |
| OLD | NEW |