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

Side by Side Diff: chrome/browser/google_apis/drive_api_parser.cc

Issue 14160002: Add HasChangeListKind and HasFileListKind methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests Created 7 years, 8 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 | Annotate | Revision Log
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 "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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 converter->RegisterStringField(kETag, &FileList::etag_); 616 converter->RegisterStringField(kETag, &FileList::etag_);
617 converter->RegisterStringField(kNextPageToken, &FileList::next_page_token_); 617 converter->RegisterStringField(kNextPageToken, &FileList::next_page_token_);
618 converter->RegisterCustomField<GURL>(kNextLink, 618 converter->RegisterCustomField<GURL>(kNextLink,
619 &FileList::next_link_, 619 &FileList::next_link_,
620 GetGURLFromString); 620 GetGURLFromString);
621 converter->RegisterRepeatedMessage<FileResource>(kItems, 621 converter->RegisterRepeatedMessage<FileResource>(kItems,
622 &FileList::items_); 622 &FileList::items_);
623 } 623 }
624 624
625 // static 625 // static
626 bool FileList::HasFileListKind(const base::Value& value) {
627 return IsResourceKindExpected(value, kFileListKind);
628 }
629
630 // static
626 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { 631 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) {
627 scoped_ptr<FileList> resource(new FileList()); 632 scoped_ptr<FileList> resource(new FileList());
628 if (!IsResourceKindExpected(value, kFileListKind) || 633 if (!HasFileListKind(value) || !resource->Parse(value)) {
629 !resource->Parse(value)) {
630 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; 634 LOG(ERROR) << "Unable to create: Invalid FileList JSON!";
631 return scoped_ptr<FileList>(NULL); 635 return scoped_ptr<FileList>(NULL);
632 } 636 }
633 return resource.Pass(); 637 return resource.Pass();
634 } 638 }
635 639
636 bool FileList::Parse(const base::Value& value) { 640 bool FileList::Parse(const base::Value& value) {
637 base::JSONValueConverter<FileList> converter; 641 base::JSONValueConverter<FileList> converter;
638 if (!converter.Convert(value, this)) { 642 if (!converter.Convert(value, this)) {
639 LOG(ERROR) << "Unable to parse: Invalid FileList"; 643 LOG(ERROR) << "Unable to parse: Invalid FileList";
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 &ChangeList::next_link_, 700 &ChangeList::next_link_,
697 GetGURLFromString); 701 GetGURLFromString);
698 converter->RegisterCustomField<int64>(kLargestChangeId, 702 converter->RegisterCustomField<int64>(kLargestChangeId,
699 &ChangeList::largest_change_id_, 703 &ChangeList::largest_change_id_,
700 &base::StringToInt64); 704 &base::StringToInt64);
701 converter->RegisterRepeatedMessage<ChangeResource>(kItems, 705 converter->RegisterRepeatedMessage<ChangeResource>(kItems,
702 &ChangeList::items_); 706 &ChangeList::items_);
703 } 707 }
704 708
705 // static 709 // static
710 bool ChangeList::HasChangeListKind(const base::Value& value) {
711 return IsResourceKindExpected(value, kChangeListKind);
712 }
713
714 // static
706 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { 715 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) {
707 scoped_ptr<ChangeList> resource(new ChangeList()); 716 scoped_ptr<ChangeList> resource(new ChangeList());
708 if (!IsResourceKindExpected(value, kChangeListKind) || 717 if (!HasChangeListKind(value) || !resource->Parse(value)) {
709 !resource->Parse(value)) {
710 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; 718 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!";
711 return scoped_ptr<ChangeList>(NULL); 719 return scoped_ptr<ChangeList>(NULL);
712 } 720 }
713 return resource.Pass(); 721 return resource.Pass();
714 } 722 }
715 723
716 bool ChangeList::Parse(const base::Value& value) { 724 bool ChangeList::Parse(const base::Value& value) {
717 base::JSONValueConverter<ChangeList> converter; 725 base::JSONValueConverter<ChangeList> converter;
718 if (!converter.Convert(value, this)) { 726 if (!converter.Convert(value, this)) {
719 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; 727 LOG(ERROR) << "Unable to parse: Invalid ChangeList";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 bool FileLabels::Parse(const base::Value& value) { 766 bool FileLabels::Parse(const base::Value& value) {
759 base::JSONValueConverter<FileLabels> converter; 767 base::JSONValueConverter<FileLabels> converter;
760 if (!converter.Convert(value, this)) { 768 if (!converter.Convert(value, this)) {
761 LOG(ERROR) << "Unable to parse: Invalid FileLabels"; 769 LOG(ERROR) << "Unable to parse: Invalid FileLabels";
762 return false; 770 return false;
763 } 771 }
764 return true; 772 return true;
765 } 773 }
766 774
767 } // namespace google_apis 775 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_parser.h ('k') | chrome/browser/google_apis/drive_api_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698