| 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> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 14 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 15 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 16 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 17 | 20 |
| 18 namespace base { | 21 namespace base { |
| 19 class Value; | 22 class Value; |
| 20 template <class StructType> | 23 template <class StructType> |
| 21 class JSONValueConverter; | 24 class JSONValueConverter; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 | 40 |
| 38 // Registers the mapping between JSON field names and the members in this | 41 // Registers the mapping between JSON field names and the members in this |
| 39 // class. | 42 // class. |
| 40 static void RegisterJSONConverter( | 43 static void RegisterJSONConverter( |
| 41 base::JSONValueConverter<AboutResource>* converter); | 44 base::JSONValueConverter<AboutResource>* converter); |
| 42 | 45 |
| 43 // Creates about resource from parsed JSON. | 46 // Creates about resource from parsed JSON. |
| 44 static scoped_ptr<AboutResource> CreateFrom(const base::Value& value); | 47 static scoped_ptr<AboutResource> CreateFrom(const base::Value& value); |
| 45 | 48 |
| 46 // Returns the largest change ID number. | 49 // Returns the largest change ID number. |
| 47 int64 largest_change_id() const { return largest_change_id_; } | 50 int64_t largest_change_id() const { return largest_change_id_; } |
| 48 // Returns total number of quota bytes. | 51 // Returns total number of quota bytes. |
| 49 int64 quota_bytes_total() const { return quota_bytes_total_; } | 52 int64_t quota_bytes_total() const { return quota_bytes_total_; } |
| 50 // Returns the number of quota bytes used. | 53 // Returns the number of quota bytes used. |
| 51 int64 quota_bytes_used_aggregate() const { | 54 int64_t quota_bytes_used_aggregate() const { |
| 52 return quota_bytes_used_aggregate_; | 55 return quota_bytes_used_aggregate_; |
| 53 } | 56 } |
| 54 // Returns root folder ID. | 57 // Returns root folder ID. |
| 55 const std::string& root_folder_id() const { return root_folder_id_; } | 58 const std::string& root_folder_id() const { return root_folder_id_; } |
| 56 | 59 |
| 57 void set_largest_change_id(int64 largest_change_id) { | 60 void set_largest_change_id(int64_t largest_change_id) { |
| 58 largest_change_id_ = largest_change_id; | 61 largest_change_id_ = largest_change_id; |
| 59 } | 62 } |
| 60 void set_quota_bytes_total(int64 quota_bytes_total) { | 63 void set_quota_bytes_total(int64_t quota_bytes_total) { |
| 61 quota_bytes_total_ = quota_bytes_total; | 64 quota_bytes_total_ = quota_bytes_total; |
| 62 } | 65 } |
| 63 void set_quota_bytes_used_aggregate(int64 quota_bytes_used_aggregate) { | 66 void set_quota_bytes_used_aggregate(int64_t quota_bytes_used_aggregate) { |
| 64 quota_bytes_used_aggregate_ = quota_bytes_used_aggregate; | 67 quota_bytes_used_aggregate_ = quota_bytes_used_aggregate; |
| 65 } | 68 } |
| 66 void set_root_folder_id(const std::string& root_folder_id) { | 69 void set_root_folder_id(const std::string& root_folder_id) { |
| 67 root_folder_id_ = root_folder_id; | 70 root_folder_id_ = root_folder_id; |
| 68 } | 71 } |
| 69 | 72 |
| 70 private: | 73 private: |
| 71 friend class DriveAPIParserTest; | 74 friend class DriveAPIParserTest; |
| 72 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser); | 75 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser); |
| 73 | 76 |
| 74 // Parses and initializes data members from content of |value|. | 77 // Parses and initializes data members from content of |value|. |
| 75 // Return false if parsing fails. | 78 // Return false if parsing fails. |
| 76 bool Parse(const base::Value& value); | 79 bool Parse(const base::Value& value); |
| 77 | 80 |
| 78 int64 largest_change_id_; | 81 int64_t largest_change_id_; |
| 79 int64 quota_bytes_total_; | 82 int64_t quota_bytes_total_; |
| 80 int64 quota_bytes_used_aggregate_; | 83 int64_t quota_bytes_used_aggregate_; |
| 81 std::string root_folder_id_; | 84 std::string root_folder_id_; |
| 82 | 85 |
| 83 // This class is copyable on purpose. | 86 // This class is copyable on purpose. |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 // DriveAppIcon represents an icon for Drive Application. | 89 // DriveAppIcon represents an icon for Drive Application. |
| 87 // https://developers.google.com/drive/v2/reference/apps | 90 // https://developers.google.com/drive/v2/reference/apps |
| 88 class DriveAppIcon { | 91 class DriveAppIcon { |
| 89 public: | 92 public: |
| 90 enum IconCategory { | 93 enum IconCategory { |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 return shared_with_me_date_; | 492 return shared_with_me_date_; |
| 490 } | 493 } |
| 491 | 494 |
| 492 // Returns the 'shared' attribute of the file. | 495 // Returns the 'shared' attribute of the file. |
| 493 bool shared() const { return shared_; } | 496 bool shared() const { return shared_; } |
| 494 | 497 |
| 495 // Returns MD5 checksum of this file. | 498 // Returns MD5 checksum of this file. |
| 496 const std::string& md5_checksum() const { return md5_checksum_; } | 499 const std::string& md5_checksum() const { return md5_checksum_; } |
| 497 | 500 |
| 498 // Returns the size of this file in bytes. | 501 // Returns the size of this file in bytes. |
| 499 int64 file_size() const { return file_size_; } | 502 int64_t file_size() const { return file_size_; } |
| 500 | 503 |
| 501 // Return the link to open the file in Google editor or viewer. | 504 // Return the link to open the file in Google editor or viewer. |
| 502 // E.g. Google Document, Google Spreadsheet. | 505 // E.g. Google Document, Google Spreadsheet. |
| 503 const GURL& alternate_link() const { return alternate_link_; } | 506 const GURL& alternate_link() const { return alternate_link_; } |
| 504 | 507 |
| 505 // Returns URL to the share dialog UI. | 508 // Returns URL to the share dialog UI. |
| 506 const GURL& share_link() const { return share_link_; } | 509 const GURL& share_link() const { return share_link_; } |
| 507 | 510 |
| 508 // Returns parent references (directories) of this file. | 511 // Returns parent references (directories) of this file. |
| 509 const std::vector<ParentReference>& parents() const { return parents_; } | 512 const std::vector<ParentReference>& parents() const { return parents_; } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 } | 545 } |
| 543 void set_shared_with_me_date(const base::Time& shared_with_me_date) { | 546 void set_shared_with_me_date(const base::Time& shared_with_me_date) { |
| 544 shared_with_me_date_ = shared_with_me_date; | 547 shared_with_me_date_ = shared_with_me_date; |
| 545 } | 548 } |
| 546 void set_shared(bool shared) { | 549 void set_shared(bool shared) { |
| 547 shared_ = shared; | 550 shared_ = shared; |
| 548 } | 551 } |
| 549 void set_md5_checksum(const std::string& md5_checksum) { | 552 void set_md5_checksum(const std::string& md5_checksum) { |
| 550 md5_checksum_ = md5_checksum; | 553 md5_checksum_ = md5_checksum; |
| 551 } | 554 } |
| 552 void set_file_size(int64 file_size) { | 555 void set_file_size(int64_t file_size) { file_size_ = file_size; } |
| 553 file_size_ = file_size; | |
| 554 } | |
| 555 void set_alternate_link(const GURL& alternate_link) { | 556 void set_alternate_link(const GURL& alternate_link) { |
| 556 alternate_link_ = alternate_link; | 557 alternate_link_ = alternate_link; |
| 557 } | 558 } |
| 558 void set_share_link(const GURL& share_link) { | 559 void set_share_link(const GURL& share_link) { |
| 559 share_link_ = share_link; | 560 share_link_ = share_link; |
| 560 } | 561 } |
| 561 std::vector<ParentReference>* mutable_parents() { return &parents_; } | 562 std::vector<ParentReference>* mutable_parents() { return &parents_; } |
| 562 std::vector<OpenWithLink>* mutable_open_with_links() { | 563 std::vector<OpenWithLink>* mutable_open_with_links() { |
| 563 return &open_with_links_; | 564 return &open_with_links_; |
| 564 } | 565 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 577 std::string title_; | 578 std::string title_; |
| 578 std::string mime_type_; | 579 std::string mime_type_; |
| 579 FileLabels labels_; | 580 FileLabels labels_; |
| 580 ImageMediaMetadata image_media_metadata_; | 581 ImageMediaMetadata image_media_metadata_; |
| 581 base::Time created_date_; | 582 base::Time created_date_; |
| 582 base::Time modified_date_; | 583 base::Time modified_date_; |
| 583 base::Time last_viewed_by_me_date_; | 584 base::Time last_viewed_by_me_date_; |
| 584 base::Time shared_with_me_date_; | 585 base::Time shared_with_me_date_; |
| 585 bool shared_; | 586 bool shared_; |
| 586 std::string md5_checksum_; | 587 std::string md5_checksum_; |
| 587 int64 file_size_; | 588 int64_t file_size_; |
| 588 GURL alternate_link_; | 589 GURL alternate_link_; |
| 589 GURL share_link_; | 590 GURL share_link_; |
| 590 std::vector<ParentReference> parents_; | 591 std::vector<ParentReference> parents_; |
| 591 std::vector<OpenWithLink> open_with_links_; | 592 std::vector<OpenWithLink> open_with_links_; |
| 592 }; | 593 }; |
| 593 | 594 |
| 594 // FileList represents a collection of files and folders. | 595 // FileList represents a collection of files and folders. |
| 595 // https://developers.google.com/drive/v2/reference/files/list | 596 // https://developers.google.com/drive/v2/reference/files/list |
| 596 class FileList { | 597 class FileList { |
| 597 public: | 598 public: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // Registers the mapping between JSON field names and the members in this | 646 // Registers the mapping between JSON field names and the members in this |
| 646 // class. | 647 // class. |
| 647 static void RegisterJSONConverter( | 648 static void RegisterJSONConverter( |
| 648 base::JSONValueConverter<ChangeResource>* converter); | 649 base::JSONValueConverter<ChangeResource>* converter); |
| 649 | 650 |
| 650 // Creates change resource from parsed JSON. | 651 // Creates change resource from parsed JSON. |
| 651 static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value); | 652 static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value); |
| 652 | 653 |
| 653 // Returns change ID for this change. This is a monotonically increasing | 654 // Returns change ID for this change. This is a monotonically increasing |
| 654 // number. | 655 // number. |
| 655 int64 change_id() const { return change_id_; } | 656 int64_t change_id() const { return change_id_; } |
| 656 | 657 |
| 657 // Returns a string file ID for corresponding file of the change. | 658 // Returns a string file ID for corresponding file of the change. |
| 658 const std::string& file_id() const { return file_id_; } | 659 const std::string& file_id() const { return file_id_; } |
| 659 | 660 |
| 660 // Returns true if this file is deleted in the change. | 661 // Returns true if this file is deleted in the change. |
| 661 bool is_deleted() const { return deleted_; } | 662 bool is_deleted() const { return deleted_; } |
| 662 | 663 |
| 663 // Returns FileResource of the file which the change refers to. | 664 // Returns FileResource of the file which the change refers to. |
| 664 const FileResource* file() const { return file_.get(); } | 665 const FileResource* file() const { return file_.get(); } |
| 665 FileResource* mutable_file() { return file_.get(); } | 666 FileResource* mutable_file() { return file_.get(); } |
| 666 | 667 |
| 667 // Returns the time of this modification. | 668 // Returns the time of this modification. |
| 668 const base::Time& modification_date() const { return modification_date_; } | 669 const base::Time& modification_date() const { return modification_date_; } |
| 669 | 670 |
| 670 void set_change_id(int64 change_id) { | 671 void set_change_id(int64_t change_id) { change_id_ = change_id; } |
| 671 change_id_ = change_id; | |
| 672 } | |
| 673 void set_file_id(const std::string& file_id) { | 672 void set_file_id(const std::string& file_id) { |
| 674 file_id_ = file_id; | 673 file_id_ = file_id; |
| 675 } | 674 } |
| 676 void set_deleted(bool deleted) { | 675 void set_deleted(bool deleted) { |
| 677 deleted_ = deleted; | 676 deleted_ = deleted; |
| 678 } | 677 } |
| 679 void set_file(scoped_ptr<FileResource> file) { | 678 void set_file(scoped_ptr<FileResource> file) { |
| 680 file_ = file.Pass(); | 679 file_ = file.Pass(); |
| 681 } | 680 } |
| 682 void set_modification_date(const base::Time& modification_date) { | 681 void set_modification_date(const base::Time& modification_date) { |
| 683 modification_date_ = modification_date; | 682 modification_date_ = modification_date; |
| 684 } | 683 } |
| 685 | 684 |
| 686 private: | 685 private: |
| 687 friend class base::internal::RepeatedMessageConverter<ChangeResource>; | 686 friend class base::internal::RepeatedMessageConverter<ChangeResource>; |
| 688 friend class ChangeList; | 687 friend class ChangeList; |
| 689 | 688 |
| 690 // Parses and initializes data members from content of |value|. | 689 // Parses and initializes data members from content of |value|. |
| 691 // Return false if parsing fails. | 690 // Return false if parsing fails. |
| 692 bool Parse(const base::Value& value); | 691 bool Parse(const base::Value& value); |
| 693 | 692 |
| 694 int64 change_id_; | 693 int64_t change_id_; |
| 695 std::string file_id_; | 694 std::string file_id_; |
| 696 bool deleted_; | 695 bool deleted_; |
| 697 scoped_ptr<FileResource> file_; | 696 scoped_ptr<FileResource> file_; |
| 698 base::Time modification_date_; | 697 base::Time modification_date_; |
| 699 | 698 |
| 700 DISALLOW_COPY_AND_ASSIGN(ChangeResource); | 699 DISALLOW_COPY_AND_ASSIGN(ChangeResource); |
| 701 }; | 700 }; |
| 702 | 701 |
| 703 // ChangeList represents a set of changes in the drive. | 702 // ChangeList represents a set of changes in the drive. |
| 704 // https://developers.google.com/drive/v2/reference/changes/list | 703 // https://developers.google.com/drive/v2/reference/changes/list |
| (...skipping 11 matching lines...) Expand all Loading... |
| 716 static bool HasChangeListKind(const base::Value& value); | 715 static bool HasChangeListKind(const base::Value& value); |
| 717 | 716 |
| 718 // Creates change list from parsed JSON. | 717 // Creates change list from parsed JSON. |
| 719 static scoped_ptr<ChangeList> CreateFrom(const base::Value& value); | 718 static scoped_ptr<ChangeList> CreateFrom(const base::Value& value); |
| 720 | 719 |
| 721 // Returns a link to the next page of files. The URL includes the next page | 720 // Returns a link to the next page of files. The URL includes the next page |
| 722 // token. | 721 // token. |
| 723 const GURL& next_link() const { return next_link_; } | 722 const GURL& next_link() const { return next_link_; } |
| 724 | 723 |
| 725 // Returns the largest change ID number. | 724 // Returns the largest change ID number. |
| 726 int64 largest_change_id() const { return largest_change_id_; } | 725 int64_t largest_change_id() const { return largest_change_id_; } |
| 727 | 726 |
| 728 // Returns a set of changes in this list. | 727 // Returns a set of changes in this list. |
| 729 const ScopedVector<ChangeResource>& items() const { return items_; } | 728 const ScopedVector<ChangeResource>& items() const { return items_; } |
| 730 ScopedVector<ChangeResource>* mutable_items() { return &items_; } | 729 ScopedVector<ChangeResource>* mutable_items() { return &items_; } |
| 731 | 730 |
| 732 void set_next_link(const GURL& next_link) { | 731 void set_next_link(const GURL& next_link) { |
| 733 next_link_ = next_link; | 732 next_link_ = next_link; |
| 734 } | 733 } |
| 735 void set_largest_change_id(int64 largest_change_id) { | 734 void set_largest_change_id(int64_t largest_change_id) { |
| 736 largest_change_id_ = largest_change_id; | 735 largest_change_id_ = largest_change_id; |
| 737 } | 736 } |
| 738 | 737 |
| 739 private: | 738 private: |
| 740 friend class DriveAPIParserTest; | 739 friend class DriveAPIParserTest; |
| 741 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); | 740 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); |
| 742 | 741 |
| 743 // Parses and initializes data members from content of |value|. | 742 // Parses and initializes data members from content of |value|. |
| 744 // Return false if parsing fails. | 743 // Return false if parsing fails. |
| 745 bool Parse(const base::Value& value); | 744 bool Parse(const base::Value& value); |
| 746 | 745 |
| 747 GURL next_link_; | 746 GURL next_link_; |
| 748 int64 largest_change_id_; | 747 int64_t largest_change_id_; |
| 749 ScopedVector<ChangeResource> items_; | 748 ScopedVector<ChangeResource> items_; |
| 750 | 749 |
| 751 DISALLOW_COPY_AND_ASSIGN(ChangeList); | 750 DISALLOW_COPY_AND_ASSIGN(ChangeList); |
| 752 }; | 751 }; |
| 753 | 752 |
| 754 } // namespace google_apis | 753 } // namespace google_apis |
| 755 | 754 |
| 756 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 755 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
| OLD | NEW |