| 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 <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 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Converts |url_string| to |result|. Always returns true to be used | 33 // Converts |url_string| to |result|. Always returns true to be used |
| 34 // for JSONValueConverter::RegisterCustomField method. | 34 // for JSONValueConverter::RegisterCustomField method. |
| 35 // TODO(mukai): make it return false in case of invalid |url_string|. | 35 // TODO(mukai): make it return false in case of invalid |url_string|. |
| 36 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { | 36 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { |
| 37 *result = GURL(url_string.as_string()); | 37 *result = GURL(url_string.as_string()); |
| 38 return true; | 38 return true; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Converts |value| to |result|. |
| 42 bool GetParentsFromValue(const base::Value* value, |
| 43 std::vector<ParentReference>* result) { |
| 44 DCHECK(value); |
| 45 DCHECK(result); |
| 46 |
| 47 const base::ListValue* list_value = NULL; |
| 48 if (!value->GetAsList(&list_value)) |
| 49 return false; |
| 50 |
| 51 base::JSONValueConverter<ParentReference> converter; |
| 52 result->resize(list_value->GetSize()); |
| 53 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 54 const base::Value* parent_value = NULL; |
| 55 if (!list_value->Get(i, &parent_value) || |
| 56 !converter.Convert(*parent_value, &(*result)[i])) |
| 57 return false; |
| 58 } |
| 59 |
| 60 return true; |
| 61 } |
| 62 |
| 41 // Converts |value| to |result|. The key of |value| is app_id, and its value | 63 // Converts |value| to |result|. The key of |value| is app_id, and its value |
| 42 // is URL to open the resource on the web app. | 64 // is URL to open the resource on the web app. |
| 43 bool GetOpenWithLinksFromDictionaryValue( | 65 bool GetOpenWithLinksFromDictionaryValue( |
| 44 const base::Value* value, | 66 const base::Value* value, |
| 45 std::vector<FileResource::OpenWithLink>* result) { | 67 std::vector<FileResource::OpenWithLink>* result) { |
| 46 DCHECK(value); | 68 DCHECK(value); |
| 47 DCHECK(result); | 69 DCHECK(result); |
| 48 | 70 |
| 49 const base::DictionaryValue* dictionary_value; | 71 const base::DictionaryValue* dictionary_value; |
| 50 if (!value->GetAsDictionary(&dictionary_value)) | 72 if (!value->GetAsDictionary(&dictionary_value)) |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 converter->RegisterBoolField(kShared, &FileResource::shared_); | 484 converter->RegisterBoolField(kShared, &FileResource::shared_); |
| 463 converter->RegisterStringField(kFileExtension, | 485 converter->RegisterStringField(kFileExtension, |
| 464 &FileResource::file_extension_); | 486 &FileResource::file_extension_); |
| 465 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); | 487 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); |
| 466 converter->RegisterCustomField<int64>(kFileSize, | 488 converter->RegisterCustomField<int64>(kFileSize, |
| 467 &FileResource::file_size_, | 489 &FileResource::file_size_, |
| 468 &base::StringToInt64); | 490 &base::StringToInt64); |
| 469 converter->RegisterCustomField<GURL>(kAlternateLink, | 491 converter->RegisterCustomField<GURL>(kAlternateLink, |
| 470 &FileResource::alternate_link_, | 492 &FileResource::alternate_link_, |
| 471 GetGURLFromString); | 493 GetGURLFromString); |
| 472 converter->RegisterRepeatedMessage<ParentReference>(kParents, | 494 converter->RegisterCustomValueField<std::vector<ParentReference> >( |
| 473 &FileResource::parents_); | 495 kParents, |
| 496 &FileResource::parents_, |
| 497 GetParentsFromValue); |
| 474 converter->RegisterCustomValueField<std::vector<OpenWithLink> >( | 498 converter->RegisterCustomValueField<std::vector<OpenWithLink> >( |
| 475 kOpenWithLinks, | 499 kOpenWithLinks, |
| 476 &FileResource::open_with_links_, | 500 &FileResource::open_with_links_, |
| 477 GetOpenWithLinksFromDictionaryValue); | 501 GetOpenWithLinksFromDictionaryValue); |
| 478 } | 502 } |
| 479 | 503 |
| 480 // static | 504 // static |
| 481 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { | 505 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { |
| 482 scoped_ptr<FileResource> resource(new FileResource()); | 506 scoped_ptr<FileResource> resource(new FileResource()); |
| 483 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { | 507 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 bool ImageMediaMetadata::Parse(const base::Value& value) { | 732 bool ImageMediaMetadata::Parse(const base::Value& value) { |
| 709 base::JSONValueConverter<ImageMediaMetadata> converter; | 733 base::JSONValueConverter<ImageMediaMetadata> converter; |
| 710 if (!converter.Convert(value, this)) { | 734 if (!converter.Convert(value, this)) { |
| 711 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; | 735 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; |
| 712 return false; | 736 return false; |
| 713 } | 737 } |
| 714 return true; | 738 return true; |
| 715 } | 739 } |
| 716 | 740 |
| 717 } // namespace google_apis | 741 } // namespace google_apis |
| OLD | NEW |