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 #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 10 matching lines...) Expand all Loading... | |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int64_t kUnsetFileSize = -1; | 23 const int64_t kUnsetFileSize = -1; |
24 | 24 |
25 bool CreateFileResourceFromValue(const base::Value* value, | 25 bool CreateFileResourceFromValue(const base::Value* value, |
26 std::unique_ptr<FileResource>* file) { | 26 std::unique_ptr<FileResource>* file) { |
27 *file = FileResource::CreateFrom(*value); | 27 *file = FileResource::CreateFrom(*value); |
28 return !!*file; | 28 return !!*file; |
29 } | 29 } |
30 | 30 |
31 bool CreateTeamDriveResourceFromValue( | |
32 const base::Value* value, | |
33 std::unique_ptr<TeamDriveResource>* file) { | |
34 *file = TeamDriveResource::CreateFrom(*value); | |
35 return !!*file; | |
36 } | |
37 | |
31 // Converts |url_string| to |result|. Always returns true to be used | 38 // Converts |url_string| to |result|. Always returns true to be used |
32 // for JSONValueConverter::RegisterCustomField method. | 39 // for JSONValueConverter::RegisterCustomField method. |
33 // TODO(mukai): make it return false in case of invalid |url_string|. | 40 // TODO(mukai): make it return false in case of invalid |url_string|. |
34 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { | 41 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { |
35 *result = GURL(url_string); | 42 *result = GURL(url_string); |
36 return true; | 43 return true; |
37 } | 44 } |
38 | 45 |
39 // Converts |value| to |result|. | 46 // Converts |value| to |result|. |
40 bool GetParentsFromValue(const base::Value* value, | 47 bool GetParentsFromValue(const base::Value* value, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 const char kCanShare[] = "canShare"; | 191 const char kCanShare[] = "canShare"; |
185 | 192 |
186 // Files List | 193 // Files List |
187 // https://developers.google.com/drive/v2/reference/files/list | 194 // https://developers.google.com/drive/v2/reference/files/list |
188 const char kFileListKind[] = "drive#fileList"; | 195 const char kFileListKind[] = "drive#fileList"; |
189 const char kNextLink[] = "nextLink"; | 196 const char kNextLink[] = "nextLink"; |
190 | 197 |
191 // Change Resource | 198 // Change Resource |
192 // https://developers.google.com/drive/v2/reference/changes | 199 // https://developers.google.com/drive/v2/reference/changes |
193 const char kChangeKind[] = "drive#change"; | 200 const char kChangeKind[] = "drive#change"; |
201 const char kType[] = "type"; | |
194 const char kFileId[] = "fileId"; | 202 const char kFileId[] = "fileId"; |
195 const char kDeleted[] = "deleted"; | 203 const char kDeleted[] = "deleted"; |
196 const char kFile[] = "file"; | 204 const char kFile[] = "file"; |
205 const char kTeamDrive[] = "teamDrive"; | |
206 const char kTeamDriveId[] = "teamDriveId"; | |
197 | 207 |
198 // Changes List | 208 // Changes List |
199 // https://developers.google.com/drive/v2/reference/changes/list | 209 // https://developers.google.com/drive/v2/reference/changes/list |
200 const char kChangeListKind[] = "drive#changeList"; | 210 const char kChangeListKind[] = "drive#changeList"; |
201 | 211 |
212 // Maps category name to enum ChangeType. | |
213 struct ChangeTypeMap { | |
214 ChangeResource::ChangeType type; | |
215 const char* type_name; | |
216 }; | |
217 | |
218 constexpr ChangeTypeMap kChangeTypeMap[] = { | |
219 { ChangeResource::FILE, "file" }, | |
220 { ChangeResource::TEAM_DRIVE, "teamDrive" }, | |
221 }; | |
222 | |
202 // Maps category name to enum IconCategory. | 223 // Maps category name to enum IconCategory. |
203 struct AppIconCategoryMap { | 224 struct AppIconCategoryMap { |
204 DriveAppIcon::IconCategory category; | 225 DriveAppIcon::IconCategory category; |
205 const char* category_name; | 226 const char* category_name; |
206 }; | 227 }; |
207 | 228 |
208 const AppIconCategoryMap kAppIconCategoryMap[] = { | 229 constexpr AppIconCategoryMap kAppIconCategoryMap[] = { |
209 { DriveAppIcon::DOCUMENT, "document" }, | 230 { DriveAppIcon::DOCUMENT, "document" }, |
210 { DriveAppIcon::APPLICATION, "application" }, | 231 { DriveAppIcon::APPLICATION, "application" }, |
211 { DriveAppIcon::SHARED_DOCUMENT, "documentShared" }, | 232 { DriveAppIcon::SHARED_DOCUMENT, "documentShared" }, |
212 }; | 233 }; |
213 | 234 |
214 // Checks if the JSON is expected kind. In Drive API, JSON data structure has | 235 // Checks if the JSON is expected kind. In Drive API, JSON data structure has |
215 // |kind| property which denotes the type of the structure (e.g. "drive#file"). | 236 // |kind| property which denotes the type of the structure (e.g. "drive#file"). |
216 bool IsResourceKindExpected(const base::Value& value, | 237 bool IsResourceKindExpected(const base::Value& value, |
217 const std::string& expected_kind) { | 238 const std::string& expected_kind) { |
218 const base::DictionaryValue* as_dict = NULL; | 239 const base::DictionaryValue* as_dict = NULL; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 can_edit_(false), | 443 can_edit_(false), |
423 can_list_children_(false), | 444 can_list_children_(false), |
424 can_manage_members_(false), | 445 can_manage_members_(false), |
425 can_read_revisions_(false), | 446 can_read_revisions_(false), |
426 can_remove_children_(false), | 447 can_remove_children_(false), |
427 can_rename_(false), | 448 can_rename_(false), |
428 can_rename_team_drive_(false), | 449 can_rename_team_drive_(false), |
429 can_share_(false) { | 450 can_share_(false) { |
430 } | 451 } |
431 | 452 |
453 TeamDriveCapabilities::TeamDriveCapabilities(const TeamDriveCapabilities& src) = | |
454 default; | |
455 | |
432 TeamDriveCapabilities::~TeamDriveCapabilities(){} | 456 TeamDriveCapabilities::~TeamDriveCapabilities(){} |
433 | 457 |
434 // static | 458 // static |
435 void TeamDriveCapabilities::RegisterJSONConverter( | 459 void TeamDriveCapabilities::RegisterJSONConverter( |
436 base::JSONValueConverter<TeamDriveCapabilities>* converter) { | 460 base::JSONValueConverter<TeamDriveCapabilities>* converter) { |
437 converter->RegisterBoolField(kCanAddChildren, | 461 converter->RegisterBoolField(kCanAddChildren, |
438 &TeamDriveCapabilities::can_add_children_); | 462 &TeamDriveCapabilities::can_add_children_); |
439 converter->RegisterBoolField(kCanComment, | 463 converter->RegisterBoolField(kCanComment, |
440 &TeamDriveCapabilities::can_comment_); | 464 &TeamDriveCapabilities::can_comment_); |
441 converter->RegisterBoolField(kCanCopy, &TeamDriveCapabilities::can_copy_); | 465 converter->RegisterBoolField(kCanCopy, &TeamDriveCapabilities::can_copy_); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 if (!converter.Convert(value, this)) { | 675 if (!converter.Convert(value, this)) { |
652 LOG(ERROR) << "Unable to parse: Invalid FileList"; | 676 LOG(ERROR) << "Unable to parse: Invalid FileList"; |
653 return false; | 677 return false; |
654 } | 678 } |
655 return true; | 679 return true; |
656 } | 680 } |
657 | 681 |
658 //////////////////////////////////////////////////////////////////////////////// | 682 //////////////////////////////////////////////////////////////////////////////// |
659 // ChangeResource implementation | 683 // ChangeResource implementation |
660 | 684 |
661 ChangeResource::ChangeResource() : change_id_(0), deleted_(false) {} | 685 // |type_| defaults to |FILE| rather than |UNKONWON| to keep backward |
686 // compatibility, because Change resource only stored file changes and didn't | |
687 // have the field before. There are also logic in many unit tests depending on | |
688 // that. | |
689 // TODO(yamaguchi): Revise all unit tests that handle ChangeResource and make | |
690 // type_ default to UNKNOWN. | |
691 ChangeResource::ChangeResource() | |
692 : change_id_(0), type_(FILE), deleted_(false) {} | |
hashimoto
2017/03/24 08:49:23
You are already fixing a number of tests.
Do we st
yamaguchi
2017/03/24 12:15:21
At least, 5 tests inside FileCacheTest fails if we
hashimoto
2017/03/27 08:47:41
FileCache should have nothing to do with ChangeRes
yamaguchi
2017/03/27 13:51:06
Now I found that those failures are not something
| |
662 | 693 |
663 ChangeResource::~ChangeResource() {} | 694 ChangeResource::~ChangeResource() {} |
664 | 695 |
665 // static | 696 // static |
666 void ChangeResource::RegisterJSONConverter( | 697 void ChangeResource::RegisterJSONConverter( |
667 base::JSONValueConverter<ChangeResource>* converter) { | 698 base::JSONValueConverter<ChangeResource>* converter) { |
668 converter->RegisterCustomField<int64_t>(kId, &ChangeResource::change_id_, | 699 converter->RegisterCustomField<int64_t>(kId, &ChangeResource::change_id_, |
669 &base::StringToInt64); | 700 &base::StringToInt64); |
701 converter->RegisterCustomField<ChangeType>(kType, &ChangeResource::type_, | |
702 &ChangeResource::GetType); | |
670 converter->RegisterStringField(kFileId, &ChangeResource::file_id_); | 703 converter->RegisterStringField(kFileId, &ChangeResource::file_id_); |
671 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); | 704 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); |
672 converter->RegisterCustomValueField(kFile, &ChangeResource::file_, | 705 converter->RegisterCustomValueField(kFile, &ChangeResource::file_, |
673 &CreateFileResourceFromValue); | 706 &CreateFileResourceFromValue); |
674 converter->RegisterCustomField<base::Time>( | 707 converter->RegisterCustomField<base::Time>( |
675 kModificationDate, &ChangeResource::modification_date_, | 708 kModificationDate, &ChangeResource::modification_date_, |
676 &util::GetTimeFromString); | 709 &util::GetTimeFromString); |
710 converter->RegisterStringField(kTeamDriveId, &ChangeResource::team_drive_id_); | |
711 converter->RegisterCustomValueField(kTeamDrive, &ChangeResource::team_drive_, | |
712 &CreateTeamDriveResourceFromValue); | |
677 } | 713 } |
678 | 714 |
679 // static | 715 // static |
680 std::unique_ptr<ChangeResource> ChangeResource::CreateFrom( | 716 std::unique_ptr<ChangeResource> ChangeResource::CreateFrom( |
681 const base::Value& value) { | 717 const base::Value& value) { |
682 std::unique_ptr<ChangeResource> resource(new ChangeResource()); | 718 std::unique_ptr<ChangeResource> resource(new ChangeResource()); |
683 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { | 719 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { |
684 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; | 720 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; |
685 return std::unique_ptr<ChangeResource>(); | 721 return std::unique_ptr<ChangeResource>(); |
686 } | 722 } |
687 return resource; | 723 return resource; |
688 } | 724 } |
689 | 725 |
690 bool ChangeResource::Parse(const base::Value& value) { | 726 bool ChangeResource::Parse(const base::Value& value) { |
691 base::JSONValueConverter<ChangeResource> converter; | 727 base::JSONValueConverter<ChangeResource> converter; |
692 if (!converter.Convert(value, this)) { | 728 if (!converter.Convert(value, this)) { |
693 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; | 729 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; |
694 return false; | 730 return false; |
695 } | 731 } |
696 return true; | 732 return true; |
697 } | 733 } |
698 | 734 |
735 // static | |
736 bool ChangeResource::GetType(const base::StringPiece& type_name, | |
737 ChangeResource::ChangeType* result) { | |
738 for (size_t i = 0; i < arraysize(kChangeTypeMap); i++) { | |
739 if (type_name == kChangeTypeMap[i].type_name) { | |
740 *result = kChangeTypeMap[i].type; | |
741 return true; | |
742 } | |
743 } | |
744 DVLOG(1) << "Unknown change type" << type_name; | |
745 return false; | |
746 } | |
747 | |
699 //////////////////////////////////////////////////////////////////////////////// | 748 //////////////////////////////////////////////////////////////////////////////// |
700 // ChangeList implementation | 749 // ChangeList implementation |
701 | 750 |
702 ChangeList::ChangeList() : largest_change_id_(0) {} | 751 ChangeList::ChangeList() : largest_change_id_(0) {} |
703 | 752 |
704 ChangeList::~ChangeList() {} | 753 ChangeList::~ChangeList() {} |
705 | 754 |
706 // static | 755 // static |
707 void ChangeList::RegisterJSONConverter( | 756 void ChangeList::RegisterJSONConverter( |
708 base::JSONValueConverter<ChangeList>* converter) { | 757 base::JSONValueConverter<ChangeList>* converter) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 bool ImageMediaMetadata::Parse(const base::Value& value) { | 859 bool ImageMediaMetadata::Parse(const base::Value& value) { |
811 base::JSONValueConverter<ImageMediaMetadata> converter; | 860 base::JSONValueConverter<ImageMediaMetadata> converter; |
812 if (!converter.Convert(value, this)) { | 861 if (!converter.Convert(value, this)) { |
813 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; | 862 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; |
814 return false; | 863 return false; |
815 } | 864 } |
816 return true; | 865 return true; |
817 } | 866 } |
818 | 867 |
819 } // namespace google_apis | 868 } // namespace google_apis |
OLD | NEW |