| 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/gdata_wapi_parser.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_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/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const char kResourceIdNode[] = "resourceId"; | 61 const char kResourceIdNode[] = "resourceId"; |
| 62 const char kSizeNode[] = "size"; | 62 const char kSizeNode[] = "size"; |
| 63 const char kSuggestedFilenameNode[] = "suggestedFilename"; | 63 const char kSuggestedFilenameNode[] = "suggestedFilename"; |
| 64 const char kTitleNode[] = "title"; | 64 const char kTitleNode[] = "title"; |
| 65 const char kUpdatedNode[] = "updated"; | 65 const char kUpdatedNode[] = "updated"; |
| 66 const char kWritersCanInviteNode[] = "writersCanInvite"; | 66 const char kWritersCanInviteNode[] = "writersCanInvite"; |
| 67 | 67 |
| 68 // Field names. | 68 // Field names. |
| 69 const char kAuthorField[] = "author"; | 69 const char kAuthorField[] = "author"; |
| 70 const char kCategoryField[] = "category"; | 70 const char kCategoryField[] = "category"; |
| 71 const char kChangestampField[] = "docs$changestamp.value"; |
| 71 const char kContentField[] = "content"; | 72 const char kContentField[] = "content"; |
| 72 const char kDeletedField[] = "gd$deleted"; | 73 const char kDeletedField[] = "gd$deleted"; |
| 73 const char kETagField[] = "gd$etag"; | 74 const char kETagField[] = "gd$etag"; |
| 74 const char kEmailField[] = "email.$t"; | 75 const char kEmailField[] = "email.$t"; |
| 75 const char kEntryField[] = "entry"; | 76 const char kEntryField[] = "entry"; |
| 76 const char kFeedField[] = "feed"; | 77 const char kFeedField[] = "feed"; |
| 77 const char kFeedLinkField[] = "gd$feedLink"; | 78 const char kFeedLinkField[] = "gd$feedLink"; |
| 78 const char kFileNameField[] = "docs$filename.$t"; | 79 const char kFileNameField[] = "docs$filename.$t"; |
| 79 const char kHrefField[] = "href"; | 80 const char kHrefField[] = "href"; |
| 80 const char kIDField[] = "id.$t"; | 81 const char kIDField[] = "id.$t"; |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 &google_apis::util::GetTimeFromString); | 587 &google_apis::util::GetTimeFromString); |
| 587 } | 588 } |
| 588 | 589 |
| 589 //////////////////////////////////////////////////////////////////////////////// | 590 //////////////////////////////////////////////////////////////////////////////// |
| 590 // DocumentEntry implementation | 591 // DocumentEntry implementation |
| 591 | 592 |
| 592 DocumentEntry::DocumentEntry() | 593 DocumentEntry::DocumentEntry() |
| 593 : kind_(ENTRY_KIND_UNKNOWN), | 594 : kind_(ENTRY_KIND_UNKNOWN), |
| 594 file_size_(0), | 595 file_size_(0), |
| 595 deleted_(false), | 596 deleted_(false), |
| 596 removed_(false) { | 597 removed_(false), |
| 598 changestamp_(0) { |
| 597 } | 599 } |
| 598 | 600 |
| 599 DocumentEntry::~DocumentEntry() { | 601 DocumentEntry::~DocumentEntry() { |
| 600 } | 602 } |
| 601 | 603 |
| 602 bool DocumentEntry::HasFieldPresent(const base::Value* value, | 604 bool DocumentEntry::HasFieldPresent(const base::Value* value, |
| 603 bool* result) { | 605 bool* result) { |
| 604 *result = (value != NULL); | 606 *result = (value != NULL); |
| 605 return true; | 607 return true; |
| 606 } | 608 } |
| 607 | 609 |
| 610 bool DocumentEntry::ParseOptionalChangestamp(const base::StringPiece& value, |
| 611 int64* result) { |
| 612 DCHECK(result); |
| 613 if (!base::StringToInt64(value, result)) |
| 614 *result = 0; |
| 615 return true; |
| 616 } |
| 617 |
| 608 // static | 618 // static |
| 609 void DocumentEntry::RegisterJSONConverter( | 619 void DocumentEntry::RegisterJSONConverter( |
| 610 base::JSONValueConverter<DocumentEntry>* converter) { | 620 base::JSONValueConverter<DocumentEntry>* converter) { |
| 611 // Inherit the parent registrations. | 621 // Inherit the parent registrations. |
| 612 FeedEntry::RegisterJSONConverter( | 622 FeedEntry::RegisterJSONConverter( |
| 613 reinterpret_cast<base::JSONValueConverter<FeedEntry>*>(converter)); | 623 reinterpret_cast<base::JSONValueConverter<FeedEntry>*>(converter)); |
| 614 converter->RegisterStringField( | 624 converter->RegisterStringField( |
| 615 kResourceIdField, &DocumentEntry::resource_id_); | 625 kResourceIdField, &DocumentEntry::resource_id_); |
| 616 converter->RegisterStringField(kIDField, &DocumentEntry::id_); | 626 converter->RegisterStringField(kIDField, &DocumentEntry::id_); |
| 617 converter->RegisterStringField(kTitleTField, &DocumentEntry::title_); | 627 converter->RegisterStringField(kTitleTField, &DocumentEntry::title_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 633 converter->RegisterCustomField<int64>( | 643 converter->RegisterCustomField<int64>( |
| 634 kSizeField, &DocumentEntry::file_size_, &base::StringToInt64); | 644 kSizeField, &DocumentEntry::file_size_, &base::StringToInt64); |
| 635 converter->RegisterStringField( | 645 converter->RegisterStringField( |
| 636 kSuggestedFileNameField, &DocumentEntry::suggested_filename_); | 646 kSuggestedFileNameField, &DocumentEntry::suggested_filename_); |
| 637 // Deleted are treated as 'trashed' items on web client side. Removed files | 647 // Deleted are treated as 'trashed' items on web client side. Removed files |
| 638 // are gone for good. We treat both cases as 'deleted' for this client. | 648 // are gone for good. We treat both cases as 'deleted' for this client. |
| 639 converter->RegisterCustomValueField<bool>( | 649 converter->RegisterCustomValueField<bool>( |
| 640 kDeletedField, &DocumentEntry::deleted_, &DocumentEntry::HasFieldPresent); | 650 kDeletedField, &DocumentEntry::deleted_, &DocumentEntry::HasFieldPresent); |
| 641 converter->RegisterCustomValueField<bool>( | 651 converter->RegisterCustomValueField<bool>( |
| 642 kRemovedField, &DocumentEntry::removed_, &DocumentEntry::HasFieldPresent); | 652 kRemovedField, &DocumentEntry::removed_, &DocumentEntry::HasFieldPresent); |
| 653 converter->RegisterCustomField<int64>( |
| 654 kChangestampField, &DocumentEntry::changestamp_, |
| 655 &DocumentEntry::ParseOptionalChangestamp); |
| 643 } | 656 } |
| 644 | 657 |
| 645 std::string DocumentEntry::GetHostedDocumentExtension() const { | 658 std::string DocumentEntry::GetHostedDocumentExtension() const { |
| 646 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) { | 659 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) { |
| 647 if (kEntryKindMap[i].kind == kind_) { | 660 if (kEntryKindMap[i].kind == kind_) { |
| 648 if (kEntryKindMap[i].extension) | 661 if (kEntryKindMap[i].extension) |
| 649 return std::string(kEntryKindMap[i].extension); | 662 return std::string(kEntryKindMap[i].extension); |
| 650 else | 663 else |
| 651 return std::string(); | 664 return std::string(); |
| 652 } | 665 } |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 bool AccountMetadataFeed::Parse(const base::Value& value) { | 1195 bool AccountMetadataFeed::Parse(const base::Value& value) { |
| 1183 base::JSONValueConverter<AccountMetadataFeed> converter; | 1196 base::JSONValueConverter<AccountMetadataFeed> converter; |
| 1184 if (!converter.Convert(value, this)) { | 1197 if (!converter.Convert(value, this)) { |
| 1185 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; | 1198 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; |
| 1186 return false; | 1199 return false; |
| 1187 } | 1200 } |
| 1188 return true; | 1201 return true; |
| 1189 } | 1202 } |
| 1190 | 1203 |
| 1191 } // namespace google_apis | 1204 } // namespace google_apis |
| OLD | NEW |