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/chromeos/gdata/drive_api_parser.h" | 5 #include "chrome/browser/chromeos/gdata/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/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // Converts |url_string| to |result|. Always returns true to be used | 25 // Converts |url_string| to |result|. Always returns true to be used |
26 // for JSONValueConverter::RegisterCustomField method. | 26 // for JSONValueConverter::RegisterCustomField method. |
27 // TODO(mukai): make it return false in case of invalid |url_string|. | 27 // TODO(mukai): make it return false in case of invalid |url_string|. |
28 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { | 28 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { |
29 *result = GURL(url_string.as_string()); | 29 *result = GURL(url_string.as_string()); |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 // Drive v2 API JSON names. | 33 // Drive v2 API JSON names. |
34 | 34 |
| 35 // Definition order follows the order of documentation in |
| 36 // https://developers.google.com/drive/v2/reference/ |
| 37 |
35 // Common | 38 // Common |
36 const char kKind[] = "kind"; | 39 const char kKind[] = "kind"; |
37 const char kId[] = "id"; | 40 const char kId[] = "id"; |
38 const char kETag[] = "etag"; | 41 const char kETag[] = "etag"; |
| 42 const char kSelfLink[] = "selfLink"; |
39 const char kItems[] = "items"; | 43 const char kItems[] = "items"; |
40 const char kLargestChangeId[] = "largestChangeId"; | 44 const char kLargestChangeId[] = "largestChangeId"; |
41 | 45 |
42 // About Resource: | 46 // About Resource |
| 47 // https://developers.google.com/drive/v2/reference/about |
43 const char kAboutKind[] = "drive#about"; | 48 const char kAboutKind[] = "drive#about"; |
44 const char kRootFolderId[] = "rootFolderId"; | |
45 const char kQuotaBytesTotal[] = "quotaBytesTotal"; | 49 const char kQuotaBytesTotal[] = "quotaBytesTotal"; |
46 const char kQuotaBytesUsed[] = "quotaBytesUsed"; | 50 const char kQuotaBytesUsed[] = "quotaBytesUsed"; |
| 51 const char kRootFolderId[] = "rootFolderId"; |
47 | 52 |
48 // App Icon: | 53 // App Icon |
| 54 // https://developers.google.com/drive/v2/reference/apps |
49 const char kCategory[] = "category"; | 55 const char kCategory[] = "category"; |
50 const char kSize[] = "size"; | 56 const char kSize[] = "size"; |
51 const char kIconUrl[] = "iconUrl"; | 57 const char kIconUrl[] = "iconUrl"; |
52 | 58 |
53 // Apps Resource: | 59 // Apps Resource |
| 60 // https://developers.google.com/drive/v2/reference/apps |
54 const char kAppKind[] = "drive#app"; | 61 const char kAppKind[] = "drive#app"; |
55 const char kName[] = "name"; | 62 const char kName[] = "name"; |
56 const char kObjectType[] = "objectType"; | 63 const char kObjectType[] = "objectType"; |
57 const char kSupportsCreate[] = "supportsCreate"; | 64 const char kSupportsCreate[] = "supportsCreate"; |
58 const char kSupportsImport[] = "supportsImport"; | 65 const char kSupportsImport[] = "supportsImport"; |
59 const char kInstalled[] = "installed"; | 66 const char kInstalled[] = "installed"; |
60 const char kAuthorized[] = "authorized"; | 67 const char kAuthorized[] = "authorized"; |
61 const char kProductUrl[] = "productUrl"; | 68 const char kProductUrl[] = "productUrl"; |
62 const char kPrimaryMimeTypes[] = "primaryMimeTypes"; | 69 const char kPrimaryMimeTypes[] = "primaryMimeTypes"; |
63 const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; | 70 const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; |
64 const char kPrimaryFileExtensions[] = "primaryFileExtensions"; | 71 const char kPrimaryFileExtensions[] = "primaryFileExtensions"; |
65 const char kSecondaryFileExtensions[] = "secondaryFileExtensions"; | 72 const char kSecondaryFileExtensions[] = "secondaryFileExtensions"; |
66 const char kIcons[] = "icons"; | 73 const char kIcons[] = "icons"; |
67 | 74 |
68 // Apps List: | 75 // Apps List |
| 76 // https://developers.google.com/drive/v2/reference/apps/list |
69 const char kAppListKind[] = "drive#appList"; | 77 const char kAppListKind[] = "drive#appList"; |
70 | 78 |
71 // Parent Resource: | 79 // Parent Resource |
| 80 // https://developers.google.com/drive/v2/reference/parents |
72 const char kParentReferenceKind[] = "drive#parentReference"; | 81 const char kParentReferenceKind[] = "drive#parentReference"; |
| 82 const char kParentLink[] = "parentLink"; |
73 const char kIsRoot[] = "isRoot"; | 83 const char kIsRoot[] = "isRoot"; |
74 | 84 |
75 // File Resource: | 85 // File Resource |
| 86 // https://developers.google.com/drive/v2/reference/files |
76 const char kFileKind[] = "drive#file"; | 87 const char kFileKind[] = "drive#file"; |
| 88 const char kTitle[] = "title"; |
77 const char kMimeType[] = "mimeType"; | 89 const char kMimeType[] = "mimeType"; |
78 const char kTitle[] = "title"; | 90 const char kCreatedDate[] = "createdDate"; |
79 const char kModifiedByMeDate[] = "modifiedByMeDate"; | 91 const char kModifiedByMeDate[] = "modifiedByMeDate"; |
80 const char kParents[] = "parents"; | |
81 const char kDownloadUrl[] = "downloadUrl"; | 92 const char kDownloadUrl[] = "downloadUrl"; |
82 const char kFileExtension[] = "fileExtension"; | 93 const char kFileExtension[] = "fileExtension"; |
83 const char kMd5Checksum[] = "md5Checksum"; | 94 const char kMd5Checksum[] = "md5Checksum"; |
84 const char kFileSize[] = "fileSize"; | 95 const char kFileSize[] = "fileSize"; |
| 96 const char kAlternateLink[] = "alternateLink"; |
| 97 const char kEmbedLink[] = "embedLink"; |
| 98 const char kParents[] = "parents"; |
| 99 const char kThumbnailLink[] = "thumbnailLink"; |
| 100 const char kWebContentLink[] = "webContentLink"; |
85 | 101 |
86 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; | 102 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; |
87 | 103 |
88 // Files List: | 104 // Files List |
| 105 // https://developers.google.com/drive/v2/reference/files/list |
89 const char kFileListKind[] = "drive#fileList"; | 106 const char kFileListKind[] = "drive#fileList"; |
90 const char kNextPageToken[] = "nextPageToken"; | 107 const char kNextPageToken[] = "nextPageToken"; |
91 const char kNextLink[] = "nextLink"; | 108 const char kNextLink[] = "nextLink"; |
92 | 109 |
93 // Change Resource: | 110 // Change Resource |
| 111 // https://developers.google.com/drive/v2/reference/changes |
94 const char kChangeKind[] = "drive#change"; | 112 const char kChangeKind[] = "drive#change"; |
95 const char kFileId[] = "fileId"; | 113 const char kFileId[] = "fileId"; |
| 114 const char kDeleted[] = "deleted"; |
96 const char kFile[] = "file"; | 115 const char kFile[] = "file"; |
97 | 116 |
98 // Changes List: | 117 // Changes List |
| 118 // https://developers.google.com/drive/v2/reference/changes/list |
99 const char kChangeListKind[] = "drive#changeList"; | 119 const char kChangeListKind[] = "drive#changeList"; |
100 | 120 |
101 // Maps category name to enum IconCategory. | 121 // Maps category name to enum IconCategory. |
102 struct AppIconCategoryMap { | 122 struct AppIconCategoryMap { |
103 gdata::DriveAppIcon::IconCategory category; | 123 gdata::DriveAppIcon::IconCategory category; |
104 const char* category_name; | 124 const char* category_name; |
105 }; | 125 }; |
106 | 126 |
107 const AppIconCategoryMap kAppIconCategoryMap[] = { | 127 const AppIconCategoryMap kAppIconCategoryMap[] = { |
108 { gdata::DriveAppIcon::DOCUMENT, "document" }, | 128 { gdata::DriveAppIcon::DOCUMENT, "document" }, |
(...skipping 15 matching lines...) Expand all Loading... |
124 | 144 |
125 } // namespace | 145 } // namespace |
126 | 146 |
127 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371 | 147 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371 |
128 namespace gdata { | 148 namespace gdata { |
129 | 149 |
130 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
131 // AboutResource implementation | 151 // AboutResource implementation |
132 | 152 |
133 AboutResource::AboutResource() | 153 AboutResource::AboutResource() |
134 : quota_bytes_total_(0), | 154 : largest_change_id_(0), |
135 quota_bytes_used_(0), | 155 quota_bytes_total_(0), |
136 largest_change_id_(0) {} | 156 quota_bytes_used_(0) {} |
137 | 157 |
138 AboutResource::~AboutResource() {} | 158 AboutResource::~AboutResource() {} |
139 | 159 |
140 // static | 160 // static |
141 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { | 161 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { |
142 scoped_ptr<AboutResource> resource(new AboutResource()); | 162 scoped_ptr<AboutResource> resource(new AboutResource()); |
143 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { | 163 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { |
144 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; | 164 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; |
145 return scoped_ptr<AboutResource>(NULL); | 165 return scoped_ptr<AboutResource>(NULL); |
146 } | 166 } |
147 return resource.Pass(); | 167 return resource.Pass(); |
148 } | 168 } |
149 | 169 |
150 // static | 170 // static |
151 void AboutResource::RegisterJSONConverter( | 171 void AboutResource::RegisterJSONConverter( |
152 base::JSONValueConverter<AboutResource>* converter) { | 172 base::JSONValueConverter<AboutResource>* converter) { |
153 converter->RegisterStringField(kRootFolderId, | 173 converter->RegisterCustomField<int64>(kLargestChangeId, |
154 &AboutResource::root_folder_id_); | 174 &AboutResource::largest_change_id_, |
| 175 &base::StringToInt64); |
155 converter->RegisterCustomField<int64>(kQuotaBytesTotal, | 176 converter->RegisterCustomField<int64>(kQuotaBytesTotal, |
156 &AboutResource::quota_bytes_total_, | 177 &AboutResource::quota_bytes_total_, |
157 &base::StringToInt64); | 178 &base::StringToInt64); |
158 converter->RegisterCustomField<int64>(kQuotaBytesUsed, | 179 converter->RegisterCustomField<int64>(kQuotaBytesUsed, |
159 &AboutResource::quota_bytes_used_, | 180 &AboutResource::quota_bytes_used_, |
160 &base::StringToInt64); | 181 &base::StringToInt64); |
161 converter->RegisterCustomField<int64>(kLargestChangeId, | 182 converter->RegisterStringField(kRootFolderId, |
162 &AboutResource::largest_change_id_, | 183 &AboutResource::root_folder_id_); |
163 &base::StringToInt64); | |
164 } | 184 } |
165 | 185 |
166 bool AboutResource::Parse(const base::Value& value) { | 186 bool AboutResource::Parse(const base::Value& value) { |
167 base::JSONValueConverter<AboutResource> converter; | 187 base::JSONValueConverter<AboutResource> converter; |
168 if (!converter.Convert(value, this)) { | 188 if (!converter.Convert(value, this)) { |
169 LOG(ERROR) << "Unable to parse: Invalid About resource JSON!"; | 189 LOG(ERROR) << "Unable to parse: Invalid About resource JSON!"; |
170 return false; | 190 return false; |
171 } | 191 } |
172 return true; | 192 return true; |
173 } | 193 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // ParentReference implementation | 332 // ParentReference implementation |
313 | 333 |
314 ParentReference::ParentReference() : is_root_(false) {} | 334 ParentReference::ParentReference() : is_root_(false) {} |
315 | 335 |
316 ParentReference::~ParentReference() {} | 336 ParentReference::~ParentReference() {} |
317 | 337 |
318 // static | 338 // static |
319 void ParentReference::RegisterJSONConverter( | 339 void ParentReference::RegisterJSONConverter( |
320 base::JSONValueConverter<ParentReference>* converter) { | 340 base::JSONValueConverter<ParentReference>* converter) { |
321 converter->RegisterStringField(kId, &ParentReference::file_id_); | 341 converter->RegisterStringField(kId, &ParentReference::file_id_); |
| 342 converter->RegisterCustomField<GURL>(kParentLink, |
| 343 &ParentReference::parent_link_, |
| 344 GetGURLFromString); |
322 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); | 345 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); |
323 } | 346 } |
324 | 347 |
325 // static | 348 // static |
326 scoped_ptr<ParentReference> | 349 scoped_ptr<ParentReference> |
327 ParentReference::CreateFrom(const base::Value& value) { | 350 ParentReference::CreateFrom(const base::Value& value) { |
328 scoped_ptr<ParentReference> reference(new ParentReference()); | 351 scoped_ptr<ParentReference> reference(new ParentReference()); |
329 if (!IsResourceKindExpected(value, kParentReferenceKind) || | 352 if (!IsResourceKindExpected(value, kParentReferenceKind) || |
330 !reference->Parse(value)) { | 353 !reference->Parse(value)) { |
331 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; | 354 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; |
(...skipping 16 matching lines...) Expand all Loading... |
348 | 371 |
349 FileResource::FileResource() : file_size_(0) {} | 372 FileResource::FileResource() : file_size_(0) {} |
350 | 373 |
351 FileResource::~FileResource() {} | 374 FileResource::~FileResource() {} |
352 | 375 |
353 // static | 376 // static |
354 void FileResource::RegisterJSONConverter( | 377 void FileResource::RegisterJSONConverter( |
355 base::JSONValueConverter<FileResource>* converter) { | 378 base::JSONValueConverter<FileResource>* converter) { |
356 converter->RegisterStringField(kId, &FileResource::file_id_); | 379 converter->RegisterStringField(kId, &FileResource::file_id_); |
357 converter->RegisterStringField(kETag, &FileResource::etag_); | 380 converter->RegisterStringField(kETag, &FileResource::etag_); |
| 381 converter->RegisterCustomField<GURL>(kSelfLink, |
| 382 &FileResource::self_link_, |
| 383 GetGURLFromString); |
| 384 converter->RegisterStringField(kTitle, &FileResource::title_); |
358 converter->RegisterStringField(kMimeType, &FileResource::mime_type_); | 385 converter->RegisterStringField(kMimeType, &FileResource::mime_type_); |
359 converter->RegisterStringField(kTitle, &FileResource::title_); | 386 converter->RegisterCustomField<base::Time>( |
| 387 kCreatedDate, |
| 388 &FileResource::created_date_, |
| 389 &gdata::util::GetTimeFromString); |
360 converter->RegisterCustomField<base::Time>( | 390 converter->RegisterCustomField<base::Time>( |
361 kModifiedByMeDate, | 391 kModifiedByMeDate, |
362 &FileResource::modified_by_me_date_, | 392 &FileResource::modified_by_me_date_, |
363 &gdata::util::GetTimeFromString); | 393 &gdata::util::GetTimeFromString); |
364 converter->RegisterRepeatedMessage<ParentReference>(kParents, | |
365 &FileResource::parents_); | |
366 converter->RegisterCustomField<GURL>(kDownloadUrl, | 394 converter->RegisterCustomField<GURL>(kDownloadUrl, |
367 &FileResource::download_url_, | 395 &FileResource::download_url_, |
368 GetGURLFromString); | 396 GetGURLFromString); |
369 converter->RegisterStringField(kFileExtension, | 397 converter->RegisterStringField(kFileExtension, |
370 &FileResource::file_extension_); | 398 &FileResource::file_extension_); |
371 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); | 399 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); |
372 converter->RegisterCustomField<int64>(kFileSize, | 400 converter->RegisterCustomField<int64>(kFileSize, |
373 &FileResource::file_size_, | 401 &FileResource::file_size_, |
374 &base::StringToInt64); | 402 &base::StringToInt64); |
| 403 converter->RegisterCustomField<GURL>(kAlternateLink, |
| 404 &FileResource::alternate_link_, |
| 405 GetGURLFromString); |
| 406 converter->RegisterCustomField<GURL>(kEmbedLink, |
| 407 &FileResource::embed_link_, |
| 408 GetGURLFromString); |
| 409 converter->RegisterRepeatedMessage<ParentReference>(kParents, |
| 410 &FileResource::parents_); |
| 411 converter->RegisterCustomField<GURL>(kThumbnailLink, |
| 412 &FileResource::thumbnail_link_, |
| 413 GetGURLFromString); |
| 414 converter->RegisterCustomField<GURL>(kWebContentLink, |
| 415 &FileResource::web_content_link_, |
| 416 GetGURLFromString); |
375 } | 417 } |
376 | 418 |
377 // static | 419 // static |
378 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { | 420 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { |
379 scoped_ptr<FileResource> resource(new FileResource()); | 421 scoped_ptr<FileResource> resource(new FileResource()); |
380 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { | 422 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { |
381 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; | 423 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; |
382 return scoped_ptr<FileResource>(NULL); | 424 return scoped_ptr<FileResource>(NULL); |
383 } | 425 } |
384 return resource.Pass(); | 426 return resource.Pass(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 485 |
444 ChangeResource::~ChangeResource() {} | 486 ChangeResource::~ChangeResource() {} |
445 | 487 |
446 // static | 488 // static |
447 void ChangeResource::RegisterJSONConverter( | 489 void ChangeResource::RegisterJSONConverter( |
448 base::JSONValueConverter<ChangeResource>* converter) { | 490 base::JSONValueConverter<ChangeResource>* converter) { |
449 converter->RegisterCustomField<int64>(kId, | 491 converter->RegisterCustomField<int64>(kId, |
450 &ChangeResource::change_id_, | 492 &ChangeResource::change_id_, |
451 &base::StringToInt64); | 493 &base::StringToInt64); |
452 converter->RegisterStringField(kFileId, &ChangeResource::file_id_); | 494 converter->RegisterStringField(kFileId, &ChangeResource::file_id_); |
| 495 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); |
453 converter->RegisterNestedField(kFile, &ChangeResource::file_); | 496 converter->RegisterNestedField(kFile, &ChangeResource::file_); |
454 } | 497 } |
455 | 498 |
456 // static | 499 // static |
457 scoped_ptr<ChangeResource> | 500 scoped_ptr<ChangeResource> |
458 ChangeResource::CreateFrom(const base::Value& value) { | 501 ChangeResource::CreateFrom(const base::Value& value) { |
459 scoped_ptr<ChangeResource> resource(new ChangeResource()); | 502 scoped_ptr<ChangeResource> resource(new ChangeResource()); |
460 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { | 503 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { |
461 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; | 504 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; |
462 return scoped_ptr<ChangeResource>(NULL); | 505 return scoped_ptr<ChangeResource>(NULL); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 bool ChangeList::Parse(const base::Value& value) { | 552 bool ChangeList::Parse(const base::Value& value) { |
510 base::JSONValueConverter<ChangeList> converter; | 553 base::JSONValueConverter<ChangeList> converter; |
511 if (!converter.Convert(value, this)) { | 554 if (!converter.Convert(value, this)) { |
512 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; | 555 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; |
513 return false; | 556 return false; |
514 } | 557 } |
515 return true; | 558 return true; |
516 } | 559 } |
517 | 560 |
518 } // namespace gdata | 561 } // namespace gdata |
OLD | NEW |