Chromium Code Reviews| Index: components/leveldb/leveldb_database_impl.cc |
| diff --git a/components/leveldb/leveldb_database_impl.cc b/components/leveldb/leveldb_database_impl.cc |
| index f5d618cc1903cf22b7a89f7c356e473ba422f862..d5bee985b24ce7780f3182e93dee531a06052494 100644 |
| --- a/components/leveldb/leveldb_database_impl.cc |
| +++ b/components/leveldb/leveldb_database_impl.cc |
| @@ -7,10 +7,10 @@ |
| #include <map> |
| #include <string> |
| +#include "base/optional.h" |
| #include "base/rand_util.h" |
| #include "components/leveldb/env_mojo.h" |
| #include "components/leveldb/public/cpp/util.h" |
| -#include "mojo/common/common_type_converters.h" |
| #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" |
| @@ -60,15 +60,15 @@ LevelDBDatabaseImpl::~LevelDBDatabaseImpl() { |
| db_->ReleaseSnapshot(p.second); |
| } |
| -void LevelDBDatabaseImpl::Put(mojo::Array<uint8_t> key, |
| - mojo::Array<uint8_t> value, |
| +void LevelDBDatabaseImpl::Put(const std::vector<uint8_t>& key, |
| + const std::vector<uint8_t>& value, |
| const PutCallback& callback) { |
| leveldb::Status status = |
| db_->Put(leveldb::WriteOptions(), GetSliceFor(key), GetSliceFor(value)); |
| callback.Run(LeveldbStatusToError(status)); |
| } |
| -void LevelDBDatabaseImpl::Delete(mojo::Array<uint8_t> key, |
| +void LevelDBDatabaseImpl::Delete(const std::vector<uint8_t>& key, |
| const DeleteCallback& callback) { |
| leveldb::Status status = |
| db_->Delete(leveldb::WriteOptions(), GetSliceFor(key)); |
| @@ -76,7 +76,7 @@ void LevelDBDatabaseImpl::Delete(mojo::Array<uint8_t> key, |
| } |
| void LevelDBDatabaseImpl::DeletePrefixed( |
| - mojo::Array<uint8_t> key_prefix, |
| + const std::vector<uint8_t>& key_prefix, |
| const DeletePrefixedCallback& callback) { |
| leveldb::WriteBatch batch; |
| leveldb::Status status = DeletePrefixedHelper( |
| @@ -87,7 +87,7 @@ void LevelDBDatabaseImpl::DeletePrefixed( |
| } |
| void LevelDBDatabaseImpl::Write( |
| - mojo::Array<mojom::BatchedOperationPtr> operations, |
| + std::vector<mojom::BatchedOperationPtr> operations, |
| const WriteCallback& callback) { |
| leveldb::WriteBatch batch; |
| @@ -95,7 +95,7 @@ void LevelDBDatabaseImpl::Write( |
| switch (operations[i]->type) { |
| case mojom::BatchOperationType::PUT_KEY: { |
| batch.Put(GetSliceFor(operations[i]->key), |
| - GetSliceFor(operations[i]->value)); |
| + GetSliceFor(*(operations[i]->value))); |
|
yzshen1
2016/08/26 16:58:40
A malicious sender may send you a null value. And
leonhsl(Using Gerrit)
2016/08/29 06:36:17
Yeah, it is true. Done and thanks. Also confirmed
|
| break; |
| } |
| case mojom::BatchOperationType::DELETE_KEY: { |
| @@ -113,23 +113,23 @@ void LevelDBDatabaseImpl::Write( |
| callback.Run(LeveldbStatusToError(status)); |
| } |
| -void LevelDBDatabaseImpl::Get(mojo::Array<uint8_t> key, |
| +void LevelDBDatabaseImpl::Get(const std::vector<uint8_t>& key, |
| const GetCallback& callback) { |
| std::string value; |
| leveldb::Status status = |
| db_->Get(leveldb::ReadOptions(), GetSliceFor(key), &value); |
| - callback.Run(LeveldbStatusToError(status), mojo::Array<uint8_t>::From(value)); |
| + callback.Run(LeveldbStatusToError(status), StdStringToUint8Vector(value)); |
| } |
| -void LevelDBDatabaseImpl::GetPrefixed(mojo::Array<uint8_t> key_prefix, |
| +void LevelDBDatabaseImpl::GetPrefixed(const std::vector<uint8_t>& key_prefix, |
| const GetPrefixedCallback& callback) { |
| - mojo::Array<mojom::KeyValuePtr> data; |
| + std::vector<mojom::KeyValuePtr> data; |
| leveldb::Status status = ForEachWithPrefix( |
| db_.get(), GetSliceFor(key_prefix), |
| [&data](const leveldb::Slice& key, const leveldb::Slice& value) { |
| mojom::KeyValuePtr kv = mojom::KeyValue::New(); |
| - kv->key = GetArrayFor(key); |
| - kv->value = GetArrayFor(value); |
| + kv->key = GetVectorFor(key); |
| + kv->value = GetVectorFor(value); |
| data.push_back(std::move(kv)); |
| }); |
| callback.Run(LeveldbStatusToError(status), std::move(data)); |
| @@ -151,13 +151,13 @@ void LevelDBDatabaseImpl::ReleaseSnapshot(uint64_t snapshot_id) { |
| } |
| void LevelDBDatabaseImpl::GetFromSnapshot(uint64_t snapshot_id, |
| - mojo::Array<uint8_t> key, |
| + const std::vector<uint8_t>& key, |
| const GetCallback& callback) { |
| // If the snapshot id is invalid, send back invalid argument |
| auto it = snapshot_map_.find(snapshot_id); |
| if (it == snapshot_map_.end()) { |
| callback.Run(mojom::DatabaseError::INVALID_ARGUMENT, |
| - mojo::Array<uint8_t>()); |
| + std::vector<uint8_t>()); |
| return; |
| } |
| @@ -165,7 +165,7 @@ void LevelDBDatabaseImpl::GetFromSnapshot(uint64_t snapshot_id, |
| leveldb::ReadOptions options; |
| options.snapshot = it->second; |
| leveldb::Status status = db_->Get(options, GetSliceFor(key), &value); |
| - callback.Run(LeveldbStatusToError(status), mojo::Array<uint8_t>::From(value)); |
| + callback.Run(LeveldbStatusToError(status), StdStringToUint8Vector(value)); |
| } |
| void LevelDBDatabaseImpl::NewIterator(const NewIteratorCallback& callback) { |
| @@ -207,8 +207,8 @@ void LevelDBDatabaseImpl::IteratorSeekToFirst( |
| const IteratorSeekToFirstCallback& callback) { |
| auto it = iterator_map_.find(iterator_id); |
| if (it == iterator_map_.end()) { |
| - callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, nullptr, |
| - nullptr); |
| + callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| @@ -222,8 +222,8 @@ void LevelDBDatabaseImpl::IteratorSeekToLast( |
| const IteratorSeekToLastCallback& callback) { |
| auto it = iterator_map_.find(iterator_id); |
| if (it == iterator_map_.end()) { |
| - callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, nullptr, |
| - nullptr); |
| + callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| @@ -234,12 +234,12 @@ void LevelDBDatabaseImpl::IteratorSeekToLast( |
| void LevelDBDatabaseImpl::IteratorSeek( |
| uint64_t iterator_id, |
| - mojo::Array<uint8_t> target, |
| + const std::vector<uint8_t>& target, |
| const IteratorSeekToLastCallback& callback) { |
| auto it = iterator_map_.find(iterator_id); |
| if (it == iterator_map_.end()) { |
| - callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, nullptr, |
| - nullptr); |
| + callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| @@ -252,8 +252,8 @@ void LevelDBDatabaseImpl::IteratorNext(uint64_t iterator_id, |
| const IteratorNextCallback& callback) { |
| auto it = iterator_map_.find(iterator_id); |
| if (it == iterator_map_.end()) { |
| - callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, nullptr, |
| - nullptr); |
| + callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| @@ -266,8 +266,8 @@ void LevelDBDatabaseImpl::IteratorPrev(uint64_t iterator_id, |
| const IteratorPrevCallback& callback) { |
| auto it = iterator_map_.find(iterator_id); |
| if (it == iterator_map_.end()) { |
| - callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, nullptr, |
| - nullptr); |
| + callback.Run(false, mojom::DatabaseError::INVALID_ARGUMENT, base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| @@ -280,12 +280,13 @@ void LevelDBDatabaseImpl::ReplyToIteratorMessage( |
| leveldb::Iterator* it, |
| const IteratorSeekToFirstCallback& callback) { |
| if (!it->Valid()) { |
| - callback.Run(false, LeveldbStatusToError(it->status()), nullptr, nullptr); |
| + callback.Run(false, LeveldbStatusToError(it->status()), base::nullopt, |
| + base::nullopt); |
| return; |
| } |
| - callback.Run(true, LeveldbStatusToError(it->status()), GetArrayFor(it->key()), |
| - GetArrayFor(it->value())); |
| + callback.Run(true, LeveldbStatusToError(it->status()), |
| + GetVectorFor(it->key()), GetVectorFor(it->value())); |
| } |
| leveldb::Status LevelDBDatabaseImpl::DeletePrefixedHelper( |