| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 std::vector<std::unique_ptr<AppResource>> items_; | 324 std::vector<std::unique_ptr<AppResource>> items_; |
| 325 | 325 |
| 326 DISALLOW_COPY_AND_ASSIGN(AppList); | 326 DISALLOW_COPY_AND_ASSIGN(AppList); |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 // Capabilities of a Team Drive indicate the permissions granted to the user | 329 // Capabilities of a Team Drive indicate the permissions granted to the user |
| 330 // for the Team Drive and items within the Team Drive. | 330 // for the Team Drive and items within the Team Drive. |
| 331 class TeamDriveCapabilities { | 331 class TeamDriveCapabilities { |
| 332 public: | 332 public: |
| 333 TeamDriveCapabilities(); | 333 TeamDriveCapabilities(); |
| 334 TeamDriveCapabilities(const TeamDriveCapabilities& src); |
| 334 ~TeamDriveCapabilities(); | 335 ~TeamDriveCapabilities(); |
| 335 | 336 |
| 336 // Registers the mapping between JSON field names and the members in this | 337 // Registers the mapping between JSON field names and the members in this |
| 337 // class. | 338 // class. |
| 338 static void RegisterJSONConverter( | 339 static void RegisterJSONConverter( |
| 339 base::JSONValueConverter<TeamDriveCapabilities>* converter); | 340 base::JSONValueConverter<TeamDriveCapabilities>* converter); |
| 340 | 341 |
| 341 // Creates Team Drive resource from parsed JSON. | 342 // Creates Team Drive resource from parsed JSON. |
| 342 static std::unique_ptr<TeamDriveCapabilities> | 343 static std::unique_ptr<TeamDriveCapabilities> |
| 343 CreateFrom(const base::Value& value); | 344 CreateFrom(const base::Value& value); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 GURL next_link_; | 744 GURL next_link_; |
| 744 std::vector<std::unique_ptr<FileResource>> items_; | 745 std::vector<std::unique_ptr<FileResource>> items_; |
| 745 | 746 |
| 746 DISALLOW_COPY_AND_ASSIGN(FileList); | 747 DISALLOW_COPY_AND_ASSIGN(FileList); |
| 747 }; | 748 }; |
| 748 | 749 |
| 749 // ChangeResource represents a change in a file. | 750 // ChangeResource represents a change in a file. |
| 750 // https://developers.google.com/drive/v2/reference/changes | 751 // https://developers.google.com/drive/v2/reference/changes |
| 751 class ChangeResource { | 752 class ChangeResource { |
| 752 public: | 753 public: |
| 754 enum ChangeType { |
| 755 UNKNOWN, // Uninitialized state. |
| 756 FILE, |
| 757 TEAM_DRIVE, |
| 758 }; |
| 753 ChangeResource(); | 759 ChangeResource(); |
| 754 ~ChangeResource(); | 760 ~ChangeResource(); |
| 755 | 761 |
| 756 // Registers the mapping between JSON field names and the members in this | 762 // Registers the mapping between JSON field names and the members in this |
| 757 // class. | 763 // class. |
| 758 static void RegisterJSONConverter( | 764 static void RegisterJSONConverter( |
| 759 base::JSONValueConverter<ChangeResource>* converter); | 765 base::JSONValueConverter<ChangeResource>* converter); |
| 760 | 766 |
| 761 // Creates change resource from parsed JSON. | 767 // Creates change resource from parsed JSON. |
| 762 static std::unique_ptr<ChangeResource> CreateFrom(const base::Value& value); | 768 static std::unique_ptr<ChangeResource> CreateFrom(const base::Value& value); |
| 763 | 769 |
| 764 // Returns change ID for this change. This is a monotonically increasing | 770 // Returns change ID for this change. This is a monotonically increasing |
| 765 // number. | 771 // number. |
| 766 int64_t change_id() const { return change_id_; } | 772 int64_t change_id() const { return change_id_; } |
| 767 | 773 |
| 774 // Returns whether this is a change of a file or a team drive. |
| 775 ChangeType type() const { return type_; } |
| 776 |
| 768 // Returns a string file ID for corresponding file of the change. | 777 // Returns a string file ID for corresponding file of the change. |
| 769 const std::string& file_id() const { return file_id_; } | 778 // Valid only when type == FILE. |
| 779 const std::string& file_id() const { |
| 780 DCHECK_EQ(FILE, type_); |
| 781 return file_id_; |
| 782 } |
| 770 | 783 |
| 771 // Returns true if this file is deleted in the change. | 784 // Returns true if this file is deleted in the change. |
| 772 bool is_deleted() const { return deleted_; } | 785 bool is_deleted() const { return deleted_; } |
| 773 | 786 |
| 774 // Returns FileResource of the file which the change refers to. | 787 // Returns FileResource of the file which the change refers to. |
| 775 const FileResource* file() const { return file_.get(); } | 788 // Valid only when type == FILE. |
| 776 FileResource* mutable_file() { return file_.get(); } | 789 const FileResource* file() const { |
| 790 DCHECK_EQ(FILE, type_); |
| 791 return file_.get(); |
| 792 } |
| 793 FileResource* mutable_file() { |
| 794 DCHECK_EQ(FILE, type_); |
| 795 return file_.get(); |
| 796 } |
| 797 |
| 798 // Returns TeamDriveResource which the change refers to. |
| 799 // Valid only when type == TEAM_DRIVE. |
| 800 const TeamDriveResource* team_drive() const { |
| 801 DCHECK_EQ(TEAM_DRIVE, type_); |
| 802 return team_drive_.get(); |
| 803 } |
| 804 TeamDriveResource* mutable_team_drive() { |
| 805 DCHECK_EQ(TEAM_DRIVE, type_); |
| 806 return team_drive_.get(); |
| 807 } |
| 808 |
| 809 // Returns the ID of the Team Drive. Valid only when type == TEAM_DRIVE. |
| 810 const std::string& team_drive_id() const { |
| 811 DCHECK_EQ(TEAM_DRIVE, type_); |
| 812 return team_drive_id_; |
| 813 } |
| 777 | 814 |
| 778 // Returns the time of this modification. | 815 // Returns the time of this modification. |
| 779 const base::Time& modification_date() const { return modification_date_; } | 816 const base::Time& modification_date() const { return modification_date_; } |
| 780 | 817 |
| 781 void set_change_id(int64_t change_id) { change_id_ = change_id; } | 818 void set_change_id(int64_t change_id) { change_id_ = change_id; } |
| 819 void set_type(ChangeType type) { type_ = type; } |
| 782 void set_file_id(const std::string& file_id) { | 820 void set_file_id(const std::string& file_id) { |
| 783 file_id_ = file_id; | 821 file_id_ = file_id; |
| 784 } | 822 } |
| 785 void set_deleted(bool deleted) { | 823 void set_deleted(bool deleted) { |
| 786 deleted_ = deleted; | 824 deleted_ = deleted; |
| 787 } | 825 } |
| 788 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); } | 826 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); } |
| 827 void set_team_drive(std::unique_ptr<TeamDriveResource> team_drive) { |
| 828 team_drive_ = std::move(team_drive); |
| 829 } |
| 789 void set_modification_date(const base::Time& modification_date) { | 830 void set_modification_date(const base::Time& modification_date) { |
| 790 modification_date_ = modification_date; | 831 modification_date_ = modification_date; |
| 791 } | 832 } |
| 792 | 833 |
| 793 private: | 834 private: |
| 794 friend class base::internal::RepeatedMessageConverter<ChangeResource>; | 835 friend class base::internal::RepeatedMessageConverter<ChangeResource>; |
| 795 friend class ChangeList; | 836 friend class ChangeList; |
| 796 | 837 |
| 797 // Parses and initializes data members from content of |value|. | 838 // Parses and initializes data members from content of |value|. |
| 798 // Return false if parsing fails. | 839 // Return false if parsing fails. |
| 799 bool Parse(const base::Value& value); | 840 bool Parse(const base::Value& value); |
| 800 | 841 |
| 842 // Extracts the change type from the given string. Returns false and does |
| 843 // not change |result| when |type_name| has an unrecognizable value. |
| 844 static bool GetType(const base::StringPiece& type_name, |
| 845 ChangeResource::ChangeType* result); |
| 846 |
| 801 int64_t change_id_; | 847 int64_t change_id_; |
| 848 ChangeType type_; |
| 802 std::string file_id_; | 849 std::string file_id_; |
| 803 bool deleted_; | 850 bool deleted_; |
| 804 std::unique_ptr<FileResource> file_; | 851 std::unique_ptr<FileResource> file_; |
| 805 base::Time modification_date_; | 852 base::Time modification_date_; |
| 853 std::string team_drive_id_; |
| 854 std::unique_ptr<TeamDriveResource> team_drive_; |
| 806 | 855 |
| 807 DISALLOW_COPY_AND_ASSIGN(ChangeResource); | 856 DISALLOW_COPY_AND_ASSIGN(ChangeResource); |
| 808 }; | 857 }; |
| 809 | 858 |
| 810 // ChangeList represents a set of changes in the drive. | 859 // ChangeList represents a set of changes in the drive. |
| 811 // https://developers.google.com/drive/v2/reference/changes/list | 860 // https://developers.google.com/drive/v2/reference/changes/list |
| 812 class ChangeList { | 861 class ChangeList { |
| 813 public: | 862 public: |
| 814 ChangeList(); | 863 ChangeList(); |
| 815 ~ChangeList(); | 864 ~ChangeList(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 GURL next_link_; | 907 GURL next_link_; |
| 859 int64_t largest_change_id_; | 908 int64_t largest_change_id_; |
| 860 std::vector<std::unique_ptr<ChangeResource>> items_; | 909 std::vector<std::unique_ptr<ChangeResource>> items_; |
| 861 | 910 |
| 862 DISALLOW_COPY_AND_ASSIGN(ChangeList); | 911 DISALLOW_COPY_AND_ASSIGN(ChangeList); |
| 863 }; | 912 }; |
| 864 | 913 |
| 865 } // namespace google_apis | 914 } // namespace google_apis |
| 866 | 915 |
| 867 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 916 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
| OLD | NEW |