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 "base/json/json_value_converter.h" | 9 #include "base/json/json_value_converter.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 AboutResource::~AboutResource() {} | 216 AboutResource::~AboutResource() {} |
217 | 217 |
218 // static | 218 // static |
219 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { | 219 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { |
220 scoped_ptr<AboutResource> resource(new AboutResource()); | 220 scoped_ptr<AboutResource> resource(new AboutResource()); |
221 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { | 221 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { |
222 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; | 222 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; |
223 return scoped_ptr<AboutResource>(); | 223 return scoped_ptr<AboutResource>(); |
224 } | 224 } |
225 return resource.Pass(); | 225 return resource; |
226 } | 226 } |
227 | 227 |
228 // static | 228 // static |
229 void AboutResource::RegisterJSONConverter( | 229 void AboutResource::RegisterJSONConverter( |
230 base::JSONValueConverter<AboutResource>* converter) { | 230 base::JSONValueConverter<AboutResource>* converter) { |
231 converter->RegisterCustomField<int64_t>(kLargestChangeId, | 231 converter->RegisterCustomField<int64_t>(kLargestChangeId, |
232 &AboutResource::largest_change_id_, | 232 &AboutResource::largest_change_id_, |
233 &base::StringToInt64); | 233 &base::StringToInt64); |
234 converter->RegisterCustomField<int64_t>(kQuotaBytesTotal, | 234 converter->RegisterCustomField<int64_t>(kQuotaBytesTotal, |
235 &AboutResource::quota_bytes_total_, | 235 &AboutResource::quota_bytes_total_, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 GetGURLFromString); | 270 GetGURLFromString); |
271 } | 271 } |
272 | 272 |
273 // static | 273 // static |
274 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFrom(const base::Value& value) { | 274 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFrom(const base::Value& value) { |
275 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon()); | 275 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon()); |
276 if (!resource->Parse(value)) { | 276 if (!resource->Parse(value)) { |
277 LOG(ERROR) << "Unable to create: Invalid DriveAppIcon JSON!"; | 277 LOG(ERROR) << "Unable to create: Invalid DriveAppIcon JSON!"; |
278 return scoped_ptr<DriveAppIcon>(); | 278 return scoped_ptr<DriveAppIcon>(); |
279 } | 279 } |
280 return resource.Pass(); | 280 return resource; |
281 } | 281 } |
282 | 282 |
283 bool DriveAppIcon::Parse(const base::Value& value) { | 283 bool DriveAppIcon::Parse(const base::Value& value) { |
284 base::JSONValueConverter<DriveAppIcon> converter; | 284 base::JSONValueConverter<DriveAppIcon> converter; |
285 if (!converter.Convert(value, this)) { | 285 if (!converter.Convert(value, this)) { |
286 LOG(ERROR) << "Unable to parse: Invalid DriveAppIcon"; | 286 LOG(ERROR) << "Unable to parse: Invalid DriveAppIcon"; |
287 return false; | 287 return false; |
288 } | 288 } |
289 return true; | 289 return true; |
290 } | 290 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 GetGURLFromString); | 335 GetGURLFromString); |
336 } | 336 } |
337 | 337 |
338 // static | 338 // static |
339 scoped_ptr<AppResource> AppResource::CreateFrom(const base::Value& value) { | 339 scoped_ptr<AppResource> AppResource::CreateFrom(const base::Value& value) { |
340 scoped_ptr<AppResource> resource(new AppResource()); | 340 scoped_ptr<AppResource> resource(new AppResource()); |
341 if (!IsResourceKindExpected(value, kAppKind) || !resource->Parse(value)) { | 341 if (!IsResourceKindExpected(value, kAppKind) || !resource->Parse(value)) { |
342 LOG(ERROR) << "Unable to create: Invalid AppResource JSON!"; | 342 LOG(ERROR) << "Unable to create: Invalid AppResource JSON!"; |
343 return scoped_ptr<AppResource>(); | 343 return scoped_ptr<AppResource>(); |
344 } | 344 } |
345 return resource.Pass(); | 345 return resource; |
346 } | 346 } |
347 | 347 |
348 bool AppResource::Parse(const base::Value& value) { | 348 bool AppResource::Parse(const base::Value& value) { |
349 base::JSONValueConverter<AppResource> converter; | 349 base::JSONValueConverter<AppResource> converter; |
350 if (!converter.Convert(value, this)) { | 350 if (!converter.Convert(value, this)) { |
351 LOG(ERROR) << "Unable to parse: Invalid AppResource"; | 351 LOG(ERROR) << "Unable to parse: Invalid AppResource"; |
352 return false; | 352 return false; |
353 } | 353 } |
354 return true; | 354 return true; |
355 } | 355 } |
(...skipping 13 matching lines...) Expand all Loading... |
369 &AppList::items_); | 369 &AppList::items_); |
370 } | 370 } |
371 | 371 |
372 // static | 372 // static |
373 scoped_ptr<AppList> AppList::CreateFrom(const base::Value& value) { | 373 scoped_ptr<AppList> AppList::CreateFrom(const base::Value& value) { |
374 scoped_ptr<AppList> resource(new AppList()); | 374 scoped_ptr<AppList> resource(new AppList()); |
375 if (!IsResourceKindExpected(value, kAppListKind) || !resource->Parse(value)) { | 375 if (!IsResourceKindExpected(value, kAppListKind) || !resource->Parse(value)) { |
376 LOG(ERROR) << "Unable to create: Invalid AppList JSON!"; | 376 LOG(ERROR) << "Unable to create: Invalid AppList JSON!"; |
377 return scoped_ptr<AppList>(); | 377 return scoped_ptr<AppList>(); |
378 } | 378 } |
379 return resource.Pass(); | 379 return resource; |
380 } | 380 } |
381 | 381 |
382 bool AppList::Parse(const base::Value& value) { | 382 bool AppList::Parse(const base::Value& value) { |
383 base::JSONValueConverter<AppList> converter; | 383 base::JSONValueConverter<AppList> converter; |
384 if (!converter.Convert(value, this)) { | 384 if (!converter.Convert(value, this)) { |
385 LOG(ERROR) << "Unable to parse: Invalid AppList"; | 385 LOG(ERROR) << "Unable to parse: Invalid AppList"; |
386 return false; | 386 return false; |
387 } | 387 } |
388 return true; | 388 return true; |
389 } | 389 } |
(...skipping 16 matching lines...) Expand all Loading... |
406 | 406 |
407 // static | 407 // static |
408 scoped_ptr<ParentReference> | 408 scoped_ptr<ParentReference> |
409 ParentReference::CreateFrom(const base::Value& value) { | 409 ParentReference::CreateFrom(const base::Value& value) { |
410 scoped_ptr<ParentReference> reference(new ParentReference()); | 410 scoped_ptr<ParentReference> reference(new ParentReference()); |
411 if (!IsResourceKindExpected(value, kParentReferenceKind) || | 411 if (!IsResourceKindExpected(value, kParentReferenceKind) || |
412 !reference->Parse(value)) { | 412 !reference->Parse(value)) { |
413 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; | 413 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; |
414 return scoped_ptr<ParentReference>(); | 414 return scoped_ptr<ParentReference>(); |
415 } | 415 } |
416 return reference.Pass(); | 416 return reference; |
417 } | 417 } |
418 | 418 |
419 bool ParentReference::Parse(const base::Value& value) { | 419 bool ParentReference::Parse(const base::Value& value) { |
420 base::JSONValueConverter<ParentReference> converter; | 420 base::JSONValueConverter<ParentReference> converter; |
421 if (!converter.Convert(value, this)) { | 421 if (!converter.Convert(value, this)) { |
422 LOG(ERROR) << "Unable to parse: Invalid ParentReference"; | 422 LOG(ERROR) << "Unable to parse: Invalid ParentReference"; |
423 return false; | 423 return false; |
424 } | 424 } |
425 return true; | 425 return true; |
426 } | 426 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 GetOpenWithLinksFromDictionaryValue); | 478 GetOpenWithLinksFromDictionaryValue); |
479 } | 479 } |
480 | 480 |
481 // static | 481 // static |
482 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { | 482 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { |
483 scoped_ptr<FileResource> resource(new FileResource()); | 483 scoped_ptr<FileResource> resource(new FileResource()); |
484 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { | 484 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { |
485 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; | 485 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; |
486 return scoped_ptr<FileResource>(); | 486 return scoped_ptr<FileResource>(); |
487 } | 487 } |
488 return resource.Pass(); | 488 return resource; |
489 } | 489 } |
490 | 490 |
491 bool FileResource::IsDirectory() const { | 491 bool FileResource::IsDirectory() const { |
492 return mime_type_ == kDriveFolderMimeType; | 492 return mime_type_ == kDriveFolderMimeType; |
493 } | 493 } |
494 | 494 |
495 bool FileResource::IsHostedDocument() const { | 495 bool FileResource::IsHostedDocument() const { |
496 // Hosted documents don't have fileSize field set: | 496 // Hosted documents don't have fileSize field set: |
497 // https://developers.google.com/drive/v2/reference/files | 497 // https://developers.google.com/drive/v2/reference/files |
498 return !IsDirectory() && file_size_ == kUnsetFileSize; | 498 return !IsDirectory() && file_size_ == kUnsetFileSize; |
(...skipping 30 matching lines...) Expand all Loading... |
529 return IsResourceKindExpected(value, kFileListKind); | 529 return IsResourceKindExpected(value, kFileListKind); |
530 } | 530 } |
531 | 531 |
532 // static | 532 // static |
533 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { | 533 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { |
534 scoped_ptr<FileList> resource(new FileList()); | 534 scoped_ptr<FileList> resource(new FileList()); |
535 if (!HasFileListKind(value) || !resource->Parse(value)) { | 535 if (!HasFileListKind(value) || !resource->Parse(value)) { |
536 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; | 536 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; |
537 return scoped_ptr<FileList>(); | 537 return scoped_ptr<FileList>(); |
538 } | 538 } |
539 return resource.Pass(); | 539 return resource; |
540 } | 540 } |
541 | 541 |
542 bool FileList::Parse(const base::Value& value) { | 542 bool FileList::Parse(const base::Value& value) { |
543 base::JSONValueConverter<FileList> converter; | 543 base::JSONValueConverter<FileList> converter; |
544 if (!converter.Convert(value, this)) { | 544 if (!converter.Convert(value, this)) { |
545 LOG(ERROR) << "Unable to parse: Invalid FileList"; | 545 LOG(ERROR) << "Unable to parse: Invalid FileList"; |
546 return false; | 546 return false; |
547 } | 547 } |
548 return true; | 548 return true; |
549 } | 549 } |
(...skipping 20 matching lines...) Expand all Loading... |
570 } | 570 } |
571 | 571 |
572 // static | 572 // static |
573 scoped_ptr<ChangeResource> | 573 scoped_ptr<ChangeResource> |
574 ChangeResource::CreateFrom(const base::Value& value) { | 574 ChangeResource::CreateFrom(const base::Value& value) { |
575 scoped_ptr<ChangeResource> resource(new ChangeResource()); | 575 scoped_ptr<ChangeResource> resource(new ChangeResource()); |
576 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { | 576 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { |
577 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; | 577 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; |
578 return scoped_ptr<ChangeResource>(); | 578 return scoped_ptr<ChangeResource>(); |
579 } | 579 } |
580 return resource.Pass(); | 580 return resource; |
581 } | 581 } |
582 | 582 |
583 bool ChangeResource::Parse(const base::Value& value) { | 583 bool ChangeResource::Parse(const base::Value& value) { |
584 base::JSONValueConverter<ChangeResource> converter; | 584 base::JSONValueConverter<ChangeResource> converter; |
585 if (!converter.Convert(value, this)) { | 585 if (!converter.Convert(value, this)) { |
586 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; | 586 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; |
587 return false; | 587 return false; |
588 } | 588 } |
589 return true; | 589 return true; |
590 } | 590 } |
(...skipping 22 matching lines...) Expand all Loading... |
613 return IsResourceKindExpected(value, kChangeListKind); | 613 return IsResourceKindExpected(value, kChangeListKind); |
614 } | 614 } |
615 | 615 |
616 // static | 616 // static |
617 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { | 617 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { |
618 scoped_ptr<ChangeList> resource(new ChangeList()); | 618 scoped_ptr<ChangeList> resource(new ChangeList()); |
619 if (!HasChangeListKind(value) || !resource->Parse(value)) { | 619 if (!HasChangeListKind(value) || !resource->Parse(value)) { |
620 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; | 620 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; |
621 return scoped_ptr<ChangeList>(); | 621 return scoped_ptr<ChangeList>(); |
622 } | 622 } |
623 return resource.Pass(); | 623 return resource; |
624 } | 624 } |
625 | 625 |
626 bool ChangeList::Parse(const base::Value& value) { | 626 bool ChangeList::Parse(const base::Value& value) { |
627 base::JSONValueConverter<ChangeList> converter; | 627 base::JSONValueConverter<ChangeList> converter; |
628 if (!converter.Convert(value, this)) { | 628 if (!converter.Convert(value, this)) { |
629 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; | 629 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; |
630 return false; | 630 return false; |
631 } | 631 } |
632 return true; | 632 return true; |
633 } | 633 } |
(...skipping 12 matching lines...) Expand all Loading... |
646 converter->RegisterBoolField(kLabelTrashed, &FileLabels::trashed_); | 646 converter->RegisterBoolField(kLabelTrashed, &FileLabels::trashed_); |
647 } | 647 } |
648 | 648 |
649 // static | 649 // static |
650 scoped_ptr<FileLabels> FileLabels::CreateFrom(const base::Value& value) { | 650 scoped_ptr<FileLabels> FileLabels::CreateFrom(const base::Value& value) { |
651 scoped_ptr<FileLabels> resource(new FileLabels()); | 651 scoped_ptr<FileLabels> resource(new FileLabels()); |
652 if (!resource->Parse(value)) { | 652 if (!resource->Parse(value)) { |
653 LOG(ERROR) << "Unable to create: Invalid FileLabels JSON!"; | 653 LOG(ERROR) << "Unable to create: Invalid FileLabels JSON!"; |
654 return scoped_ptr<FileLabels>(); | 654 return scoped_ptr<FileLabels>(); |
655 } | 655 } |
656 return resource.Pass(); | 656 return resource; |
657 } | 657 } |
658 | 658 |
659 bool FileLabels::Parse(const base::Value& value) { | 659 bool FileLabels::Parse(const base::Value& value) { |
660 base::JSONValueConverter<FileLabels> converter; | 660 base::JSONValueConverter<FileLabels> converter; |
661 if (!converter.Convert(value, this)) { | 661 if (!converter.Convert(value, this)) { |
662 LOG(ERROR) << "Unable to parse: Invalid FileLabels."; | 662 LOG(ERROR) << "Unable to parse: Invalid FileLabels."; |
663 return false; | 663 return false; |
664 } | 664 } |
665 return true; | 665 return true; |
666 } | 666 } |
(...skipping 20 matching lines...) Expand all Loading... |
687 } | 687 } |
688 | 688 |
689 // static | 689 // static |
690 scoped_ptr<ImageMediaMetadata> ImageMediaMetadata::CreateFrom( | 690 scoped_ptr<ImageMediaMetadata> ImageMediaMetadata::CreateFrom( |
691 const base::Value& value) { | 691 const base::Value& value) { |
692 scoped_ptr<ImageMediaMetadata> resource(new ImageMediaMetadata()); | 692 scoped_ptr<ImageMediaMetadata> resource(new ImageMediaMetadata()); |
693 if (!resource->Parse(value)) { | 693 if (!resource->Parse(value)) { |
694 LOG(ERROR) << "Unable to create: Invalid ImageMediaMetadata JSON!"; | 694 LOG(ERROR) << "Unable to create: Invalid ImageMediaMetadata JSON!"; |
695 return scoped_ptr<ImageMediaMetadata>(); | 695 return scoped_ptr<ImageMediaMetadata>(); |
696 } | 696 } |
697 return resource.Pass(); | 697 return resource; |
698 } | 698 } |
699 | 699 |
700 bool ImageMediaMetadata::Parse(const base::Value& value) { | 700 bool ImageMediaMetadata::Parse(const base::Value& value) { |
701 base::JSONValueConverter<ImageMediaMetadata> converter; | 701 base::JSONValueConverter<ImageMediaMetadata> converter; |
702 if (!converter.Convert(value, this)) { | 702 if (!converter.Convert(value, this)) { |
703 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; | 703 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; |
704 return false; | 704 return false; |
705 } | 705 } |
706 return true; | 706 return true; |
707 } | 707 } |
708 | 708 |
709 } // namespace google_apis | 709 } // namespace google_apis |
OLD | NEW |