OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 6 #define GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 GURL next_link_; | 743 GURL next_link_; |
744 std::vector<std::unique_ptr<FileResource>> items_; | 744 std::vector<std::unique_ptr<FileResource>> items_; |
745 | 745 |
746 DISALLOW_COPY_AND_ASSIGN(FileList); | 746 DISALLOW_COPY_AND_ASSIGN(FileList); |
747 }; | 747 }; |
748 | 748 |
749 // ChangeResource represents a change in a file. | 749 // ChangeResource represents a change in a file. |
750 // https://developers.google.com/drive/v2/reference/changes | 750 // https://developers.google.com/drive/v2/reference/changes |
751 class ChangeResource { | 751 class ChangeResource { |
752 public: | 752 public: |
753 enum ChangeType { | |
754 UNKNOWN, // Uninitialized state. | |
755 FILE, | |
756 TEAM_DRIVE, | |
757 }; | |
753 ChangeResource(); | 758 ChangeResource(); |
754 ~ChangeResource(); | 759 ~ChangeResource(); |
755 | 760 |
756 // Registers the mapping between JSON field names and the members in this | 761 // Registers the mapping between JSON field names and the members in this |
757 // class. | 762 // class. |
758 static void RegisterJSONConverter( | 763 static void RegisterJSONConverter( |
759 base::JSONValueConverter<ChangeResource>* converter); | 764 base::JSONValueConverter<ChangeResource>* converter); |
760 | 765 |
761 // Creates change resource from parsed JSON. | 766 // Creates change resource from parsed JSON. |
762 static std::unique_ptr<ChangeResource> CreateFrom(const base::Value& value); | 767 static std::unique_ptr<ChangeResource> CreateFrom(const base::Value& value); |
763 | 768 |
764 // Returns change ID for this change. This is a monotonically increasing | 769 // Returns change ID for this change. This is a monotonically increasing |
765 // number. | 770 // number. |
766 int64_t change_id() const { return change_id_; } | 771 int64_t change_id() const { return change_id_; } |
767 | 772 |
773 // Returns whether this is a change of a file or a team drive. | |
774 ChangeType type() const { return type_; } | |
775 | |
768 // Returns a string file ID for corresponding file of the change. | 776 // Returns a string file ID for corresponding file of the change. |
769 const std::string& file_id() const { return file_id_; } | 777 // Valid only when type == FILE. |
778 const std::string& file_id() const { | |
779 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.
| |
780 return file_id_; | |
781 } | |
770 | 782 |
771 // Returns true if this file is deleted in the change. | 783 // Returns true if this file is deleted in the change. |
772 bool is_deleted() const { return deleted_; } | 784 bool is_deleted() const { return deleted_; } |
773 | 785 |
774 // Returns FileResource of the file which the change refers to. | 786 // Returns FileResource of the file which the change refers to. |
775 const FileResource* file() const { return file_.get(); } | 787 // Valid only when type == FILE. |
776 FileResource* mutable_file() { return file_.get(); } | 788 const FileResource* file() const { |
789 DCHECK(type_ == FILE); | |
790 return file_.get(); | |
791 } | |
792 FileResource* mutable_file() { | |
793 DCHECK(type_ == FILE); | |
794 return file_.get(); | |
795 } | |
796 | |
797 // Returns TeamDriveResource which the change refers to. | |
798 // Valid only when type == TEAM_DRIVE. | |
799 const TeamDriveResource* team_drive() const { | |
800 DCHECK(type_ == TEAM_DRIVE); | |
801 return team_drive_.get(); | |
802 } | |
803 TeamDriveResource* mutable_team_drive() { | |
804 DCHECK(type_ == TEAM_DRIVE); | |
805 return team_drive_.get(); | |
806 } | |
807 | |
808 // Returns the ID of the Team Drive. Valid only when type == TEAM_DRIVE. | |
809 const std::string& team_drive_id() const { | |
810 DCHECK(type_ == TEAM_DRIVE); | |
811 return team_drive_id_; | |
812 } | |
777 | 813 |
778 // Returns the time of this modification. | 814 // Returns the time of this modification. |
779 const base::Time& modification_date() const { return modification_date_; } | 815 const base::Time& modification_date() const { return modification_date_; } |
780 | 816 |
781 void set_change_id(int64_t change_id) { change_id_ = change_id; } | 817 void set_change_id(int64_t change_id) { change_id_ = change_id; } |
782 void set_file_id(const std::string& file_id) { | 818 void set_file_id(const std::string& file_id) { |
783 file_id_ = file_id; | 819 file_id_ = file_id; |
784 } | 820 } |
785 void set_deleted(bool deleted) { | 821 void set_deleted(bool deleted) { |
786 deleted_ = deleted; | 822 deleted_ = deleted; |
787 } | 823 } |
788 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); } | 824 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); } |
789 void set_modification_date(const base::Time& modification_date) { | 825 void set_modification_date(const base::Time& modification_date) { |
790 modification_date_ = modification_date; | 826 modification_date_ = modification_date; |
791 } | 827 } |
792 | 828 |
793 private: | 829 private: |
794 friend class base::internal::RepeatedMessageConverter<ChangeResource>; | 830 friend class base::internal::RepeatedMessageConverter<ChangeResource>; |
795 friend class ChangeList; | 831 friend class ChangeList; |
796 | 832 |
797 // Parses and initializes data members from content of |value|. | 833 // Parses and initializes data members from content of |value|. |
798 // Return false if parsing fails. | 834 // Return false if parsing fails. |
799 bool Parse(const base::Value& value); | 835 bool Parse(const base::Value& value); |
800 | 836 |
837 // Extracts the change type from the given string. Returns false and does | |
838 // not change |result| when |type_name| has an unrecognizable value. | |
839 static bool GetType(const base::StringPiece& type_name, | |
840 ChangeResource::ChangeType* result); | |
841 | |
801 int64_t change_id_; | 842 int64_t change_id_; |
843 ChangeType type_; | |
802 std::string file_id_; | 844 std::string file_id_; |
803 bool deleted_; | 845 bool deleted_; |
804 std::unique_ptr<FileResource> file_; | 846 std::unique_ptr<FileResource> file_; |
805 base::Time modification_date_; | 847 base::Time modification_date_; |
848 std::string team_drive_id_; | |
849 std::unique_ptr<TeamDriveResource> team_drive_; | |
806 | 850 |
807 DISALLOW_COPY_AND_ASSIGN(ChangeResource); | 851 DISALLOW_COPY_AND_ASSIGN(ChangeResource); |
808 }; | 852 }; |
809 | 853 |
810 // ChangeList represents a set of changes in the drive. | 854 // ChangeList represents a set of changes in the drive. |
811 // https://developers.google.com/drive/v2/reference/changes/list | 855 // https://developers.google.com/drive/v2/reference/changes/list |
812 class ChangeList { | 856 class ChangeList { |
813 public: | 857 public: |
814 ChangeList(); | 858 ChangeList(); |
815 ~ChangeList(); | 859 ~ChangeList(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 GURL next_link_; | 902 GURL next_link_; |
859 int64_t largest_change_id_; | 903 int64_t largest_change_id_; |
860 std::vector<std::unique_ptr<ChangeResource>> items_; | 904 std::vector<std::unique_ptr<ChangeResource>> items_; |
861 | 905 |
862 DISALLOW_COPY_AND_ASSIGN(ChangeList); | 906 DISALLOW_COPY_AND_ASSIGN(ChangeList); |
863 }; | 907 }; |
864 | 908 |
865 } // namespace google_apis | 909 } // namespace google_apis |
866 | 910 |
867 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 911 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
OLD | NEW |