summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-31 11:34:20 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-31 11:34:20 +0000
commit4979eaf0a54cef95dd4bfc15081250b86de9fa1f (patch)
tree6dce25148414b64b629661ab8a0a4976b373b2d7 /google_apis
parent9d8fa48dc0f827d6d53bd2a4c09cffa627665905 (diff)
downloadchromium_src-4979eaf0a54cef95dd4bfc15081250b86de9fa1f.zip
chromium_src-4979eaf0a54cef95dd4bfc15081250b86de9fa1f.tar.gz
chromium_src-4979eaf0a54cef95dd4bfc15081250b86de9fa1f.tar.bz2
drive: Determine if an entry is hosted by the existence of fileSize field.
With this change, newly added hosted document types can be correctly handled as hosted without any code-level change. The unknown documents get .glink extension in Files.app. BUG=397391 Review URL: https://codereview.chromium.org/419183002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@286735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_parser.cc10
-rw-r--r--google_apis/drive/drive_api_parser.h6
-rw-r--r--google_apis/drive/drive_api_parser_unittest.cc7
3 files changed, 20 insertions, 3 deletions
diff --git a/google_apis/drive/drive_api_parser.cc b/google_apis/drive/drive_api_parser.cc
index c22070e..89c6a9e 100644
--- a/google_apis/drive/drive_api_parser.cc
+++ b/google_apis/drive/drive_api_parser.cc
@@ -24,6 +24,8 @@ namespace google_apis {
namespace {
+const int64 kUnsetFileSize = -1;
+
bool CreateFileResourceFromValue(const base::Value* value,
scoped_ptr<FileResource>* file) {
*file = FileResource::CreateFrom(*value);
@@ -429,7 +431,7 @@ bool ParentReference::Parse(const base::Value& value) {
////////////////////////////////////////////////////////////////////////////////
// FileResource implementation
-FileResource::FileResource() : shared_(false), file_size_(0) {}
+FileResource::FileResource() : shared_(false), file_size_(kUnsetFileSize) {}
FileResource::~FileResource() {}
@@ -491,6 +493,12 @@ bool FileResource::IsDirectory() const {
return mime_type_ == kDriveFolderMimeType;
}
+bool FileResource::IsHostedDocument() const {
+ // Hosted documents don't have fileSize field set:
+ // https://developers.google.com/drive/v2/reference/files
+ return !IsDirectory() && file_size_ == kUnsetFileSize;
+}
+
bool FileResource::Parse(const base::Value& value) {
base::JSONValueConverter<FileResource> converter;
if (!converter.Convert(value, this)) {
diff --git a/google_apis/drive/drive_api_parser.h b/google_apis/drive/drive_api_parser.h
index babb4cd..0f21bdd 100644
--- a/google_apis/drive/drive_api_parser.h
+++ b/google_apis/drive/drive_api_parser.h
@@ -446,6 +446,12 @@ class FileResource {
// but outside this file we use "directory" to match HTML5 filesystem API.
bool IsDirectory() const;
+ // Returns true if this is a hosted document.
+ // A hosted document is a document in one of Google Docs formats (Documents,
+ // Spreadsheets, Slides, ...) whose content is not exposed via the API. It is
+ // available only as |alternate_link()| to the document hosted on the server.
+ bool IsHostedDocument() const;
+
// Returns file ID. This is unique in all files in Google Drive.
const std::string& file_id() const { return file_id_; }
diff --git a/google_apis/drive/drive_api_parser_unittest.cc b/google_apis/drive/drive_api_parser_unittest.cc
index 6f9ee65..86fc482 100644
--- a/google_apis/drive/drive_api_parser_unittest.cc
+++ b/google_apis/drive/drive_api_parser_unittest.cc
@@ -159,6 +159,7 @@ TEST(DriveAPIParserTest, FileListParser) {
EXPECT_EQ("d41d8cd98f00b204e9800998ecf8427e", file1.md5_checksum());
EXPECT_EQ(1000U, file1.file_size());
+ EXPECT_FALSE(file1.IsHostedDocument());
EXPECT_EQ(GURL("https://docs.google.com/file/d/"
"0B4v7G8yEYAWHUmRrU2lMS2hLABC/edit"),
@@ -185,7 +186,8 @@ TEST(DriveAPIParserTest, FileListParser) {
&shared_with_me_time));
EXPECT_EQ(shared_with_me_time, file2.shared_with_me_date());
- EXPECT_EQ(0U, file2.file_size());
+ EXPECT_EQ(-1, file2.file_size());
+ EXPECT_TRUE(file2.IsHostedDocument());
ASSERT_EQ(0U, file2.parents().size());
@@ -193,7 +195,8 @@ TEST(DriveAPIParserTest, FileListParser) {
// Check file 3 (a folder)
const FileResource& file3 = *filelist->items()[2];
- EXPECT_EQ(0U, file3.file_size());
+ EXPECT_EQ(-1, file3.file_size());
+ EXPECT_FALSE(file3.IsHostedDocument());
EXPECT_EQ("TestFolder", file3.title());
EXPECT_EQ("application/vnd.google-apps.folder", file3.mime_type());
ASSERT_TRUE(file3.IsDirectory());