| 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 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 LevelDBWrapperImpl::LevelDBWrapperImpl( | 11 LevelDBWrapperImpl::LevelDBWrapperImpl( |
| 12 const std::string& prefix, const base::Closure& no_bindings_callback) | 12 leveldb::LevelDBDatabase* database, |
| 13 : prefix_(prefix), no_bindings_callback_(no_bindings_callback) { | 13 const std::string& prefix, |
| 14 const base::Closure& no_bindings_callback) |
| 15 : prefix_(prefix), |
| 16 no_bindings_callback_(no_bindings_callback), |
| 17 database_(database) { |
| 14 bindings_.set_connection_error_handler(base::Bind( | 18 bindings_.set_connection_error_handler(base::Bind( |
| 15 &LevelDBWrapperImpl::OnConnectionError, base::Unretained(this))); | 19 &LevelDBWrapperImpl::OnConnectionError, base::Unretained(this))); |
| 16 } | 20 } |
| 17 | 21 |
| 18 void LevelDBWrapperImpl::Bind(mojo::InterfaceRequest<LevelDBWrapper> request) { | 22 void LevelDBWrapperImpl::Bind(LevelDBWrapperRequest request) { |
| 19 bindings_.AddBinding(this, std::move(request)); | 23 bindings_.AddBinding(this, std::move(request)); |
| 20 } | 24 } |
| 21 | 25 |
| 22 LevelDBWrapperImpl::~LevelDBWrapperImpl() { | 26 LevelDBWrapperImpl::~LevelDBWrapperImpl() {} |
| 23 } | |
| 24 | 27 |
| 25 void LevelDBWrapperImpl::Put(mojo::Array<uint8_t> key, | 28 void LevelDBWrapperImpl::Put(mojo::Array<uint8_t> key, |
| 26 mojo::Array<uint8_t> value, | 29 mojo::Array<uint8_t> value, |
| 27 const mojo::String& source, | 30 const mojo::String& source, |
| 28 const PutCallback& callback) { | 31 const PutCallback& callback) { |
| 29 // TODO(jam): call observers before running callback. | 32 NOTIMPLEMENTED(); |
| 33 callback.Run(leveldb::DatabaseError::NOT_SUPPORTED); |
| 30 } | 34 } |
| 31 | 35 |
| 32 void LevelDBWrapperImpl::Delete(mojo::Array<uint8_t> key, | 36 void LevelDBWrapperImpl::Delete(mojo::Array<uint8_t> key, |
| 33 const mojo::String& source, | 37 const mojo::String& source, |
| 34 const DeleteCallback& callback) { | 38 const DeleteCallback& callback) { |
| 35 // TODO(jam): call observers before running callback. | 39 NOTIMPLEMENTED(); |
| 40 callback.Run(leveldb::DatabaseError::NOT_SUPPORTED); |
| 36 } | 41 } |
| 37 | 42 |
| 38 void LevelDBWrapperImpl::DeleteAll(LevelDBObserverPtr observer, | 43 void LevelDBWrapperImpl::DeleteAll(LevelDBObserverPtr observer, |
| 39 const mojo::String& source, | 44 const mojo::String& source, |
| 40 const DeleteAllCallback& callback) { | 45 const DeleteAllCallback& callback) { |
| 41 // TODO(jam): store observer and call it when changes occur. | 46 // TODO(jam): store observer and call it when changes occur. |
| 42 // TODO(jam): call observers before running callback. | 47 NOTIMPLEMENTED(); |
| 48 callback.Run(leveldb::DatabaseError::NOT_SUPPORTED); |
| 43 } | 49 } |
| 44 | 50 |
| 45 void LevelDBWrapperImpl::Get(mojo::Array<uint8_t> key, | 51 void LevelDBWrapperImpl::Get(mojo::Array<uint8_t> key, |
| 46 const GetCallback& callback) { | 52 const GetCallback& callback) { |
| 53 NOTIMPLEMENTED(); |
| 54 callback.Run(leveldb::DatabaseError::NOT_SUPPORTED, mojo::Array<uint8_t>()); |
| 47 } | 55 } |
| 48 | 56 |
| 49 void LevelDBWrapperImpl::GetAll(LevelDBObserverPtr observer, | 57 void LevelDBWrapperImpl::GetAll(LevelDBObserverPtr observer, |
| 50 const GetAllCallback& callback) { | 58 const GetAllCallback& callback) { |
| 51 // TODO(jam): store observer and call it when changes occur. | 59 // TODO(jam): store observer and call it when changes occur. |
| 60 NOTIMPLEMENTED(); |
| 61 callback.Run(leveldb::DatabaseError::NOT_SUPPORTED, |
| 62 mojo::Array<KeyValuePtr>()); |
| 52 } | 63 } |
| 53 | 64 |
| 54 void LevelDBWrapperImpl::OnConnectionError() { | 65 void LevelDBWrapperImpl::OnConnectionError() { |
| 55 if (!bindings_.empty()) | 66 if (!bindings_.empty()) |
| 56 return; | 67 return; |
| 57 | 68 |
| 58 no_bindings_callback_.Run(); | 69 no_bindings_callback_.Run(); |
| 59 } | 70 } |
| 60 | 71 |
| 61 } // namespace content | 72 } // namespace content |
| OLD | NEW |