Commit 901fe63a authored by kochi@chromium.org's avatar kochi@chromium.org

Add missing fields in Drive V2 API parser.

These added fields are necessary to work with our file system
implementation.

BUG=chromium:127728
TEST=unit_tests --gtest_filter="DriveAPI*"

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150291 0039d316-1c4b-4281-b951-d872f2087c98
parent 23db99e0
......@@ -32,25 +32,32 @@ bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) {
// Drive v2 API JSON names.
// Definition order follows the order of documentation in
// https://developers.google.com/drive/v2/reference/
// Common
const char kKind[] = "kind";
const char kId[] = "id";
const char kETag[] = "etag";
const char kSelfLink[] = "selfLink";
const char kItems[] = "items";
const char kLargestChangeId[] = "largestChangeId";
// About Resource:
// About Resource
// https://developers.google.com/drive/v2/reference/about
const char kAboutKind[] = "drive#about";
const char kRootFolderId[] = "rootFolderId";
const char kQuotaBytesTotal[] = "quotaBytesTotal";
const char kQuotaBytesUsed[] = "quotaBytesUsed";
const char kRootFolderId[] = "rootFolderId";
// App Icon:
// App Icon
// https://developers.google.com/drive/v2/reference/apps
const char kCategory[] = "category";
const char kSize[] = "size";
const char kIconUrl[] = "iconUrl";
// Apps Resource:
// Apps Resource
// https://developers.google.com/drive/v2/reference/apps
const char kAppKind[] = "drive#app";
const char kName[] = "name";
const char kObjectType[] = "objectType";
......@@ -65,37 +72,50 @@ const char kPrimaryFileExtensions[] = "primaryFileExtensions";
const char kSecondaryFileExtensions[] = "secondaryFileExtensions";
const char kIcons[] = "icons";
// Apps List:
// Apps List
// https://developers.google.com/drive/v2/reference/apps/list
const char kAppListKind[] = "drive#appList";
// Parent Resource:
// Parent Resource
// https://developers.google.com/drive/v2/reference/parents
const char kParentReferenceKind[] = "drive#parentReference";
const char kParentLink[] = "parentLink";
const char kIsRoot[] = "isRoot";
// File Resource:
// File Resource
// https://developers.google.com/drive/v2/reference/files
const char kFileKind[] = "drive#file";
const char kMimeType[] = "mimeType";
const char kTitle[] = "title";
const char kMimeType[] = "mimeType";
const char kCreatedDate[] = "createdDate";
const char kModifiedByMeDate[] = "modifiedByMeDate";
const char kParents[] = "parents";
const char kDownloadUrl[] = "downloadUrl";
const char kFileExtension[] = "fileExtension";
const char kMd5Checksum[] = "md5Checksum";
const char kFileSize[] = "fileSize";
const char kAlternateLink[] = "alternateLink";
const char kEmbedLink[] = "embedLink";
const char kParents[] = "parents";
const char kThumbnailLink[] = "thumbnailLink";
const char kWebContentLink[] = "webContentLink";
const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
// Files List:
// Files List
// https://developers.google.com/drive/v2/reference/files/list
const char kFileListKind[] = "drive#fileList";
const char kNextPageToken[] = "nextPageToken";
const char kNextLink[] = "nextLink";
// Change Resource:
// Change Resource
// https://developers.google.com/drive/v2/reference/changes
const char kChangeKind[] = "drive#change";
const char kFileId[] = "fileId";
const char kDeleted[] = "deleted";
const char kFile[] = "file";
// Changes List:
// Changes List
// https://developers.google.com/drive/v2/reference/changes/list
const char kChangeListKind[] = "drive#changeList";
// Maps category name to enum IconCategory.
......@@ -131,9 +151,9 @@ namespace gdata {
// AboutResource implementation
AboutResource::AboutResource()
: quota_bytes_total_(0),
quota_bytes_used_(0),
largest_change_id_(0) {}
: largest_change_id_(0),
quota_bytes_total_(0),
quota_bytes_used_(0) {}
AboutResource::~AboutResource() {}
......@@ -150,17 +170,17 @@ scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) {
// static
void AboutResource::RegisterJSONConverter(
base::JSONValueConverter<AboutResource>* converter) {
converter->RegisterStringField(kRootFolderId,
&AboutResource::root_folder_id_);
converter->RegisterCustomField<int64>(kLargestChangeId,
&AboutResource::largest_change_id_,
&base::StringToInt64);
converter->RegisterCustomField<int64>(kQuotaBytesTotal,
&AboutResource::quota_bytes_total_,
&base::StringToInt64);
converter->RegisterCustomField<int64>(kQuotaBytesUsed,
&AboutResource::quota_bytes_used_,
&base::StringToInt64);
converter->RegisterCustomField<int64>(kLargestChangeId,
&AboutResource::largest_change_id_,
&base::StringToInt64);
converter->RegisterStringField(kRootFolderId,
&AboutResource::root_folder_id_);
}
bool AboutResource::Parse(const base::Value& value) {
......@@ -319,6 +339,9 @@ ParentReference::~ParentReference() {}
void ParentReference::RegisterJSONConverter(
base::JSONValueConverter<ParentReference>* converter) {
converter->RegisterStringField(kId, &ParentReference::file_id_);
converter->RegisterCustomField<GURL>(kParentLink,
&ParentReference::parent_link_,
GetGURLFromString);
converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_);
}
......@@ -355,14 +378,19 @@ void FileResource::RegisterJSONConverter(
base::JSONValueConverter<FileResource>* converter) {
converter->RegisterStringField(kId, &FileResource::file_id_);
converter->RegisterStringField(kETag, &FileResource::etag_);
converter->RegisterStringField(kMimeType, &FileResource::mime_type_);
converter->RegisterCustomField<GURL>(kSelfLink,
&FileResource::self_link_,
GetGURLFromString);
converter->RegisterStringField(kTitle, &FileResource::title_);
converter->RegisterStringField(kMimeType, &FileResource::mime_type_);
converter->RegisterCustomField<base::Time>(
kCreatedDate,
&FileResource::created_date_,
&gdata::util::GetTimeFromString);
converter->RegisterCustomField<base::Time>(
kModifiedByMeDate,
&FileResource::modified_by_me_date_,
&gdata::util::GetTimeFromString);
converter->RegisterRepeatedMessage<ParentReference>(kParents,
&FileResource::parents_);
converter->RegisterCustomField<GURL>(kDownloadUrl,
&FileResource::download_url_,
GetGURLFromString);
......@@ -372,6 +400,20 @@ void FileResource::RegisterJSONConverter(
converter->RegisterCustomField<int64>(kFileSize,
&FileResource::file_size_,
&base::StringToInt64);
converter->RegisterCustomField<GURL>(kAlternateLink,
&FileResource::alternate_link_,
GetGURLFromString);
converter->RegisterCustomField<GURL>(kEmbedLink,
&FileResource::embed_link_,
GetGURLFromString);
converter->RegisterRepeatedMessage<ParentReference>(kParents,
&FileResource::parents_);
converter->RegisterCustomField<GURL>(kThumbnailLink,
&FileResource::thumbnail_link_,
GetGURLFromString);
converter->RegisterCustomField<GURL>(kWebContentLink,
&FileResource::web_content_link_,
GetGURLFromString);
}
// static
......@@ -450,6 +492,7 @@ void ChangeResource::RegisterJSONConverter(
&ChangeResource::change_id_,
&base::StringToInt64);
converter->RegisterStringField(kFileId, &ChangeResource::file_id_);
converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_);
converter->RegisterNestedField(kFile, &ChangeResource::file_);
}
......
......@@ -44,14 +44,14 @@ class AboutResource {
// Creates about resource from parsed JSON.
static scoped_ptr<AboutResource> CreateFrom(const base::Value& value);
// Returns root folder ID.
const std::string& root_folder_id() const { return root_folder_id_; }
// Returns the largest change ID number.
int64 largest_change_id() const { return largest_change_id_; }
// Returns total number of quta bytes.
int64 quota_bytes_total() const { return quota_bytes_total_; }
// Returns the number of quota bytes used.
int64 quota_bytes_used() const { return quota_bytes_used_; }
// Returns the largest change ID number.
int64 largest_change_id() const { return largest_change_id_; }
// Returns root folder ID.
const std::string& root_folder_id() const { return root_folder_id_; }
private:
friend class DriveAPIParserTest;
......@@ -62,10 +62,10 @@ class AboutResource {
// Return false if parsing fails.
bool Parse(const base::Value& value);
std::string root_folder_id_;
int64 largest_change_id_;
int64 quota_bytes_total_;
int64 quota_bytes_used_;
int64 largest_change_id_;
std::string root_folder_id_;
DISALLOW_COPY_AND_ASSIGN(AboutResource);
};
......@@ -275,6 +275,9 @@ class ParentReference {
// Returns the file id of the reference.
const std::string& file_id() const { return file_id_; }
// Returns the URL for the parent in Drive.
const GURL& parent_link() const { return parent_link_; }
// Returns true if the reference is root directory.
bool is_root() const { return is_root_; }
......@@ -287,6 +290,7 @@ class ParentReference {
bool Parse(const base::Value& value);
std::string file_id_;
GURL parent_link_;
bool is_root_;
DISALLOW_COPY_AND_ASSIGN(ParentReference);
......@@ -317,19 +321,23 @@ class FileResource {
// Returns ETag for this file.
const std::string& etag() const { return etag_; }
// Returns MIME type of this file.
const std::string& mime_type() const { return mime_type_; }
// Returns the link to JSON of this file itself.
const GURL& self_link() const { return self_link_; }
// Returns the title of this file.
const std::string& title() const { return title_; }
// Returns MIME type of this file.
const std::string& mime_type() const { return mime_type_; }
// Returns created time of this file.
const base::Time& created_date() const { return created_date_; }
// Returns modification time by the user.
const base::Time& modified_by_me_date() const { return modified_by_me_date_; }
// Returns parent references (directories) of this file.
const ScopedVector<ParentReference>& parents() const { return parents_; }
// Returns the download URL.
// Returns the short-lived download URL for the file. This field exists
// only when the file content is stored in Drive.
const GURL& download_url() const { return download_url_; }
// Returns the extension part of the filename.
......@@ -341,6 +349,23 @@ class FileResource {
// Returns the size of this file in bytes.
int64 file_size() const { return file_size_; }
// Return the link to open the file in Google editor or viewer.
// E.g. Google Document, Google Spreadsheet.
const GURL& alternate_link() const { return alternate_link_; }
// Returns the link for embedding the file.
const GURL& embed_link() const { return embed_link_; }
// Returns parent references (directories) of this file.
const ScopedVector<ParentReference>& parents() const { return parents_; }
// Returns the link to the file's thumbnail.
const GURL& thumbnail_link() const { return thumbnail_link_; }
// Returns the link to open its downloadable content, using cookie based
// authentication.
const GURL& web_content_link() const { return web_content_link_; }
private:
friend class base::internal::RepeatedMessageConverter<FileResource>;
friend class ChangeResource;
......@@ -353,14 +378,20 @@ class FileResource {
std::string file_id_;
std::string etag_;
std::string mime_type_;
GURL self_link_;
std::string title_;
std::string mime_type_;
base::Time created_date_;
base::Time modified_by_me_date_;
ScopedVector<ParentReference> parents_;
GURL download_url_;
std::string file_extension_;
std::string md5_checksum_;
int64 file_size_;
GURL alternate_link_;
GURL embed_link_;
ScopedVector<ParentReference> parents_;
GURL thumbnail_link_;
GURL web_content_link_;
DISALLOW_COPY_AND_ASSIGN(FileResource);
};
......
......@@ -162,7 +162,7 @@ TEST_F(DriveAPIParserTest, FileListParser) {
"t10AAAAABC"), filelist->next_link());
ASSERT_EQ(3U, filelist->items().size());
// Check file 1 (a file)
// Check file 1 (a regular file)
const FileResource& file1 = *filelist->items()[0];
EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", file1.file_id());
EXPECT_EQ("\"WtRjAPZWbDA7_fkFjc5ojsEvDEF/MTM0MzM2NzgwMDIXYZ\"",
......@@ -170,6 +170,11 @@ TEST_F(DriveAPIParserTest, FileListParser) {
EXPECT_EQ("My first file data", file1.title());
EXPECT_EQ("application/octet-stream", file1.mime_type());
base::Time created_time;
ASSERT_TRUE(gdata::util::GetTimeFromString("2012-07-24T08:51:16.570Z",
&created_time));
EXPECT_EQ(created_time, file1.created_date());
base::Time modified_time;
ASSERT_TRUE(gdata::util::GetTimeFromString("2012-07-27T05:43:20.269Z",
&modified_time));
......@@ -177,6 +182,9 @@ TEST_F(DriveAPIParserTest, FileListParser) {
ASSERT_EQ(1U, file1.parents().size());
EXPECT_EQ("0B4v7G8yEYAWHYW1OcExsUVZLABC", file1.parents()[0]->file_id());
EXPECT_EQ(GURL("https://www.googleapis.com/drive/v2/files/"
"0B4v7G8yEYAWHYW1OcExsUVZLABC"),
file1.parents()[0]->parent_link());
EXPECT_FALSE(file1.parents()[0]->is_root());
EXPECT_EQ(GURL("https://www.example.com/download"), file1.download_url());
......@@ -184,6 +192,16 @@ TEST_F(DriveAPIParserTest, FileListParser) {
EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", file1.md5_checksum());
EXPECT_EQ(1000U, file1.file_size());
EXPECT_EQ(GURL("https://www.googleapis.com/drive/v2/files/"
"0B4v7G8yEYAWHUmRrU2lMS2hLABC"),
file1.self_link());
EXPECT_EQ(GURL("https://docs.google.com/file/d/"
"0B4v7G8yEYAWHUmRrU2lMS2hLABC/edit"),
file1.alternate_link());
EXPECT_EQ(GURL("https://docs.google.com/uc?"
"id=0B4v7G8yEYAWHUmRrU2lMS2hLABC&export=download"),
file1.web_content_link());
// Check file 2 (a Google Document)
const FileResource& file2 = *filelist->items()[1];
EXPECT_EQ("Test Google Document", file2.title());
......@@ -192,6 +210,14 @@ TEST_F(DriveAPIParserTest, FileListParser) {
ASSERT_EQ(0U, file2.parents().size());
EXPECT_EQ(GURL("https://docs.google.com/a/chromium.org/document/d/"
"1Pc8jzfU1ErbN_eucMMqdqzY3eBm0v8sxXm_1CtLxABC/preview"),
file2.embed_link());
EXPECT_EQ(GURL("https://docs.google.com/feeds/vt?gd=true&"
"id=1Pc8jzfU1ErbN_eucMMqdqzY3eBm0v8sxXm_1CtLxABC&"
"v=3&s=AMedNnoAAAAAUBJyB0g8HbxZaLRnlztxefZPS24LiXYZ&sz=s220"),
file2.thumbnail_link());
// Check file 3 (a folder)
const FileResource& file3 = *filelist->items()[2];
EXPECT_EQ(0U, file3.file_size());
......
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