summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/google_apis/gdata_wapi_parser.cc23
-rw-r--r--chrome/browser/google_apis/gdata_wapi_parser.h14
-rw-r--r--chrome/browser/google_apis/gdata_wapi_parser_unittest.cc7
-rw-r--r--chrome/chrome_tests_unit.gypi1
-rw-r--r--chrome/test/data/chromeos/gdata/basic_feed.json3
5 files changed, 41 insertions, 7 deletions
diff --git a/chrome/browser/google_apis/gdata_wapi_parser.cc b/chrome/browser/google_apis/gdata_wapi_parser.cc
index ccf6edc..c6f649f 100644
--- a/chrome/browser/google_apis/gdata_wapi_parser.cc
+++ b/chrome/browser/google_apis/gdata_wapi_parser.cc
@@ -68,6 +68,7 @@ const char kWritersCanInviteNode[] = "writersCanInvite";
// Field names.
const char kAuthorField[] = "author";
const char kCategoryField[] = "category";
+const char kChangestampField[] = "docs$changestamp.value";
const char kContentField[] = "content";
const char kDeletedField[] = "gd$deleted";
const char kETagField[] = "gd$etag";
@@ -593,7 +594,8 @@ DocumentEntry::DocumentEntry()
: kind_(ENTRY_KIND_UNKNOWN),
file_size_(0),
deleted_(false),
- removed_(false) {
+ removed_(false),
+ changestamp_(0) {
}
DocumentEntry::~DocumentEntry() {
@@ -605,6 +607,22 @@ bool DocumentEntry::HasFieldPresent(const base::Value* value,
return true;
}
+bool DocumentEntry::ParseChangestamp(const base::Value* value,
+ int64* result) {
+ DCHECK(result);
+ if (!value) {
+ *result = 0;
+ return true;
+ }
+
+ std::string string_value;
+ if (value->GetAsString(&string_value) &&
+ base::StringToInt64(string_value, result))
+ return true;
+
+ return false;
+}
+
// static
void DocumentEntry::RegisterJSONConverter(
base::JSONValueConverter<DocumentEntry>* converter) {
@@ -640,6 +658,9 @@ void DocumentEntry::RegisterJSONConverter(
kDeletedField, &DocumentEntry::deleted_, &DocumentEntry::HasFieldPresent);
converter->RegisterCustomValueField<bool>(
kRemovedField, &DocumentEntry::removed_, &DocumentEntry::HasFieldPresent);
+ converter->RegisterCustomValueField<int64>(
+ kChangestampField, &DocumentEntry::changestamp_,
+ &DocumentEntry::ParseChangestamp);
}
std::string DocumentEntry::GetHostedDocumentExtension() const {
diff --git a/chrome/browser/google_apis/gdata_wapi_parser.h b/chrome/browser/google_apis/gdata_wapi_parser.h
index 684b219..99395e1 100644
--- a/chrome/browser/google_apis/gdata_wapi_parser.h
+++ b/chrome/browser/google_apis/gdata_wapi_parser.h
@@ -382,10 +382,15 @@ class DocumentEntry : public FeedEntry {
static void RegisterJSONConverter(
base::JSONValueConverter<DocumentEntry>* converter);
- // Helper function for parsing bool fields based on presence of
- // their value nodes.
+ // Sets true to |result| if the field exists.
+ // Always returns true even when the field does not exist.
static bool HasFieldPresent(const base::Value* value, bool* result);
+ // Parses |value| as int64 and sets it to |result|. If the field does not
+ // exist, sets 0 to |result| as default value.
+ // Returns true if |value| is NULL or it is parsed as int64 successfully.
+ static bool ParseChangestamp(const base::Value* value, int64* result);
+
// Returns true if |file| has one of the hosted document extensions.
static bool HasHostedDocumentExtension(const FilePath& file);
@@ -434,6 +439,10 @@ class DocumentEntry : public FeedEntry {
// True if the file or directory is deleted (applicable to change feeds only).
bool deleted() const { return deleted_ || removed_; }
+ // Changestamp (exists only for change query results).
+ // If not exists, defaults to 0.
+ int64 changestamp() const { return changestamp_; }
+
// Text version of document entry kind. Returns an empty string for
// unknown entry kind.
std::string GetEntryKindText() const;
@@ -517,6 +526,7 @@ class DocumentEntry : public FeedEntry {
int64 file_size_;
bool deleted_;
bool removed_;
+ int64 changestamp_;
DISALLOW_COPY_AND_ASSIGN(DocumentEntry);
};
diff --git a/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc b/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc
index f2aa8d4..c7decea 100644
--- a/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc
+++ b/chrome/browser/google_apis/gdata_wapi_parser_unittest.cc
@@ -54,9 +54,8 @@ class GDataWAPIParserTest : public testing::Test {
}
};
-// TODO(nhiroki): Make it possible to run these tests on any platforms after
-// moving json files to out of 'chromeos' directory (http://crbug.com/149788).
-#if defined(OS_CHROMEOS)
+// TODO(nhiroki): Move json files to out of 'chromeos' directory
+// (http://crbug.com/149788).
// Test document feed parsing.
TEST_F(GDataWAPIParserTest, DocumentFeedJsonParser) {
std::string error;
@@ -161,6 +160,7 @@ TEST_F(GDataWAPIParserTest, DocumentFeedJsonParser) {
file_open_with_link->href().spec());
EXPECT_EQ("application/atom+xml", file_open_with_link->mime_type());
EXPECT_EQ("the_app_id", file_open_with_link->app_id());
+ EXPECT_EQ(654321, file_entry->changestamp());
const Link* file_unknown_link = file_entry->GetLinkByType(Link::LINK_UNKNOWN);
ASSERT_TRUE(file_unknown_link);
@@ -336,7 +336,6 @@ TEST_F(GDataWAPIParserTest, AccountMetadataFeedParser) {
EXPECT_EQ(1U, second_app->primary_extensions().size());
EXPECT_EQ(0U, second_app->secondary_extensions().size());
}
-#endif // OS_CHROMEOS
// Test file extension checking in DocumentEntry::HasDocumentExtension().
TEST_F(GDataWAPIParserTest, DocumentEntryHasDocumentExtension) {
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index 371caf6..fcb5cea 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -2116,6 +2116,7 @@
# Test files cannot be opened on Android.
'browser/google_apis/gdata_wapi_operations_unittest.cc',
+ 'browser/google_apis/gdata_wapi_parser_unittest.cc',
],
'sources/': [
['exclude', '^browser/captive_portal/'],
diff --git a/chrome/test/data/chromeos/gdata/basic_feed.json b/chrome/test/data/chromeos/gdata/basic_feed.json
index dde5b56..ca7c673 100644
--- a/chrome/test/data/chromeos/gdata/basic_feed.json
+++ b/chrome/test/data/chromeos/gdata/basic_feed.json
@@ -116,6 +116,9 @@
"src": "https://file_content_url/",
"type": "audio/mpeg"
},
+ "docs$changestamp": {
+ "value": "654321"
+ },
"docs$filename": {
"$t": "filename.m4a"
},