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

Side by Side Diff: chrome/browser/chromeos/gdata/drive_api_parser.cc

Issue 10855017: Add missing fields in Drive V2 API parser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for comments Created 8 years, 4 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/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
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";
96 const char kFile[] = "file"; 114 const char kFile[] = "file";
97 115
98 // Changes List: 116 // Changes List
117 // https://developers.google.com/drive/v2/reference/changes/list
99 const char kChangeListKind[] = "drive#changeList"; 118 const char kChangeListKind[] = "drive#changeList";
100 119
101 // Maps category name to enum IconCategory. 120 // Maps category name to enum IconCategory.
102 struct AppIconCategoryMap { 121 struct AppIconCategoryMap {
103 gdata::DriveAppIcon::IconCategory category; 122 gdata::DriveAppIcon::IconCategory category;
104 const char* category_name; 123 const char* category_name;
105 }; 124 };
106 125
107 const AppIconCategoryMap kAppIconCategoryMap[] = { 126 const AppIconCategoryMap kAppIconCategoryMap[] = {
108 { gdata::DriveAppIcon::DOCUMENT, "document" }, 127 { gdata::DriveAppIcon::DOCUMENT, "document" },
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // ParentReference implementation 331 // ParentReference implementation
313 332
314 ParentReference::ParentReference() : is_root_(false) {} 333 ParentReference::ParentReference() : is_root_(false) {}
315 334
316 ParentReference::~ParentReference() {} 335 ParentReference::~ParentReference() {}
317 336
318 // static 337 // static
319 void ParentReference::RegisterJSONConverter( 338 void ParentReference::RegisterJSONConverter(
320 base::JSONValueConverter<ParentReference>* converter) { 339 base::JSONValueConverter<ParentReference>* converter) {
321 converter->RegisterStringField(kId, &ParentReference::file_id_); 340 converter->RegisterStringField(kId, &ParentReference::file_id_);
341 converter->RegisterCustomField<GURL>(kParentLink,
342 &ParentReference::parent_link_,
343 GetGURLFromString);
322 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); 344 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_);
323 } 345 }
324 346
325 // static 347 // static
326 scoped_ptr<ParentReference> 348 scoped_ptr<ParentReference>
327 ParentReference::CreateFrom(const base::Value& value) { 349 ParentReference::CreateFrom(const base::Value& value) {
328 scoped_ptr<ParentReference> reference(new ParentReference()); 350 scoped_ptr<ParentReference> reference(new ParentReference());
329 if (!IsResourceKindExpected(value, kParentReferenceKind) || 351 if (!IsResourceKindExpected(value, kParentReferenceKind) ||
330 !reference->Parse(value)) { 352 !reference->Parse(value)) {
331 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; 353 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!";
(...skipping 18 matching lines...) Expand all
350 372
351 FileResource::~FileResource() {} 373 FileResource::~FileResource() {}
352 374
353 // static 375 // static
354 void FileResource::RegisterJSONConverter( 376 void FileResource::RegisterJSONConverter(
355 base::JSONValueConverter<FileResource>* converter) { 377 base::JSONValueConverter<FileResource>* converter) {
356 converter->RegisterStringField(kId, &FileResource::file_id_); 378 converter->RegisterStringField(kId, &FileResource::file_id_);
357 converter->RegisterStringField(kETag, &FileResource::etag_); 379 converter->RegisterStringField(kETag, &FileResource::etag_);
358 converter->RegisterStringField(kMimeType, &FileResource::mime_type_); 380 converter->RegisterStringField(kMimeType, &FileResource::mime_type_);
359 converter->RegisterStringField(kTitle, &FileResource::title_); 381 converter->RegisterStringField(kTitle, &FileResource::title_);
360 converter->RegisterCustomField<base::Time>( 382 converter->RegisterCustomField<base::Time>(
hashimoto 2012/08/07 05:55:04 Could you order these too?
kochi 2012/08/07 06:30:37 Done.
383 kCreatedDate,
384 &FileResource::created_date_,
385 &gdata::util::GetTimeFromString);
386 converter->RegisterCustomField<base::Time>(
361 kModifiedByMeDate, 387 kModifiedByMeDate,
362 &FileResource::modified_by_me_date_, 388 &FileResource::modified_by_me_date_,
363 &gdata::util::GetTimeFromString); 389 &gdata::util::GetTimeFromString);
364 converter->RegisterRepeatedMessage<ParentReference>(kParents, 390 converter->RegisterRepeatedMessage<ParentReference>(kParents,
365 &FileResource::parents_); 391 &FileResource::parents_);
366 converter->RegisterCustomField<GURL>(kDownloadUrl,
367 &FileResource::download_url_,
368 GetGURLFromString);
369 converter->RegisterStringField(kFileExtension, 392 converter->RegisterStringField(kFileExtension,
370 &FileResource::file_extension_); 393 &FileResource::file_extension_);
371 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); 394 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_);
372 converter->RegisterCustomField<int64>(kFileSize, 395 converter->RegisterCustomField<int64>(kFileSize,
373 &FileResource::file_size_, 396 &FileResource::file_size_,
374 &base::StringToInt64); 397 &base::StringToInt64);
398 converter->RegisterCustomField<GURL>(kDownloadUrl,
399 &FileResource::download_url_,
400 GetGURLFromString);
401 converter->RegisterCustomField<GURL>(kSelfLink,
402 &FileResource::self_link_,
403 GetGURLFromString);
404 converter->RegisterCustomField<GURL>(kAlternateLink,
405 &FileResource::alternate_link_,
406 GetGURLFromString);
407 converter->RegisterCustomField<GURL>(kEmbedLink,
408 &FileResource::embed_link_,
409 GetGURLFromString);
410 converter->RegisterCustomField<GURL>(kThumbnailLink,
411 &FileResource::thumbnail_link_,
412 GetGURLFromString);
413 converter->RegisterCustomField<GURL>(kWebContentLink,
414 &FileResource::web_content_link_,
415 GetGURLFromString);
375 } 416 }
376 417
377 // static 418 // static
378 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { 419 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) {
379 scoped_ptr<FileResource> resource(new FileResource()); 420 scoped_ptr<FileResource> resource(new FileResource());
380 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { 421 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) {
381 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; 422 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!";
382 return scoped_ptr<FileResource>(NULL); 423 return scoped_ptr<FileResource>(NULL);
383 } 424 }
384 return resource.Pass(); 425 return resource.Pass();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 bool ChangeList::Parse(const base::Value& value) { 550 bool ChangeList::Parse(const base::Value& value) {
510 base::JSONValueConverter<ChangeList> converter; 551 base::JSONValueConverter<ChangeList> converter;
511 if (!converter.Convert(value, this)) { 552 if (!converter.Convert(value, this)) {
512 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; 553 LOG(ERROR) << "Unable to parse: Invalid ChangeList";
513 return false; 554 return false;
514 } 555 }
515 return true; 556 return true;
516 } 557 }
517 558
518 } // namespace gdata 559 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698