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

Unified Diff: chrome/browser/chromeos/gdata/gdata_files.cc

Issue 10210012: GDataDB support with leveldb. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: shorten prefixes Created 8 years, 8 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 | « chrome/browser/chromeos/gdata/gdata_files.h ('k') | chrome/browser/chromeos/gdata/gdata_leveldb.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/gdata/gdata_files.cc
===================================================================
--- chrome/browser/chromeos/gdata/gdata_files.cc (revision 133819)
+++ chrome/browser/chromeos/gdata/gdata_files.cc (working copy)
@@ -78,10 +78,20 @@
return NULL;
}
-FilePath GDataEntry::GetFilePath() {
+const GDataFile* GDataEntry::AsGDataFileConst() const {
+ // cast away const and call the non-const version. This is safe.
+ return const_cast<GDataEntry*>(this)->AsGDataFile();
+}
+
+const GDataDirectory* GDataEntry::AsGDataDirectoryConst() const {
+ // cast away const and call the non-const version. This is safe.
+ return const_cast<GDataEntry*>(this)->AsGDataDirectory();
+}
+
+FilePath GDataEntry::GetFilePath() const {
FilePath path;
std::vector<FilePath::StringType> parts;
- for (GDataEntry* entry = this; entry != NULL; entry = entry->parent())
+ for (const GDataEntry* entry = this; entry != NULL; entry = entry->parent_)
parts.push_back(entry->file_name());
// Paste paths parts back together in reverse order from upward tree
@@ -133,6 +143,7 @@
: GDataEntry(parent, root),
kind_(gdata::DocumentEntry::UNKNOWN),
is_hosted_document_(false) {
+ file_info_.is_directory = false;
}
GDataFile::~GDataFile() {
@@ -581,6 +592,7 @@
}
void GDataFile::FromProto(const GDataFileProto& proto) {
+ DCHECK(!proto.gdata_entry().file_info().is_directory());
GDataEntry::FromProto(proto.gdata_entry());
kind_ = DocumentEntry::EntryKind(proto.kind());
thumbnail_url_ = GURL(proto.thumbnail_url());
@@ -595,6 +607,7 @@
void GDataFile::ToProto(GDataFileProto* proto) const {
GDataEntry::ToProto(proto->mutable_gdata_entry());
+ DCHECK(!proto->gdata_entry().file_info().is_directory());
proto->set_kind(kind_);
proto->set_thumbnail_url(thumbnail_url_.spec());
proto->set_alternate_url(alternate_url_.spec());
@@ -607,6 +620,7 @@
}
void GDataDirectory::FromProto(const GDataDirectoryProto& proto) {
+ DCHECK(proto.gdata_entry().file_info().is_directory());
GDataEntry::FromProto(proto.gdata_entry());
refresh_time_ = base::Time::FromInternalValue(proto.refresh_time());
start_feed_url_ = GURL(proto.start_feed_url());
@@ -627,6 +641,7 @@
void GDataDirectory::ToProto(GDataDirectoryProto* proto) const {
GDataEntry::ToProto(proto->mutable_gdata_entry());
+ DCHECK(proto->gdata_entry().file_info().is_directory());
proto->set_refresh_time(refresh_time_.ToInternalValue());
proto->set_start_feed_url(start_feed_url_.spec());
proto->set_next_feed_url(next_feed_url_.spec());
@@ -654,18 +669,61 @@
proto->set_largest_changestamp(largest_changestamp_);
}
-void GDataRootDirectory::SerializeToString(std::string* proto_string) const {
+void GDataEntry::SerializeToString(std::string* serialized_proto) const {
+ const GDataFile* file = AsGDataFileConst();
+ const GDataDirectory* dir = AsGDataDirectoryConst();
+
+ if (file) {
+ scoped_ptr<GDataFileProto> proto(new GDataFileProto());
+ file->ToProto(proto.get());
+ const bool ok = proto->SerializeToString(serialized_proto);
+ DCHECK(ok);
+ } else if (dir) {
+ scoped_ptr<GDataDirectoryProto> proto(new GDataDirectoryProto());
+ dir->ToProto(proto.get());
+ const bool ok = proto->SerializeToString(serialized_proto);
+ DCHECK(ok);
+ }
+}
+
+// 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 GDataFileProto - we have to check
+ // is_directory to be sure.
+ scoped_ptr<GDataDirectoryProto> dir_proto(new GDataDirectoryProto());
+ bool ok = dir_proto->ParseFromString(serialized_proto);
+ if (ok && dir_proto->gdata_entry().file_info().is_directory()) {
+ GDataDirectory* dir = new GDataDirectory(NULL, NULL);
+ dir->FromProto(*dir_proto);
+ return scoped_ptr<GDataEntry>(dir);
+ }
+
+ scoped_ptr<GDataFileProto> file_proto(new GDataFileProto());
+ ok = file_proto->ParseFromString(serialized_proto);
+ if (ok) {
+ DCHECK(!file_proto->gdata_entry().file_info().is_directory());
+ GDataFile* file = new GDataFile(NULL, NULL);
+ file->FromProto(*file_proto);
+ return scoped_ptr<GDataEntry>(file);
+ }
+ return scoped_ptr<GDataEntry>(NULL);
+}
+
+void GDataRootDirectory::SerializeToString(
+ std::string* serialized_proto) const {
scoped_ptr<GDataRootDirectoryProto> proto(
new GDataRootDirectoryProto());
ToProto(proto.get());
- const bool ok = proto->SerializeToString(proto_string);
+ const bool ok = proto->SerializeToString(serialized_proto);
DCHECK(ok);
}
-bool GDataRootDirectory::ParseFromString(const std::string& proto_string) {
+bool GDataRootDirectory::ParseFromString(const std::string& serialized_proto) {
scoped_ptr<GDataRootDirectoryProto> proto(
new GDataRootDirectoryProto());
- bool ok = proto->ParseFromString(proto_string);
+ bool ok = proto->ParseFromString(serialized_proto);
if (ok) {
FromProto(*proto.get());
set_origin(FROM_CACHE);
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_files.h ('k') | chrome/browser/chromeos/gdata/gdata_leveldb.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698