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 "chrome/browser/google_apis/drive_api_parser.h" | 5 #include "chrome/browser/google_apis/drive_api_parser.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 quota_bytes_total_(0), | 216 quota_bytes_total_(0), |
217 quota_bytes_used_(0) {} | 217 quota_bytes_used_(0) {} |
218 | 218 |
219 AboutResource::~AboutResource() {} | 219 AboutResource::~AboutResource() {} |
220 | 220 |
221 // static | 221 // static |
222 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { | 222 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { |
223 scoped_ptr<AboutResource> resource(new AboutResource()); | 223 scoped_ptr<AboutResource> resource(new AboutResource()); |
224 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { | 224 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { |
225 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; | 225 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; |
226 return scoped_ptr<AboutResource>(NULL); | 226 return scoped_ptr<AboutResource>(); |
227 } | 227 } |
228 return resource.Pass(); | 228 return resource.Pass(); |
229 } | 229 } |
230 | 230 |
231 // static | 231 // static |
232 scoped_ptr<AboutResource> AboutResource::CreateFromAccountMetadata( | 232 scoped_ptr<AboutResource> AboutResource::CreateFromAccountMetadata( |
233 const AccountMetadata& account_metadata, | 233 const AccountMetadata& account_metadata, |
234 const std::string& root_resource_id) { | 234 const std::string& root_resource_id) { |
235 scoped_ptr<AboutResource> resource(new AboutResource); | 235 scoped_ptr<AboutResource> resource(new AboutResource); |
236 resource->set_largest_change_id(account_metadata.largest_changestamp()); | 236 resource->set_largest_change_id(account_metadata.largest_changestamp()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 converter->RegisterCustomField<GURL>(kIconUrl, | 283 converter->RegisterCustomField<GURL>(kIconUrl, |
284 &DriveAppIcon::icon_url_, | 284 &DriveAppIcon::icon_url_, |
285 GetGURLFromString); | 285 GetGURLFromString); |
286 } | 286 } |
287 | 287 |
288 // static | 288 // static |
289 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFrom(const base::Value& value) { | 289 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFrom(const base::Value& value) { |
290 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon()); | 290 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon()); |
291 if (!resource->Parse(value)) { | 291 if (!resource->Parse(value)) { |
292 LOG(ERROR) << "Unable to create: Invalid DriveAppIcon JSON!"; | 292 LOG(ERROR) << "Unable to create: Invalid DriveAppIcon JSON!"; |
293 return scoped_ptr<DriveAppIcon>(NULL); | 293 return scoped_ptr<DriveAppIcon>(); |
294 } | 294 } |
295 return resource.Pass(); | 295 return resource.Pass(); |
296 } | 296 } |
297 | 297 |
298 // static | 298 // static |
299 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFromAppIcon( | 299 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFromAppIcon( |
300 const AppIcon& app_icon) { | 300 const AppIcon& app_icon) { |
301 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon); | 301 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon); |
302 switch (app_icon.category()) { | 302 switch (app_icon.category()) { |
303 case AppIcon::ICON_UNKNOWN: | 303 case AppIcon::ICON_UNKNOWN: |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 converter->RegisterRepeatedString(kSecondaryFileExtensions, | 377 converter->RegisterRepeatedString(kSecondaryFileExtensions, |
378 &AppResource::secondary_file_extensions_); | 378 &AppResource::secondary_file_extensions_); |
379 converter->RegisterRepeatedMessage(kIcons, &AppResource::icons_); | 379 converter->RegisterRepeatedMessage(kIcons, &AppResource::icons_); |
380 } | 380 } |
381 | 381 |
382 // static | 382 // static |
383 scoped_ptr<AppResource> AppResource::CreateFrom(const base::Value& value) { | 383 scoped_ptr<AppResource> AppResource::CreateFrom(const base::Value& value) { |
384 scoped_ptr<AppResource> resource(new AppResource()); | 384 scoped_ptr<AppResource> resource(new AppResource()); |
385 if (!IsResourceKindExpected(value, kAppKind) || !resource->Parse(value)) { | 385 if (!IsResourceKindExpected(value, kAppKind) || !resource->Parse(value)) { |
386 LOG(ERROR) << "Unable to create: Invalid AppResource JSON!"; | 386 LOG(ERROR) << "Unable to create: Invalid AppResource JSON!"; |
387 return scoped_ptr<AppResource>(NULL); | 387 return scoped_ptr<AppResource>(); |
388 } | 388 } |
389 return resource.Pass(); | 389 return resource.Pass(); |
390 } | 390 } |
391 | 391 |
392 // static | 392 // static |
393 scoped_ptr<AppResource> AppResource::CreateFromInstalledApp( | 393 scoped_ptr<AppResource> AppResource::CreateFromInstalledApp( |
394 const InstalledApp& installed_app) { | 394 const InstalledApp& installed_app) { |
395 scoped_ptr<AppResource> resource(new AppResource); | 395 scoped_ptr<AppResource> resource(new AppResource); |
396 resource->set_application_id(installed_app.app_id()); | 396 resource->set_application_id(installed_app.app_id()); |
397 resource->set_name(installed_app.app_name()); | 397 resource->set_name(installed_app.app_name()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 converter->RegisterStringField(kETag, &AppList::etag_); | 459 converter->RegisterStringField(kETag, &AppList::etag_); |
460 converter->RegisterRepeatedMessage<AppResource>(kItems, | 460 converter->RegisterRepeatedMessage<AppResource>(kItems, |
461 &AppList::items_); | 461 &AppList::items_); |
462 } | 462 } |
463 | 463 |
464 // static | 464 // static |
465 scoped_ptr<AppList> AppList::CreateFrom(const base::Value& value) { | 465 scoped_ptr<AppList> AppList::CreateFrom(const base::Value& value) { |
466 scoped_ptr<AppList> resource(new AppList()); | 466 scoped_ptr<AppList> resource(new AppList()); |
467 if (!IsResourceKindExpected(value, kAppListKind) || !resource->Parse(value)) { | 467 if (!IsResourceKindExpected(value, kAppListKind) || !resource->Parse(value)) { |
468 LOG(ERROR) << "Unable to create: Invalid AppList JSON!"; | 468 LOG(ERROR) << "Unable to create: Invalid AppList JSON!"; |
469 return scoped_ptr<AppList>(NULL); | 469 return scoped_ptr<AppList>(); |
470 } | 470 } |
471 return resource.Pass(); | 471 return resource.Pass(); |
472 } | 472 } |
473 | 473 |
474 // static | 474 // static |
475 scoped_ptr<AppList> AppList::CreateFromAccountMetadata( | 475 scoped_ptr<AppList> AppList::CreateFromAccountMetadata( |
476 const AccountMetadata& account_metadata) { | 476 const AccountMetadata& account_metadata) { |
477 scoped_ptr<AppList> resource(new AppList); | 477 scoped_ptr<AppList> resource(new AppList); |
478 | 478 |
479 const ScopedVector<InstalledApp>& installed_apps = | 479 const ScopedVector<InstalledApp>& installed_apps = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); | 517 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); |
518 } | 518 } |
519 | 519 |
520 // static | 520 // static |
521 scoped_ptr<ParentReference> | 521 scoped_ptr<ParentReference> |
522 ParentReference::CreateFrom(const base::Value& value) { | 522 ParentReference::CreateFrom(const base::Value& value) { |
523 scoped_ptr<ParentReference> reference(new ParentReference()); | 523 scoped_ptr<ParentReference> reference(new ParentReference()); |
524 if (!IsResourceKindExpected(value, kParentReferenceKind) || | 524 if (!IsResourceKindExpected(value, kParentReferenceKind) || |
525 !reference->Parse(value)) { | 525 !reference->Parse(value)) { |
526 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; | 526 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; |
527 return scoped_ptr<ParentReference>(NULL); | 527 return scoped_ptr<ParentReference>(); |
528 } | 528 } |
529 return reference.Pass(); | 529 return reference.Pass(); |
530 } | 530 } |
531 | 531 |
532 bool ParentReference::Parse(const base::Value& value) { | 532 bool ParentReference::Parse(const base::Value& value) { |
533 base::JSONValueConverter<ParentReference> converter; | 533 base::JSONValueConverter<ParentReference> converter; |
534 if (!converter.Convert(value, this)) { | 534 if (!converter.Convert(value, this)) { |
535 LOG(ERROR) << "Unable to parse: Invalid ParentReference"; | 535 LOG(ERROR) << "Unable to parse: Invalid ParentReference"; |
536 return false; | 536 return false; |
537 } | 537 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 kOpenWithLinks, | 603 kOpenWithLinks, |
604 &FileResource::open_with_links_, | 604 &FileResource::open_with_links_, |
605 GetOpenWithLinksFromDictionaryValue); | 605 GetOpenWithLinksFromDictionaryValue); |
606 } | 606 } |
607 | 607 |
608 // static | 608 // static |
609 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { | 609 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { |
610 scoped_ptr<FileResource> resource(new FileResource()); | 610 scoped_ptr<FileResource> resource(new FileResource()); |
611 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { | 611 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { |
612 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; | 612 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; |
613 return scoped_ptr<FileResource>(NULL); | 613 return scoped_ptr<FileResource>(); |
614 } | 614 } |
615 return resource.Pass(); | 615 return resource.Pass(); |
616 } | 616 } |
617 | 617 |
618 bool FileResource::IsDirectory() const { | 618 bool FileResource::IsDirectory() const { |
619 return mime_type_ == kDriveFolderMimeType; | 619 return mime_type_ == kDriveFolderMimeType; |
620 } | 620 } |
621 | 621 |
622 DriveEntryKind FileResource::GetKind() const { | 622 DriveEntryKind FileResource::GetKind() const { |
623 if (mime_type() == kGoogleDocumentMimeType) | 623 if (mime_type() == kGoogleDocumentMimeType) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 // static | 668 // static |
669 bool FileList::HasFileListKind(const base::Value& value) { | 669 bool FileList::HasFileListKind(const base::Value& value) { |
670 return IsResourceKindExpected(value, kFileListKind); | 670 return IsResourceKindExpected(value, kFileListKind); |
671 } | 671 } |
672 | 672 |
673 // static | 673 // static |
674 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { | 674 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { |
675 scoped_ptr<FileList> resource(new FileList()); | 675 scoped_ptr<FileList> resource(new FileList()); |
676 if (!HasFileListKind(value) || !resource->Parse(value)) { | 676 if (!HasFileListKind(value) || !resource->Parse(value)) { |
677 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; | 677 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; |
678 return scoped_ptr<FileList>(NULL); | 678 return scoped_ptr<FileList>(); |
679 } | 679 } |
680 return resource.Pass(); | 680 return resource.Pass(); |
681 } | 681 } |
682 | 682 |
683 bool FileList::Parse(const base::Value& value) { | 683 bool FileList::Parse(const base::Value& value) { |
684 base::JSONValueConverter<FileList> converter; | 684 base::JSONValueConverter<FileList> converter; |
685 if (!converter.Convert(value, this)) { | 685 if (!converter.Convert(value, this)) { |
686 LOG(ERROR) << "Unable to parse: Invalid FileList"; | 686 LOG(ERROR) << "Unable to parse: Invalid FileList"; |
687 return false; | 687 return false; |
688 } | 688 } |
(...skipping 17 matching lines...) Expand all Loading... |
706 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); | 706 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); |
707 converter->RegisterNestedField(kFile, &ChangeResource::file_); | 707 converter->RegisterNestedField(kFile, &ChangeResource::file_); |
708 } | 708 } |
709 | 709 |
710 // static | 710 // static |
711 scoped_ptr<ChangeResource> | 711 scoped_ptr<ChangeResource> |
712 ChangeResource::CreateFrom(const base::Value& value) { | 712 ChangeResource::CreateFrom(const base::Value& value) { |
713 scoped_ptr<ChangeResource> resource(new ChangeResource()); | 713 scoped_ptr<ChangeResource> resource(new ChangeResource()); |
714 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { | 714 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { |
715 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; | 715 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; |
716 return scoped_ptr<ChangeResource>(NULL); | 716 return scoped_ptr<ChangeResource>(); |
717 } | 717 } |
718 return resource.Pass(); | 718 return resource.Pass(); |
719 } | 719 } |
720 | 720 |
721 bool ChangeResource::Parse(const base::Value& value) { | 721 bool ChangeResource::Parse(const base::Value& value) { |
722 base::JSONValueConverter<ChangeResource> converter; | 722 base::JSONValueConverter<ChangeResource> converter; |
723 if (!converter.Convert(value, this)) { | 723 if (!converter.Convert(value, this)) { |
724 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; | 724 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; |
725 return false; | 725 return false; |
726 } | 726 } |
(...skipping 25 matching lines...) Expand all Loading... |
752 // static | 752 // static |
753 bool ChangeList::HasChangeListKind(const base::Value& value) { | 753 bool ChangeList::HasChangeListKind(const base::Value& value) { |
754 return IsResourceKindExpected(value, kChangeListKind); | 754 return IsResourceKindExpected(value, kChangeListKind); |
755 } | 755 } |
756 | 756 |
757 // static | 757 // static |
758 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { | 758 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { |
759 scoped_ptr<ChangeList> resource(new ChangeList()); | 759 scoped_ptr<ChangeList> resource(new ChangeList()); |
760 if (!HasChangeListKind(value) || !resource->Parse(value)) { | 760 if (!HasChangeListKind(value) || !resource->Parse(value)) { |
761 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; | 761 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; |
762 return scoped_ptr<ChangeList>(NULL); | 762 return scoped_ptr<ChangeList>(); |
763 } | 763 } |
764 return resource.Pass(); | 764 return resource.Pass(); |
765 } | 765 } |
766 | 766 |
767 bool ChangeList::Parse(const base::Value& value) { | 767 bool ChangeList::Parse(const base::Value& value) { |
768 base::JSONValueConverter<ChangeList> converter; | 768 base::JSONValueConverter<ChangeList> converter; |
769 if (!converter.Convert(value, this)) { | 769 if (!converter.Convert(value, this)) { |
770 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; | 770 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; |
771 return false; | 771 return false; |
772 } | 772 } |
(...skipping 21 matching lines...) Expand all Loading... |
794 converter->RegisterBoolField(kLabelTrashed, &FileLabels::trashed_); | 794 converter->RegisterBoolField(kLabelTrashed, &FileLabels::trashed_); |
795 converter->RegisterBoolField(kLabelRestricted, &FileLabels::restricted_); | 795 converter->RegisterBoolField(kLabelRestricted, &FileLabels::restricted_); |
796 converter->RegisterBoolField(kLabelViewed, &FileLabels::viewed_); | 796 converter->RegisterBoolField(kLabelViewed, &FileLabels::viewed_); |
797 } | 797 } |
798 | 798 |
799 // static | 799 // static |
800 scoped_ptr<FileLabels> FileLabels::CreateFrom(const base::Value& value) { | 800 scoped_ptr<FileLabels> FileLabels::CreateFrom(const base::Value& value) { |
801 scoped_ptr<FileLabels> resource(new FileLabels()); | 801 scoped_ptr<FileLabels> resource(new FileLabels()); |
802 if (!resource->Parse(value)) { | 802 if (!resource->Parse(value)) { |
803 LOG(ERROR) << "Unable to create: Invalid FileLabels JSON!"; | 803 LOG(ERROR) << "Unable to create: Invalid FileLabels JSON!"; |
804 return scoped_ptr<FileLabels>(NULL); | 804 return scoped_ptr<FileLabels>(); |
805 } | 805 } |
806 return resource.Pass(); | 806 return resource.Pass(); |
807 } | 807 } |
808 | 808 |
809 bool FileLabels::Parse(const base::Value& value) { | 809 bool FileLabels::Parse(const base::Value& value) { |
810 base::JSONValueConverter<FileLabels> converter; | 810 base::JSONValueConverter<FileLabels> converter; |
811 if (!converter.Convert(value, this)) { | 811 if (!converter.Convert(value, this)) { |
812 LOG(ERROR) << "Unable to parse: Invalid FileLabels"; | 812 LOG(ERROR) << "Unable to parse: Invalid FileLabels"; |
813 return false; | 813 return false; |
814 } | 814 } |
815 return true; | 815 return true; |
816 } | 816 } |
817 | 817 |
818 } // namespace google_apis | 818 } // namespace google_apis |
OLD | NEW |