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

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

Issue 10829056: Add FileResource/FileList parser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for comments. Created 8 years, 5 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
Index: chrome/browser/chromeos/gdata/drive_api_parser.cc
diff --git a/chrome/browser/chromeos/gdata/drive_api_parser.cc b/chrome/browser/chromeos/gdata/drive_api_parser.cc
index 6f1cf75b5ddc09a5f59f69248aea2c3d4bca92bb..5d76d55b6b29b568e8ab34a92422a9e1060196ae 100644
--- a/chrome/browser/chromeos/gdata/drive_api_parser.cc
+++ b/chrome/browser/chromeos/gdata/drive_api_parser.cc
@@ -34,6 +34,9 @@ bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) {
// Common
const char kKind[] = "kind";
+const char kId[] = "id";
+const char kETag[] = "etag";
+const char kItems[] = "items";
// About Resource:
const char kAboutKind[] = "drive#about";
@@ -49,8 +52,6 @@ const char kIconUrl[] = "iconUrl";
// Apps Resource:
const char kAppKind[] = "drive#app";
-const char kId[] = "id";
-const char kETag[] = "etag";
const char kName[] = "name";
const char kObjectType[] = "objectType";
const char kSupportsCreate[] = "supportsCreate";
@@ -66,8 +67,23 @@ const char kIcons[] = "icons";
// Apps List:
const char kAppListKind[] = "drive#appList";
-const char kItems[] = "items";
+// File Resource:
+const char kFileKind[] = "drive#file";
+const char kMimeType[] = "mimeType";
+const char kTitle[] = "title";
+const char kModifiedByMeDate[] = "modifiedByMeDate";
+const char kDownloadUrl[] = "downloadUrl";
+const char kFileExtension[] = "fileExtension";
+const char kMd5Checksum[] = "md5Checksum";
+const char kFileSize[] = "fileSize";
+
+const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
+
+// Files List:
+const char kFileListKind[] = "drive#fileList";
+const char kNextPageToken[] = "nextPageToken";
+const char kNextLink[] = "nextLink";
// Maps category name to enum IconCategory.
struct AppIconCategoryMap {
@@ -279,4 +295,95 @@ bool AppList::Parse(const base::Value& value) {
return true;
}
+////////////////////////////////////////////////////////////////////////////////
+// FileResource implementation
+
+FileResource::FileResource() {}
+
+FileResource::~FileResource() {}
+
+// static
+void FileResource::RegisterJSONConverter(
+ base::JSONValueConverter<FileResource>* converter) {
+ converter->RegisterStringField(kId, &FileResource::id_);
+ converter->RegisterStringField(kETag, &FileResource::etag_);
+ converter->RegisterStringField(kMimeType, &FileResource::mime_type_);
+ converter->RegisterStringField(kTitle, &FileResource::title_);
+ converter->RegisterCustomField<base::Time>(
+ kModifiedByMeDate,
+ &FileResource::modified_by_me_date_,
+ &gdata::util::GetTimeFromString);
+ converter->RegisterCustomField<GURL>(kDownloadUrl,
+ &FileResource::download_url_,
+ GetGURLFromString);
+ converter->RegisterStringField(kFileExtension,
+ &FileResource::file_extension_);
+ converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_);
+ converter->RegisterCustomField<int64>(kFileSize,
+ &FileResource::file_size_,
+ &base::StringToInt64);
+}
+
+// static
+scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) {
+ scoped_ptr<FileResource> resource(new FileResource());
+ if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) {
+ LOG(ERROR) << "Unable to create: Invalid FileResource JSON!";
+ return scoped_ptr<FileResource>(NULL);
+ }
+ return resource.Pass();
+}
+
+bool FileResource::IsFolder() const {
+ return mime_type_ == kDriveFolderMimeType;
+}
+
+bool FileResource::Parse(const base::Value& value) {
+ base::JSONValueConverter<FileResource> converter;
+ if (!converter.Convert(value, this)) {
+ LOG(ERROR) << "Unable to parse: Invalid FileResource";
+ return false;
+ }
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// FileList implementation
+
+FileList::FileList() {}
+
+FileList::~FileList() {}
+
+// static
+void FileList::RegisterJSONConverter(
+ base::JSONValueConverter<FileList>* converter) {
+ converter->RegisterStringField(kETag, &FileList::etag_);
+ converter->RegisterStringField(kNextPageToken, &FileList::next_page_token_);
+ converter->RegisterCustomField<GURL>(kNextLink,
+ &FileList::next_link_,
+ GetGURLFromString);
+ converter->RegisterRepeatedMessage<FileResource>(kItems,
+ &FileList::items_);
+}
+
+// static
+scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) {
+ scoped_ptr<FileList> resource(new FileList());
+ if (!IsResourceKindExpected(value, kFileListKind) ||
+ !resource->Parse(value)) {
+ LOG(ERROR) << "Unable to create: Invalid FileList JSON!";
+ return scoped_ptr<FileList>(NULL);
+ }
+ return resource.Pass();
+}
+
+bool FileList::Parse(const base::Value& value) {
+ base::JSONValueConverter<FileList> converter;
+ if (!converter.Convert(value, this)) {
+ LOG(ERROR) << "Unable to parse: Invalid FileList";
+ return false;
+ }
+ return true;
+}
+
} // namespace gdata

Powered by Google App Engine
This is Rietveld 408576698