Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_leveldb.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_leveldb.cc b/chrome/browser/chromeos/gdata/gdata_leveldb.cc |
| index 8ea19c67722c2dff7d3c0407ac35b6dd3a411a6a..74a88b0d825dafef0220d79ba4c3377f0e2d3cae 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_leveldb.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_leveldb.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/threading/thread_restrictions.h" |
| #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| #include "leveldb/write_batch.h" |
| +#include "third_party/protobuf/src/google/protobuf/message_lite.h" |
| namespace gdata { |
| namespace { |
| @@ -139,7 +140,8 @@ GDataDB::Status GDataLevelDB::GetByResourceId(const std::string& resource_id, |
| if (db_status.ok()) { |
| DCHECK(!serialized_proto.empty()); |
| *entry = GDataEntry::FromProtoString(serialized_proto); |
| - DCHECK(entry->get()); |
| + if (!entry->get()) |
|
achuithb
2012/07/10 17:21:19
nit: can we make this a ternary return? It saves 2
satorux1
2012/07/10 17:28:35
Done.
|
| + return DB_CORRUPTION; |
| return DB_OK; |
| } |
| return GetStatus(db_status); |
| @@ -176,6 +178,22 @@ scoped_ptr<GDataDBIter> GDataLevelDB::CreateIterator(const FilePath& path) { |
| path)); |
| } |
| +GDataDB::Status GDataLevelDB::PutRawForTesting( |
| + const std::string& resource_id, |
| + const google::protobuf::MessageLite& protobuf) { |
| + std::string serialized_proto; |
| + protobuf.SerializeToString(&serialized_proto); |
| + |
| + const std::string resource_id_key = |
| + ResourceIdToKey(resource_id); |
| + leveldb::Status db_status = level_db_->Put( |
| + leveldb::WriteOptions(), |
| + leveldb::Slice(resource_id_key), |
| + leveldb::Slice(serialized_proto)); |
| + |
| + return GetStatus(db_status); |
| +} |
| + |
| GDataLevelDBIter::GDataLevelDBIter(scoped_ptr<leveldb::Iterator> level_db_iter, |
| GDataDB* db, |
| const FilePath& path) |
| @@ -211,7 +229,8 @@ bool GDataLevelDBIter::GetNext(std::string* path, |
| GDataDB::Status status = |
| db_->GetByResourceId(level_db_iter_->value().ToString(), entry); |
| - DCHECK_EQ(GDataDB::DB_OK, status); |
| + if (status != GDataDB::DB_OK) |
| + return false; |
| key_slice.remove_prefix(sizeof(kPathPrefix) - 1); |
| path->assign(key_slice.ToString()); |