summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 06:38:51 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-17 06:38:51 +0000
commit0e261905f64d6c779b11f135e31cef34d8fe2b51 (patch)
tree7a0da4e46aaf6623d01f43b8023b2c64654fbd6b /google_apis
parent3975f93f7ca74154ea782cafff59abf533a0f7d9 (diff)
downloadchromium_src-0e261905f64d6c779b11f135e31cef34d8fe2b51.zip
chromium_src-0e261905f64d6c779b11f135e31cef34d8fe2b51.tar.gz
chromium_src-0e261905f64d6c779b11f135e31cef34d8fe2b51.tar.bz2
drive: Check "modificationDate" property of a change before applying it
Updating a locally edited entry with an older change results in unnecessarily overwriting users' edit. Add "modificationDate" field to ChangeResource. (Corresponding API documentation: https://developers.google.com/drive/v2/reference/changes#resource) Request "modificationDate" Use "modificationDate" for conflict resolution in ChangeListProcessor. BUG=350398 Review URL: https://codereview.chromium.org/199343004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/drive/drive_api_parser.cc4
-rw-r--r--google_apis/drive/drive_api_parser.h7
-rw-r--r--google_apis/drive/drive_api_parser_unittest.cc7
-rw-r--r--google_apis/drive/gdata_wapi_parser.h9
4 files changed, 27 insertions, 0 deletions
diff --git a/google_apis/drive/drive_api_parser.cc b/google_apis/drive/drive_api_parser.cc
index 018c37d..384db45 100644
--- a/google_apis/drive/drive_api_parser.cc
+++ b/google_apis/drive/drive_api_parser.cc
@@ -125,6 +125,7 @@ const char kFileKind[] = "drive#file";
const char kTitle[] = "title";
const char kMimeType[] = "mimeType";
const char kCreatedDate[] = "createdDate";
+const char kModificationDate[] = "modificationDate";
const char kModifiedDate[] = "modifiedDate";
const char kModifiedByMeDate[] = "modifiedByMeDate";
const char kLastViewedByMeDate[] = "lastViewedByMeDate";
@@ -559,6 +560,9 @@ void ChangeResource::RegisterJSONConverter(
converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_);
converter->RegisterCustomValueField(kFile, &ChangeResource::file_,
&CreateFileResourceFromValue);
+ converter->RegisterCustomField<base::Time>(
+ kModificationDate, &ChangeResource::modification_date_,
+ &util::GetTimeFromString);
}
// static
diff --git a/google_apis/drive/drive_api_parser.h b/google_apis/drive/drive_api_parser.h
index 75f2792..e51b864 100644
--- a/google_apis/drive/drive_api_parser.h
+++ b/google_apis/drive/drive_api_parser.h
@@ -730,6 +730,9 @@ class ChangeResource {
const FileResource* file() const { return file_.get(); }
FileResource* mutable_file() { return file_.get(); }
+ // Returns the time of this modification.
+ const base::Time& modification_date() const { return modification_date_; }
+
void set_change_id(int64 change_id) {
change_id_ = change_id;
}
@@ -742,6 +745,9 @@ class ChangeResource {
void set_file(scoped_ptr<FileResource> file) {
file_ = file.Pass();
}
+ void set_modification_date(const base::Time& modification_date) {
+ modification_date_ = modification_date;
+ }
private:
friend class base::internal::RepeatedMessageConverter<ChangeResource>;
@@ -755,6 +761,7 @@ class ChangeResource {
std::string file_id_;
bool deleted_;
scoped_ptr<FileResource> file_;
+ base::Time modification_date_;
DISALLOW_COPY_AND_ASSIGN(ChangeResource);
};
diff --git a/google_apis/drive/drive_api_parser_unittest.cc b/google_apis/drive/drive_api_parser_unittest.cc
index 413e7ef..fd9b0c3 100644
--- a/google_apis/drive/drive_api_parser_unittest.cc
+++ b/google_apis/drive/drive_api_parser_unittest.cc
@@ -254,6 +254,7 @@ TEST(DriveAPIParserTest, ChangeListParser) {
EXPECT_EQ("1Pc8jzfU1ErbN_eucMMqdqzY3eBm0v8sxXm_1CtLxABC", change1.file_id());
EXPECT_EQ(change1.file_id(), change1.file()->file_id());
EXPECT_FALSE(change1.file()->shared());
+ EXPECT_EQ(change1.file()->modified_date(), change1.modification_date());
const ChangeResource& change2 = *changelist->items()[1];
EXPECT_EQ(8424, change2.change_id());
@@ -261,6 +262,7 @@ TEST(DriveAPIParserTest, ChangeListParser) {
EXPECT_EQ("0B4v7G8yEYAWHUmRrU2lMS2hLABC", change2.file_id());
EXPECT_EQ(change2.file_id(), change2.file()->file_id());
EXPECT_TRUE(change2.file()->shared());
+ EXPECT_EQ(change2.file()->modified_date(), change2.modification_date());
const ChangeResource& change3 = *changelist->items()[2];
EXPECT_EQ(8429, change3.change_id());
@@ -268,12 +270,17 @@ TEST(DriveAPIParserTest, ChangeListParser) {
EXPECT_EQ("0B4v7G8yEYAWHYW1OcExsUVZLABC", change3.file_id());
EXPECT_EQ(change3.file_id(), change3.file()->file_id());
EXPECT_FALSE(change3.file()->shared());
+ EXPECT_EQ(change3.file()->modified_date(), change3.modification_date());
// Deleted entry.
const ChangeResource& change4 = *changelist->items()[3];
EXPECT_EQ(8430, change4.change_id());
EXPECT_EQ("ABCv7G8yEYAWHc3Y5X0hMSkJYXYZ", change4.file_id());
EXPECT_TRUE(change4.is_deleted());
+ base::Time modification_time;
+ ASSERT_TRUE(util::GetTimeFromString("2012-07-27T12:34:56.789Z",
+ &modification_time));
+ EXPECT_EQ(modification_time, change4.modification_date());
}
TEST(DriveAPIParserTest, HasKind) {
diff --git a/google_apis/drive/gdata_wapi_parser.h b/google_apis/drive/gdata_wapi_parser.h
index a7ac493..eddd0e1 100644
--- a/google_apis/drive/gdata_wapi_parser.h
+++ b/google_apis/drive/gdata_wapi_parser.h
@@ -464,6 +464,10 @@ class ResourceEntry : public CommonMetadata {
// If doesn't exist, then equals -1.
int64 image_rotation() const { return image_rotation_; }
+ // The time of this modification.
+ // Note: This property is filled only when converted from ChangeResource.
+ const base::Time& modification_date() const { return modification_date_; }
+
// Text version of resource entry kind. Returns an empty string for
// unknown entry kind.
std::string GetEntryKindText() const;
@@ -557,6 +561,9 @@ class ResourceEntry : public CommonMetadata {
void set_image_rotation(int64 image_rotation) {
image_rotation_ = image_rotation;
}
+ void set_modification_date(const base::Time& modification_date) {
+ modification_date_ = modification_date;
+ }
// Fills the remaining fields where JSONValueConverter cannot catch.
// Currently, sets |kind_| and |labels_| based on the |categories_| in the
@@ -595,6 +602,8 @@ class ResourceEntry : public CommonMetadata {
int64 image_height_;
int64 image_rotation_;
+ base::Time modification_date_;
+
DISALLOW_COPY_AND_ASSIGN(ResourceEntry);
};