Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: google_apis/drive/drive_api_parser.h

Issue 2748053005: Parse TeamDrive resource inside ChangeList. (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
777 // Filled only when type == FILE.
hashimoto 2017/03/22 06:40:30 What does "filled" here mean? Please use a more sp
yamaguchi 2017/03/22 07:30:36 It means uninitialized. Also added DCHECK.
769 const std::string& file_id() const { return file_id_; } 778 const std::string& file_id() const { return file_id_; }
770 779
771 // Returns true if this file is deleted in the change. 780 // Returns true if this file is deleted in the change.
772 bool is_deleted() const { return deleted_; } 781 bool is_deleted() const { return deleted_; }
773 782
774 // Returns FileResource of the file which the change refers to. 783 // Returns FileResource of the file which the change refers to.
784 // Filled only when type == FILE.
hashimoto 2017/03/22 06:40:30 "Filled" here is ambiguous. If type != FILE, it's
yamaguchi 2017/03/22 07:30:36 It'll be empty (owns nothing). Added DCHECK.
775 const FileResource* file() const { return file_.get(); } 785 const FileResource* file() const { return file_.get(); }
776 FileResource* mutable_file() { return file_.get(); } 786 FileResource* mutable_file() { return file_.get(); }
777 787
788 // Returns TeamDriveResource which the change refers to.
789 // Filled only when type == TEAM_DRIVE.
hashimoto 2017/03/22 06:40:30 ditto.
yamaguchi 2017/03/22 07:30:36 Done.
790 const TeamDriveResource* team_drive() const { return team_drive_.get(); }
791 TeamDriveResource* mutable_team_drive() { return team_drive_.get(); }
792
793 // Returns the ID of the Team Drive. Filled only when type == TEAM_DRIVE.
hashimoto 2017/03/22 06:40:30 ditto.
yamaguchi 2017/03/22 07:30:36 Done.
794 const std::string& team_drive_id() const { return team_drive_id_; }
795
778 // Returns the time of this modification. 796 // Returns the time of this modification.
779 const base::Time& modification_date() const { return modification_date_; } 797 const base::Time& modification_date() const { return modification_date_; }
780 798
781 void set_change_id(int64_t change_id) { change_id_ = change_id; } 799 void set_change_id(int64_t change_id) { change_id_ = change_id; }
782 void set_file_id(const std::string& file_id) { 800 void set_file_id(const std::string& file_id) {
783 file_id_ = file_id; 801 file_id_ = file_id;
784 } 802 }
785 void set_deleted(bool deleted) { 803 void set_deleted(bool deleted) {
786 deleted_ = deleted; 804 deleted_ = deleted;
787 } 805 }
788 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); } 806 void set_file(std::unique_ptr<FileResource> file) { file_ = std::move(file); }
789 void set_modification_date(const base::Time& modification_date) { 807 void set_modification_date(const base::Time& modification_date) {
790 modification_date_ = modification_date; 808 modification_date_ = modification_date;
791 } 809 }
792 810
793 private: 811 private:
794 friend class base::internal::RepeatedMessageConverter<ChangeResource>; 812 friend class base::internal::RepeatedMessageConverter<ChangeResource>;
795 friend class ChangeList; 813 friend class ChangeList;
796 814
797 // Parses and initializes data members from content of |value|. 815 // Parses and initializes data members from content of |value|.
798 // Return false if parsing fails. 816 // Return false if parsing fails.
799 bool Parse(const base::Value& value); 817 bool Parse(const base::Value& value);
800 818
819 // Extracts the change type from the given string. Returns false and does
820 // not change |result| when |type_name| has an unrecognizable value.
821 static bool GetType(const base::StringPiece& type_name,
822 ChangeResource::ChangeType* result);
823
801 int64_t change_id_; 824 int64_t change_id_;
825 ChangeType type_;
802 std::string file_id_; 826 std::string file_id_;
803 bool deleted_; 827 bool deleted_;
804 std::unique_ptr<FileResource> file_; 828 std::unique_ptr<FileResource> file_;
805 base::Time modification_date_; 829 base::Time modification_date_;
830 std::string team_drive_id_;
831 std::unique_ptr<TeamDriveResource> team_drive_;
806 832
807 DISALLOW_COPY_AND_ASSIGN(ChangeResource); 833 DISALLOW_COPY_AND_ASSIGN(ChangeResource);
808 }; 834 };
809 835
810 // ChangeList represents a set of changes in the drive. 836 // ChangeList represents a set of changes in the drive.
811 // https://developers.google.com/drive/v2/reference/changes/list 837 // https://developers.google.com/drive/v2/reference/changes/list
812 class ChangeList { 838 class ChangeList {
813 public: 839 public:
814 ChangeList(); 840 ChangeList();
815 ~ChangeList(); 841 ~ChangeList();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 GURL next_link_; 884 GURL next_link_;
859 int64_t largest_change_id_; 885 int64_t largest_change_id_;
860 std::vector<std::unique_ptr<ChangeResource>> items_; 886 std::vector<std::unique_ptr<ChangeResource>> items_;
861 887
862 DISALLOW_COPY_AND_ASSIGN(ChangeList); 888 DISALLOW_COPY_AND_ASSIGN(ChangeList);
863 }; 889 };
864 890
865 } // namespace google_apis 891 } // namespace google_apis
866 892
867 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ 893 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698