Commit e6281bba authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Remove obsolete GDataDB related code

Turned out the original design was not good, and the code won't be used.

BUG=140314
TEST=compile
TBR=ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10828163

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149955 0039d316-1c4b-4281-b951-d872f2087c98
parent 4967673d
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_H_
#include <string>
#include "base/memory/scoped_ptr.h"
class FilePath;
namespace gdata {
class GDataEntry;
class GDataDBIter;
// GData Database interface class.
class GDataDB {
public:
enum Status {
DB_OK = 0,
DB_KEY_NOT_FOUND, // Key not found.
DB_CORRUPTION, // Database file corrupt.
DB_IO_ERROR, // File I/O error.
DB_INTERNAL_ERROR,
};
virtual ~GDataDB() {}
// Puts |entry| to the database.
virtual Status Put(const GDataEntry& entry) = 0;
// Deletes a database entry with key |resource_id| or |path| respectively.
virtual Status DeleteByResourceId(const std::string& resource_id) = 0;
virtual Status DeleteByPath(const FilePath& path) = 0;
// Fetches a GDataEntry* by key |resource_id| or |path| respectively.
virtual Status GetByResourceId(const std::string& resource_id,
scoped_ptr<GDataEntry>* entry) = 0;
virtual Status GetByPath(const FilePath& path,
scoped_ptr<GDataEntry>* entry) = 0;
// Creates an iterator to fetch all GDataEntry's under |path|.
// Will not return NULL.
virtual scoped_ptr<GDataDBIter> CreateIterator(const FilePath& path) = 0;
// Puts |raw_value| keyed with |resource_id| to the database.
// Used for testing (ex. injecting incompatible proto).
virtual Status PutRawForTesting(const std::string& resource_id,
const std::string& raw_value) = 0;
protected:
GDataDB() {}
};
// GData Database Iterator interface class.
class GDataDBIter {
public:
virtual ~GDataDBIter() {}
// Fetches the next |entry| in the iteration sequence. Returns false when
// there are no more entries.
virtual bool GetNext(std::string* path, scoped_ptr<GDataEntry>* entry) = 0;
protected:
GDataDBIter() {}
};
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/gdata/gdata_db_factory.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/gdata/gdata_leveldb.h"
namespace gdata {
namespace db_factory {
scoped_ptr<GDataDB> CreateGDataDB(const FilePath& db_path) {
DVLOG(1) << "CreateGDataDB " << db_path.value();
GDataLevelDB* level_db = new GDataLevelDB();
level_db->Init(db_path);
return scoped_ptr<GDataDB>(level_db);
}
} // namespace db_factory
} // namespace gdata
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_FACTORY_H_
#include "base/memory/scoped_ptr.h"
class FilePath;
namespace gdata {
class GDataDB;
namespace db_factory {
// Factory method to create an instance of GDataDB.
scoped_ptr<GDataDB> CreateGDataDB(const FilePath& db_path);
} // namespace db_factory
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_FACTORY_H_
This diff is collapsed.
...@@ -733,33 +733,6 @@ void GDataEntry::SerializeToString(std::string* serialized_proto) const { ...@@ -733,33 +733,6 @@ void GDataEntry::SerializeToString(std::string* serialized_proto) const {
} }
} }
// static
scoped_ptr<GDataEntry> GDataEntry::FromProtoString(
const std::string& serialized_proto) {
// First try to parse as GDataDirectoryProto. Note that this can succeed for
// a serialized_proto that's really a GDataEntryProto - we have to check
// is_directory to be sure.
GDataDirectoryProto dir_proto;
bool ok = dir_proto.ParseFromString(serialized_proto);
if (ok && dir_proto.gdata_entry().file_info().is_directory()) {
scoped_ptr<GDataDirectory> dir(new GDataDirectory(NULL, NULL));
if (!dir->FromProto(dir_proto))
return scoped_ptr<GDataEntry>(NULL);
return scoped_ptr<GDataEntry>(dir.release());
}
GDataEntryProto entry_proto;
ok = entry_proto.ParseFromString(serialized_proto);
if (ok) {
DCHECK(!entry_proto.file_info().is_directory());
scoped_ptr<GDataFile> file(new GDataFile(NULL, NULL));
if (!file->FromProto(entry_proto))
return scoped_ptr<GDataEntry>(NULL);
return scoped_ptr<GDataEntry>(file.release());
}
return scoped_ptr<GDataEntry>(NULL);
}
void GDataDirectoryService::SerializeToString( void GDataDirectoryService::SerializeToString(
std::string* serialized_proto) const { std::string* serialized_proto) const {
GDataRootDirectoryProto proto; GDataRootDirectoryProto proto;
......
...@@ -89,11 +89,7 @@ class GDataEntry { ...@@ -89,11 +89,7 @@ class GDataEntry {
GDataDirectoryService* directory_service); GDataDirectoryService* directory_service);
// Serialize/Parse to/from string via proto classes. // Serialize/Parse to/from string via proto classes.
// TODO(achuith): Correctly set up parent_ and root_ links in
// FromProtoString.
void SerializeToString(std::string* serialized_proto) const; void SerializeToString(std::string* serialized_proto) const;
static scoped_ptr<GDataEntry> FromProtoString(
const std::string& serialized_proto);
// Converts the proto representation to the platform file. // Converts the proto representation to the platform file.
static void ConvertProtoToPlatformFileInfo( static void ConvertProtoToPlatformFileInfo(
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/gdata/gdata_leveldb.h"
#include <string>
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/chromeos/gdata/gdata_files.h"
#include "leveldb/write_batch.h"
namespace gdata {
namespace {
const char kResourceIdPrefix[] = "r:";
const char kPathPrefix[] = "p:";
// Append prefix id: to |resource_id|.
std::string ResourceIdToKey(const std::string& resource_id) {
return std::string(kResourceIdPrefix) + resource_id;
}
// Append prefix path: to |path|.
std::string PathToKey(const FilePath& path) {
return std::string(kPathPrefix) + path.value();
}
GDataDB::Status GetStatus(const leveldb::Status& db_status) {
if (db_status.ok())
return GDataDB::DB_OK;
if (db_status.IsNotFound())
return GDataDB::DB_KEY_NOT_FOUND;
if (db_status.IsCorruption())
return GDataDB::DB_CORRUPTION;
if (db_status.IsIOError())
return GDataDB::DB_IO_ERROR;
NOTREACHED();
return GDataDB::DB_INTERNAL_ERROR;
}
} // namespace
GDataLevelDB::GDataLevelDB() {
}
GDataLevelDB::~GDataLevelDB() {
}
void GDataLevelDB::Init(const FilePath& db_path) {
base::ThreadRestrictions::AssertIOAllowed();
leveldb::DB* level_db = NULL;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status db_status = leveldb::DB::Open(options,
db_path.Append("level_db").value(), &level_db);
DCHECK(level_db);
// TODO(achuith): If db cannot be opened, we should try to recover it.
// If that fails, we should just delete it and create a new file.
DCHECK(db_status.ok());
level_db_.reset(level_db);
}
GDataDB::Status GDataLevelDB::Put(const GDataEntry& entry) {
base::ThreadRestrictions::AssertIOAllowed();
// Write the serialized proto.
std::string serialized_proto;
entry.SerializeToString(&serialized_proto);
leveldb::WriteBatch batch;
const std::string resource_id_key =
ResourceIdToKey(entry.resource_id());
const std::string path_key = PathToKey(entry.GetFilePath());
batch.Put(leveldb::Slice(resource_id_key), leveldb::Slice(serialized_proto));
// Note we store the resource_id without prefix when it's the value.
batch.Put(leveldb::Slice(path_key), leveldb::Slice(entry.resource_id()));
leveldb::Status db_status = level_db_->Write(
leveldb::WriteOptions(),
&batch);
DVLOG(1) << "GDataLevelDB::Put resource_id key = " << resource_id_key
<< ", path key = " << path_key;
return GetStatus(db_status);
}
GDataDB::Status GDataLevelDB::DeleteByResourceId(
const std::string& resource_id) {
base::ThreadRestrictions::AssertIOAllowed();
scoped_ptr<GDataEntry> entry;
Status status = GetByResourceId(resource_id, &entry);
if (status == DB_KEY_NOT_FOUND)
return DB_OK;
else if (status != DB_OK)
return status;
leveldb::WriteBatch batch;
const std::string resource_id_key = ResourceIdToKey(resource_id);
const std::string path_key = PathToKey(entry->GetFilePath());
batch.Delete(leveldb::Slice(resource_id_key));
batch.Delete(leveldb::Slice(path_key));
leveldb::Status db_status = level_db_->Write(leveldb::WriteOptions(),
&batch);
return GetStatus(db_status);
}
GDataDB::Status GDataLevelDB::DeleteByPath(
const FilePath& path) {
base::ThreadRestrictions::AssertIOAllowed();
std::string resource_id;
const Status status = ResourceIdForPath(path, &resource_id);
if (status != DB_OK)
return status;
return DeleteByResourceId(resource_id);
}
GDataDB::Status GDataLevelDB::GetByResourceId(const std::string& resource_id,
scoped_ptr<GDataEntry>* entry) {
base::ThreadRestrictions::AssertIOAllowed();
entry->reset();
std::string serialized_proto;
const std::string resource_id_key = ResourceIdToKey(resource_id);
const leveldb::Status db_status = level_db_->Get(leveldb::ReadOptions(),
leveldb::Slice(resource_id_key), &serialized_proto);
if (db_status.IsNotFound())
return DB_KEY_NOT_FOUND;
if (db_status.ok()) {
DCHECK(!serialized_proto.empty());
*entry = GDataEntry::FromProtoString(serialized_proto);
return entry->get() ? DB_OK : DB_CORRUPTION;
}
return GetStatus(db_status);
}
GDataDB::Status GDataLevelDB::GetByPath(const FilePath& path,
scoped_ptr<GDataEntry>* entry) {
base::ThreadRestrictions::AssertIOAllowed();
entry->reset();
std::string resource_id;
const Status status = ResourceIdForPath(path, &resource_id);
if (status != DB_OK)
return status;
return GetByResourceId(resource_id, entry);
}
GDataDB::Status GDataLevelDB::ResourceIdForPath(const FilePath& path,
std::string* resource_id) {
base::ThreadRestrictions::AssertIOAllowed();
const std::string path_key = PathToKey(path);
const leveldb::Status db_status = level_db_->Get(
leveldb::ReadOptions(), path_key, resource_id);
return GetStatus(db_status);
}
scoped_ptr<GDataDBIter> GDataLevelDB::CreateIterator(const FilePath& path) {
return scoped_ptr<GDataDBIter>(new GDataLevelDBIter(
scoped_ptr<leveldb::Iterator>(
level_db_->NewIterator(leveldb::ReadOptions())),
this,
path));
}
GDataDB::Status GDataLevelDB::PutRawForTesting(
const std::string& resource_id,
const std::string& raw_value) {
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(raw_value));
return GetStatus(db_status);
}
GDataLevelDBIter::GDataLevelDBIter(scoped_ptr<leveldb::Iterator> level_db_iter,
GDataDB* db,
const FilePath& path)
: level_db_iter_(level_db_iter.Pass()),
db_(db),
path_(path) {
base::ThreadRestrictions::AssertIOAllowed();
const std::string path_key = PathToKey(path);
level_db_iter_->Seek(leveldb::Slice(path_key));
}
GDataLevelDBIter::~GDataLevelDBIter() {
}
bool GDataLevelDBIter::GetNext(std::string* path,
scoped_ptr<GDataEntry>* entry) {
base::ThreadRestrictions::AssertIOAllowed();
DCHECK(path);
DCHECK(entry);
path->clear();
entry->reset();
if (!level_db_iter_->Valid())
return false;
// Only consider keys under |path|.
const std::string path_key = PathToKey(path_);
leveldb::Slice key_slice(level_db_iter_->key());
if (!key_slice.starts_with(path_key))
return false;
GDataDB::Status status =
db_->GetByResourceId(level_db_iter_->value().ToString(), entry);
if (status != GDataDB::DB_OK)
return false;
key_slice.remove_prefix(sizeof(kPathPrefix) - 1);
path->assign(key_slice.ToString());
level_db_iter_->Next();
return true;
}
} // namespace gdata
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_LEVELDB_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_LEVELDB_H_
#include <leveldb/db.h>
#include <string>
#include "base/file_path.h"
#include "chrome/browser/chromeos/gdata/gdata_db.h"
namespace gdata {
class GDataLevelDB : public GDataDB {
public:
GDataLevelDB();
void Init(const FilePath& db_path);
private:
virtual ~GDataLevelDB();
// GDataDB implementation.
virtual Status Put(const GDataEntry& file) OVERRIDE;
virtual Status DeleteByResourceId(const std::string& resource_id) OVERRIDE;
virtual Status DeleteByPath(const FilePath& path) OVERRIDE;
virtual Status GetByResourceId(const std::string& resource_id,
scoped_ptr<GDataEntry>* file) OVERRIDE;
virtual Status GetByPath(const FilePath& path,
scoped_ptr<GDataEntry>* file) OVERRIDE;
virtual scoped_ptr<GDataDBIter> CreateIterator(const FilePath& path) OVERRIDE;
virtual Status PutRawForTesting(const std::string& resource_id,
const std::string& raw_value) OVERRIDE;
// Returns |resource_id| for |path| by looking up path_db_.
Status ResourceIdForPath(const FilePath& path, std::string* resource_id);
scoped_ptr<leveldb::DB> level_db_;
};
class GDataLevelDBIter : public GDataDBIter {
public:
GDataLevelDBIter(scoped_ptr<leveldb::Iterator> level_db_iter,
GDataDB* db, const FilePath& path);
private:
virtual ~GDataLevelDBIter();
// GDataDBIter implementation.
virtual bool GetNext(std::string* path,
scoped_ptr<GDataEntry>* entry) OVERRIDE;
scoped_ptr<leveldb::Iterator> level_db_iter_;
GDataDB* db_;
const FilePath path_;
};
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_LEVELDB_H_
...@@ -558,9 +558,6 @@ ...@@ -558,9 +558,6 @@
'browser/chromeos/gdata/gdata_cache_metadata.h', 'browser/chromeos/gdata/gdata_cache_metadata.h',
'browser/chromeos/gdata/gdata_contacts_service.cc', 'browser/chromeos/gdata/gdata_contacts_service.cc',
'browser/chromeos/gdata/gdata_contacts_service.h', 'browser/chromeos/gdata/gdata_contacts_service.h',
'browser/chromeos/gdata/gdata_db.h',
'browser/chromeos/gdata/gdata_db_factory.cc',
'browser/chromeos/gdata/gdata_db_factory.h',
'browser/chromeos/gdata/gdata_documents_service.cc', 'browser/chromeos/gdata/gdata_documents_service.cc',
'browser/chromeos/gdata/gdata_documents_service.h', 'browser/chromeos/gdata/gdata_documents_service.h',
'browser/chromeos/gdata/gdata_download_observer.cc', 'browser/chromeos/gdata/gdata_download_observer.cc',
...@@ -573,8 +570,6 @@ ...@@ -573,8 +570,6 @@
'browser/chromeos/gdata/gdata_file_system_proxy.h', 'browser/chromeos/gdata/gdata_file_system_proxy.h',
'browser/chromeos/gdata/gdata_files.cc', 'browser/chromeos/gdata/gdata_files.cc',
'browser/chromeos/gdata/gdata_files.h', 'browser/chromeos/gdata/gdata_files.h',
'browser/chromeos/gdata/gdata_leveldb.cc',
'browser/chromeos/gdata/gdata_leveldb.h',
'browser/chromeos/gdata/gdata_operation_registry.cc', 'browser/chromeos/gdata/gdata_operation_registry.cc',
'browser/chromeos/gdata/gdata_operation_registry.h', 'browser/chromeos/gdata/gdata_operation_registry.h',
'browser/chromeos/gdata/gdata_operation_runner.cc', 'browser/chromeos/gdata/gdata_operation_runner.cc',
......
...@@ -1110,7 +1110,6 @@ ...@@ -1110,7 +1110,6 @@
'browser/chromeos/gdata/gdata_cache_unittest.cc', 'browser/chromeos/gdata/gdata_cache_unittest.cc',
'browser/chromeos/gdata/gdata_contacts_service_stub.cc', 'browser/chromeos/gdata/gdata_contacts_service_stub.cc',
'browser/chromeos/gdata/gdata_contacts_service_stub.h', 'browser/chromeos/gdata/gdata_contacts_service_stub.h',
'browser/chromeos/gdata/gdata_db_unittest.cc',
'browser/chromeos/gdata/gdata_file_system_unittest.cc', 'browser/chromeos/gdata/gdata_file_system_unittest.cc',
'browser/chromeos/gdata/gdata_files_unittest.cc', 'browser/chromeos/gdata/gdata_files_unittest.cc',
'browser/chromeos/gdata/gdata_operation_registry_unittest.cc', 'browser/chromeos/gdata/gdata_operation_registry_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment