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

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

Issue 2885323002: Add URL generator / json parser for getting start_page_token of changes. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « google_apis/drive/drive_api_parser.h ('k') | google_apis/drive/drive_api_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "google_apis/drive/drive_api_parser.h" 5 #include "google_apis/drive/drive_api_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 const char kFileId[] = "fileId"; 204 const char kFileId[] = "fileId";
205 const char kDeleted[] = "deleted"; 205 const char kDeleted[] = "deleted";
206 const char kFile[] = "file"; 206 const char kFile[] = "file";
207 const char kTeamDrive[] = "teamDrive"; 207 const char kTeamDrive[] = "teamDrive";
208 const char kTeamDriveId[] = "teamDriveId"; 208 const char kTeamDriveId[] = "teamDriveId";
209 209
210 // Changes List 210 // Changes List
211 // https://developers.google.com/drive/v2/reference/changes/list 211 // https://developers.google.com/drive/v2/reference/changes/list
212 const char kChangeListKind[] = "drive#changeList"; 212 const char kChangeListKind[] = "drive#changeList";
213 213
214 // Changes StartPageToken
215 // https://developers.google.com/drive/v2/reference/changes/getStartPageToken
216 const char kStartPageTokenKind[] = "drive#startPageToken";
217 const char kStartPageToken[] = "startPageToken";
218
214 // Maps category name to enum ChangeType. 219 // Maps category name to enum ChangeType.
215 struct ChangeTypeMap { 220 struct ChangeTypeMap {
216 ChangeResource::ChangeType type; 221 ChangeResource::ChangeType type;
217 const char* type_name; 222 const char* type_name;
218 }; 223 };
219 224
220 constexpr ChangeTypeMap kChangeTypeMap[] = { 225 constexpr ChangeTypeMap kChangeTypeMap[] = {
221 { ChangeResource::FILE, "file" }, 226 { ChangeResource::FILE, "file" },
222 { ChangeResource::TEAM_DRIVE, "teamDrive" }, 227 { ChangeResource::TEAM_DRIVE, "teamDrive" },
223 }; 228 };
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 if (type_name == kChangeTypeMap[i].type_name) { 781 if (type_name == kChangeTypeMap[i].type_name) {
777 *result = kChangeTypeMap[i].type; 782 *result = kChangeTypeMap[i].type;
778 return true; 783 return true;
779 } 784 }
780 } 785 }
781 DVLOG(1) << "Unknown change type" << type_name; 786 DVLOG(1) << "Unknown change type" << type_name;
782 return false; 787 return false;
783 } 788 }
784 789
785 //////////////////////////////////////////////////////////////////////////////// 790 ////////////////////////////////////////////////////////////////////////////////
791 // StartPageToken implementation
792
793 StartPageToken::StartPageToken() {}
794
795 StartPageToken::~StartPageToken() {}
796
797 // static
798 void StartPageToken::RegisterJSONConverter(
799 base::JSONValueConverter<StartPageToken>* converter) {
800 converter->RegisterStringField(kStartPageToken,
801 &StartPageToken::start_page_token_);
802 }
803
804 // static
805 bool StartPageToken::HasStartPageTokenKind(const base::Value& value) {
806 return IsResourceKindExpected(value, kStartPageTokenKind);
807 }
808
809 // static
810 std::unique_ptr<StartPageToken> StartPageToken::CreateFrom(
811 const base::Value& value) {
812 std::unique_ptr<StartPageToken> resource(new StartPageToken());
813 if (!HasStartPageTokenKind(value) || !resource->Parse(value)) {
814 LOG(ERROR) << "Unable to create: Invalid StartPageToken JSON!";
815 return std::unique_ptr<StartPageToken>();
816 }
817 return resource;
818 }
819
820 bool StartPageToken::Parse(const base::Value& value) {
821 base::JSONValueConverter<StartPageToken> converter;
822 if (!converter.Convert(value, this)) {
823 LOG(ERROR) << "Unable to parse: Invalid StartPageToken";
824 return false;
825 }
826 return true;
827 }
828
829 ////////////////////////////////////////////////////////////////////////////////
786 // ChangeList implementation 830 // ChangeList implementation
787 831
788 ChangeList::ChangeList() : largest_change_id_(0) {} 832 ChangeList::ChangeList() : largest_change_id_(0) {}
789 833
790 ChangeList::~ChangeList() {} 834 ChangeList::~ChangeList() {}
791 835
792 // static 836 // static
793 void ChangeList::RegisterJSONConverter( 837 void ChangeList::RegisterJSONConverter(
794 base::JSONValueConverter<ChangeList>* converter) { 838 base::JSONValueConverter<ChangeList>* converter) {
795 converter->RegisterCustomField<GURL>(kNextLink, 839 converter->RegisterCustomField<GURL>(kNextLink,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 bool ImageMediaMetadata::Parse(const base::Value& value) { 940 bool ImageMediaMetadata::Parse(const base::Value& value) {
897 base::JSONValueConverter<ImageMediaMetadata> converter; 941 base::JSONValueConverter<ImageMediaMetadata> converter;
898 if (!converter.Convert(value, this)) { 942 if (!converter.Convert(value, this)) {
899 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; 943 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata.";
900 return false; 944 return false;
901 } 945 }
902 return true; 946 return true;
903 } 947 }
904 948
905 } // namespace google_apis 949 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_parser.h ('k') | google_apis/drive/drive_api_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698