Index: google_apis/drive/drive_api_parser.h |
diff --git a/google_apis/drive/drive_api_parser.h b/google_apis/drive/drive_api_parser.h |
index da66d2123130a4b61c85cec1dc02698131918bd5..9b21798a02c72086da8d6f7b08d9607e7f77e7f9 100644 |
--- a/google_apis/drive/drive_api_parser.h |
+++ b/google_apis/drive/drive_api_parser.h |
@@ -750,6 +750,11 @@ class FileList { |
// https://developers.google.com/drive/v2/reference/changes |
class ChangeResource { |
public: |
+ enum ChangeType { |
+ UNKNOWN, // Uninitialized state. |
+ FILE, |
+ TEAM_DRIVE, |
+ }; |
ChangeResource(); |
~ChangeResource(); |
@@ -765,15 +770,46 @@ class ChangeResource { |
// number. |
int64_t change_id() const { return change_id_; } |
+ // Returns whether this is a change of a file or a team drive. |
+ ChangeType type() const { return type_; } |
+ |
// Returns a string file ID for corresponding file of the change. |
- const std::string& file_id() const { return file_id_; } |
+ // Valid only when type == FILE. |
+ const std::string& file_id() const { |
+ DCHECK(type_ == FILE); |
hashimoto
2017/03/22 07:34:13
Please use DCHECK_EQ for better error message.
yamaguchi
2017/03/22 07:56:14
Done.
|
+ return file_id_; |
+ } |
// Returns true if this file is deleted in the change. |
bool is_deleted() const { return deleted_; } |
// Returns FileResource of the file which the change refers to. |
- const FileResource* file() const { return file_.get(); } |
- FileResource* mutable_file() { return file_.get(); } |
+ // Valid only when type == FILE. |
+ const FileResource* file() const { |
+ DCHECK(type_ == FILE); |
+ return file_.get(); |
+ } |
+ FileResource* mutable_file() { |
+ DCHECK(type_ == FILE); |
+ return file_.get(); |
+ } |
+ |
+ // Returns TeamDriveResource which the change refers to. |
+ // Valid only when type == TEAM_DRIVE. |
+ const TeamDriveResource* team_drive() const { |
+ DCHECK(type_ == TEAM_DRIVE); |
+ return team_drive_.get(); |
+ } |
+ TeamDriveResource* mutable_team_drive() { |
+ DCHECK(type_ == TEAM_DRIVE); |
+ return team_drive_.get(); |
+ } |
+ |
+ // Returns the ID of the Team Drive. Valid only when type == TEAM_DRIVE. |
+ const std::string& team_drive_id() const { |
+ DCHECK(type_ == TEAM_DRIVE); |
+ return team_drive_id_; |
+ } |
// Returns the time of this modification. |
const base::Time& modification_date() const { return modification_date_; } |
@@ -798,11 +834,19 @@ class ChangeResource { |
// Return false if parsing fails. |
bool Parse(const base::Value& value); |
+ // Extracts the change type from the given string. Returns false and does |
+ // not change |result| when |type_name| has an unrecognizable value. |
+ static bool GetType(const base::StringPiece& type_name, |
+ ChangeResource::ChangeType* result); |
+ |
int64_t change_id_; |
+ ChangeType type_; |
std::string file_id_; |
bool deleted_; |
std::unique_ptr<FileResource> file_; |
base::Time modification_date_; |
+ std::string team_drive_id_; |
+ std::unique_ptr<TeamDriveResource> team_drive_; |
DISALLOW_COPY_AND_ASSIGN(ChangeResource); |
}; |