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