Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: components/leveldb/leveldb_database_impl.cc

Issue 2285623002: [Leveldb] Use std::{string,vector} instead of mojo::{String,Array}. (Closed)
Patch Set: Address comments from Yuzhu Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/leveldb/leveldb_database_impl.h ('k') | components/leveldb/leveldb_service_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..82b1773e7c65b07c226d8870233bf82a69a4d7bf 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,15 +87,19 @@ void LevelDBDatabaseImpl::DeletePrefixed(
}
void LevelDBDatabaseImpl::Write(
- mojo::Array<mojom::BatchedOperationPtr> operations,
+ std::vector<mojom::BatchedOperationPtr> operations,
const WriteCallback& callback) {
leveldb::WriteBatch batch;
for (size_t i = 0; i < operations.size(); ++i) {
switch (operations[i]->type) {
case mojom::BatchOperationType::PUT_KEY: {
- batch.Put(GetSliceFor(operations[i]->key),
- GetSliceFor(operations[i]->value));
+ if (operations[i]->value) {
+ batch.Put(GetSliceFor(operations[i]->key),
+ GetSliceFor(*(operations[i]->value)));
+ } else {
+ batch.Put(GetSliceFor(operations[i]->key), leveldb::Slice());
+ }
break;
}
case mojom::BatchOperationType::DELETE_KEY: {
@@ -113,23 +117,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 +155,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 +169,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 +211,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 +226,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 +238,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 +256,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 +270,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 +284,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(
« no previous file with comments | « components/leveldb/leveldb_database_impl.h ('k') | components/leveldb/leveldb_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698