| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/json/json_value_converter.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/string_number_conversions.h" | |
| 14 #include "base/string_piece.h" | |
| 15 #include "base/string_util.h" | |
| 16 #include "base/values.h" | |
| 17 #include "chrome/browser/chromeos/gdata/gdata_util.h" | |
| 18 | |
| 19 using base::Value; | |
| 20 using base::DictionaryValue; | |
| 21 using base::ListValue; | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 // Converts |url_string| to |result|. Always returns true to be used | |
| 26 // for JSONValueConverter::RegisterCustomField method. | |
| 27 // TODO(mukai): make it return false in case of invalid |url_string|. | |
| 28 bool GetGURLFromString(const base::StringPiece& url_string, GURL* result) { | |
| 29 *result = GURL(url_string.as_string()); | |
| 30 return true; | |
| 31 } | |
| 32 | |
| 33 // Drive v2 API JSON names. | |
| 34 | |
| 35 // Definition order follows the order of documentation in | |
| 36 // https://developers.google.com/drive/v2/reference/ | |
| 37 | |
| 38 // Common | |
| 39 const char kKind[] = "kind"; | |
| 40 const char kId[] = "id"; | |
| 41 const char kETag[] = "etag"; | |
| 42 const char kSelfLink[] = "selfLink"; | |
| 43 const char kItems[] = "items"; | |
| 44 const char kLargestChangeId[] = "largestChangeId"; | |
| 45 | |
| 46 // About Resource | |
| 47 // https://developers.google.com/drive/v2/reference/about | |
| 48 const char kAboutKind[] = "drive#about"; | |
| 49 const char kQuotaBytesTotal[] = "quotaBytesTotal"; | |
| 50 const char kQuotaBytesUsed[] = "quotaBytesUsed"; | |
| 51 const char kRootFolderId[] = "rootFolderId"; | |
| 52 | |
| 53 // App Icon | |
| 54 // https://developers.google.com/drive/v2/reference/apps | |
| 55 const char kCategory[] = "category"; | |
| 56 const char kSize[] = "size"; | |
| 57 const char kIconUrl[] = "iconUrl"; | |
| 58 | |
| 59 // Apps Resource | |
| 60 // https://developers.google.com/drive/v2/reference/apps | |
| 61 const char kAppKind[] = "drive#app"; | |
| 62 const char kName[] = "name"; | |
| 63 const char kObjectType[] = "objectType"; | |
| 64 const char kSupportsCreate[] = "supportsCreate"; | |
| 65 const char kSupportsImport[] = "supportsImport"; | |
| 66 const char kInstalled[] = "installed"; | |
| 67 const char kAuthorized[] = "authorized"; | |
| 68 const char kProductUrl[] = "productUrl"; | |
| 69 const char kPrimaryMimeTypes[] = "primaryMimeTypes"; | |
| 70 const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; | |
| 71 const char kPrimaryFileExtensions[] = "primaryFileExtensions"; | |
| 72 const char kSecondaryFileExtensions[] = "secondaryFileExtensions"; | |
| 73 const char kIcons[] = "icons"; | |
| 74 | |
| 75 // Apps List | |
| 76 // https://developers.google.com/drive/v2/reference/apps/list | |
| 77 const char kAppListKind[] = "drive#appList"; | |
| 78 | |
| 79 // Parent Resource | |
| 80 // https://developers.google.com/drive/v2/reference/parents | |
| 81 const char kParentReferenceKind[] = "drive#parentReference"; | |
| 82 const char kParentLink[] = "parentLink"; | |
| 83 const char kIsRoot[] = "isRoot"; | |
| 84 | |
| 85 // File Resource | |
| 86 // https://developers.google.com/drive/v2/reference/files | |
| 87 const char kFileKind[] = "drive#file"; | |
| 88 const char kTitle[] = "title"; | |
| 89 const char kMimeType[] = "mimeType"; | |
| 90 const char kCreatedDate[] = "createdDate"; | |
| 91 const char kModifiedByMeDate[] = "modifiedByMeDate"; | |
| 92 const char kDownloadUrl[] = "downloadUrl"; | |
| 93 const char kFileExtension[] = "fileExtension"; | |
| 94 const char kMd5Checksum[] = "md5Checksum"; | |
| 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"; | |
| 101 const char kLabels[] = "labels"; | |
| 102 // These 5 flags are defined under |labels|. | |
| 103 const char kLabelStarred[] = "starred"; | |
| 104 const char kLabelHidden[] = "hidden"; | |
| 105 const char kLabelTrashed[] = "trashed"; | |
| 106 const char kLabelRestricted[] = "restricted"; | |
| 107 const char kLabelViewed[] = "viewed"; | |
| 108 | |
| 109 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; | |
| 110 | |
| 111 // Files List | |
| 112 // https://developers.google.com/drive/v2/reference/files/list | |
| 113 const char kFileListKind[] = "drive#fileList"; | |
| 114 const char kNextPageToken[] = "nextPageToken"; | |
| 115 const char kNextLink[] = "nextLink"; | |
| 116 | |
| 117 // Change Resource | |
| 118 // https://developers.google.com/drive/v2/reference/changes | |
| 119 const char kChangeKind[] = "drive#change"; | |
| 120 const char kFileId[] = "fileId"; | |
| 121 const char kDeleted[] = "deleted"; | |
| 122 const char kFile[] = "file"; | |
| 123 | |
| 124 // Changes List | |
| 125 // https://developers.google.com/drive/v2/reference/changes/list | |
| 126 const char kChangeListKind[] = "drive#changeList"; | |
| 127 | |
| 128 // Google Apps MIME types: | |
| 129 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; | |
| 130 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; | |
| 131 const char kGoogleFormMimeType[] = "application/vnd.google-apps.form"; | |
| 132 const char kGooglePresentationMimeType[] = | |
| 133 "application/vnd.google-apps.presentation"; | |
| 134 const char kGoogleScriptMimeType[] = "application/vnd.google-apps.script"; | |
| 135 const char kGoogleSiteMimeType[] = "application/vnd.google-apps.site"; | |
| 136 const char kGoogleSpreadsheetMimeType[] = | |
| 137 "application/vnd.google-apps.spreadsheet"; | |
| 138 const char kGoogleTableMimeType[] = "application/vnd.google-apps.table"; | |
| 139 | |
| 140 // Maps category name to enum IconCategory. | |
| 141 struct AppIconCategoryMap { | |
| 142 gdata::DriveAppIcon::IconCategory category; | |
| 143 const char* category_name; | |
| 144 }; | |
| 145 | |
| 146 const AppIconCategoryMap kAppIconCategoryMap[] = { | |
| 147 { gdata::DriveAppIcon::DOCUMENT, "document" }, | |
| 148 { gdata::DriveAppIcon::APPLICATION, "application" }, | |
| 149 { gdata::DriveAppIcon::SHARED_DOCUMENT, "documentShared" }, | |
| 150 }; | |
| 151 | |
| 152 // Checks if the JSON is expected kind. In Drive API, JSON data structure has | |
| 153 // |kind| property which denotes the type of the structure (e.g. "drive#file"). | |
| 154 bool IsResourceKindExpected(const base::Value& value, | |
| 155 const std::string& expected_kind) { | |
| 156 const base::DictionaryValue* as_dict = NULL; | |
| 157 std::string kind; | |
| 158 return value.GetAsDictionary(&as_dict) && | |
| 159 as_dict->HasKey(kKind) && | |
| 160 as_dict->GetString(kKind, &kind) && | |
| 161 kind == expected_kind; | |
| 162 } | |
| 163 | |
| 164 } // namespace | |
| 165 | |
| 166 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371 | |
| 167 namespace gdata { | |
| 168 | |
| 169 //////////////////////////////////////////////////////////////////////////////// | |
| 170 // AboutResource implementation | |
| 171 | |
| 172 AboutResource::AboutResource() | |
| 173 : largest_change_id_(0), | |
| 174 quota_bytes_total_(0), | |
| 175 quota_bytes_used_(0) {} | |
| 176 | |
| 177 AboutResource::~AboutResource() {} | |
| 178 | |
| 179 // static | |
| 180 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { | |
| 181 scoped_ptr<AboutResource> resource(new AboutResource()); | |
| 182 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { | |
| 183 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; | |
| 184 return scoped_ptr<AboutResource>(NULL); | |
| 185 } | |
| 186 return resource.Pass(); | |
| 187 } | |
| 188 | |
| 189 // static | |
| 190 void AboutResource::RegisterJSONConverter( | |
| 191 base::JSONValueConverter<AboutResource>* converter) { | |
| 192 converter->RegisterCustomField<int64>(kLargestChangeId, | |
| 193 &AboutResource::largest_change_id_, | |
| 194 &base::StringToInt64); | |
| 195 converter->RegisterCustomField<int64>(kQuotaBytesTotal, | |
| 196 &AboutResource::quota_bytes_total_, | |
| 197 &base::StringToInt64); | |
| 198 converter->RegisterCustomField<int64>(kQuotaBytesUsed, | |
| 199 &AboutResource::quota_bytes_used_, | |
| 200 &base::StringToInt64); | |
| 201 converter->RegisterStringField(kRootFolderId, | |
| 202 &AboutResource::root_folder_id_); | |
| 203 } | |
| 204 | |
| 205 bool AboutResource::Parse(const base::Value& value) { | |
| 206 base::JSONValueConverter<AboutResource> converter; | |
| 207 if (!converter.Convert(value, this)) { | |
| 208 LOG(ERROR) << "Unable to parse: Invalid About resource JSON!"; | |
| 209 return false; | |
| 210 } | |
| 211 return true; | |
| 212 } | |
| 213 | |
| 214 //////////////////////////////////////////////////////////////////////////////// | |
| 215 // DriveAppIcon implementation | |
| 216 | |
| 217 DriveAppIcon::DriveAppIcon() {} | |
| 218 | |
| 219 DriveAppIcon::~DriveAppIcon() {} | |
| 220 | |
| 221 // static | |
| 222 void DriveAppIcon::RegisterJSONConverter( | |
| 223 base::JSONValueConverter<DriveAppIcon>* converter) { | |
| 224 converter->RegisterCustomField<IconCategory>( | |
| 225 kCategory, | |
| 226 &DriveAppIcon::category_, | |
| 227 &DriveAppIcon::GetIconCategory); | |
| 228 converter->RegisterIntField(kSize, &DriveAppIcon::icon_side_length_); | |
| 229 converter->RegisterCustomField<GURL>(kIconUrl, | |
| 230 &DriveAppIcon::icon_url_, | |
| 231 GetGURLFromString); | |
| 232 } | |
| 233 | |
| 234 // static | |
| 235 scoped_ptr<DriveAppIcon> DriveAppIcon::CreateFrom(const base::Value& value) { | |
| 236 scoped_ptr<DriveAppIcon> resource(new DriveAppIcon()); | |
| 237 if (!resource->Parse(value)) { | |
| 238 LOG(ERROR) << "Unable to create: Invalid DriveAppIcon JSON!"; | |
| 239 return scoped_ptr<DriveAppIcon>(NULL); | |
| 240 } | |
| 241 return resource.Pass(); | |
| 242 } | |
| 243 | |
| 244 bool DriveAppIcon::Parse(const base::Value& value) { | |
| 245 base::JSONValueConverter<DriveAppIcon> converter; | |
| 246 if (!converter.Convert(value, this)) { | |
| 247 LOG(ERROR) << "Unable to parse: Invalid DriveAppIcon"; | |
| 248 return false; | |
| 249 } | |
| 250 return true; | |
| 251 } | |
| 252 | |
| 253 // static | |
| 254 bool DriveAppIcon::GetIconCategory(const base::StringPiece& category, | |
| 255 DriveAppIcon::IconCategory* result) { | |
| 256 for (size_t i = 0; i < arraysize(kAppIconCategoryMap); i++) { | |
| 257 if (category == kAppIconCategoryMap[i].category_name) { | |
| 258 *result = kAppIconCategoryMap[i].category; | |
| 259 return true; | |
| 260 } | |
| 261 } | |
| 262 DVLOG(1) << "Unknown icon category " << category; | |
| 263 return false; | |
| 264 } | |
| 265 | |
| 266 //////////////////////////////////////////////////////////////////////////////// | |
| 267 // AppResource implementation | |
| 268 | |
| 269 AppResource::AppResource() {} | |
| 270 | |
| 271 AppResource::~AppResource() {} | |
| 272 | |
| 273 // static | |
| 274 void AppResource::RegisterJSONConverter( | |
| 275 base::JSONValueConverter<AppResource>* converter) { | |
| 276 converter->RegisterStringField(kId, &AppResource::application_id_); | |
| 277 converter->RegisterStringField(kName, &AppResource::name_); | |
| 278 converter->RegisterStringField(kObjectType, &AppResource::object_type_); | |
| 279 converter->RegisterBoolField(kSupportsCreate, &AppResource::supports_create_); | |
| 280 converter->RegisterBoolField(kSupportsImport, &AppResource::supports_import_); | |
| 281 converter->RegisterBoolField(kInstalled, &AppResource::installed_); | |
| 282 converter->RegisterBoolField(kAuthorized, &AppResource::authorized_); | |
| 283 converter->RegisterCustomField<GURL>(kProductUrl, | |
| 284 &AppResource::product_url_, | |
| 285 GetGURLFromString); | |
| 286 converter->RegisterRepeatedString(kPrimaryMimeTypes, | |
| 287 &AppResource::primary_mimetypes_); | |
| 288 converter->RegisterRepeatedString(kSecondaryMimeTypes, | |
| 289 &AppResource::secondary_mimetypes_); | |
| 290 converter->RegisterRepeatedString(kPrimaryFileExtensions, | |
| 291 &AppResource::primary_file_extensions_); | |
| 292 converter->RegisterRepeatedString(kSecondaryFileExtensions, | |
| 293 &AppResource::secondary_file_extensions_); | |
| 294 converter->RegisterRepeatedMessage(kIcons, &AppResource::icons_); | |
| 295 } | |
| 296 | |
| 297 // static | |
| 298 scoped_ptr<AppResource> AppResource::CreateFrom(const base::Value& value) { | |
| 299 scoped_ptr<AppResource> resource(new AppResource()); | |
| 300 if (!IsResourceKindExpected(value, kAppKind) || !resource->Parse(value)) { | |
| 301 LOG(ERROR) << "Unable to create: Invalid AppResource JSON!"; | |
| 302 return scoped_ptr<AppResource>(NULL); | |
| 303 } | |
| 304 return resource.Pass(); | |
| 305 } | |
| 306 | |
| 307 bool AppResource::Parse(const base::Value& value) { | |
| 308 base::JSONValueConverter<AppResource> converter; | |
| 309 if (!converter.Convert(value, this)) { | |
| 310 LOG(ERROR) << "Unable to parse: Invalid AppResource"; | |
| 311 return false; | |
| 312 } | |
| 313 return true; | |
| 314 } | |
| 315 | |
| 316 //////////////////////////////////////////////////////////////////////////////// | |
| 317 // AppList implementation | |
| 318 | |
| 319 AppList::AppList() {} | |
| 320 | |
| 321 AppList::~AppList() {} | |
| 322 | |
| 323 // static | |
| 324 void AppList::RegisterJSONConverter( | |
| 325 base::JSONValueConverter<AppList>* converter) { | |
| 326 converter->RegisterStringField(kETag, &AppList::etag_); | |
| 327 converter->RegisterRepeatedMessage<AppResource>(kItems, | |
| 328 &AppList::items_); | |
| 329 } | |
| 330 | |
| 331 // static | |
| 332 scoped_ptr<AppList> AppList::CreateFrom(const base::Value& value) { | |
| 333 scoped_ptr<AppList> resource(new AppList()); | |
| 334 if (!IsResourceKindExpected(value, kAppListKind) || !resource->Parse(value)) { | |
| 335 LOG(ERROR) << "Unable to create: Invalid AppList JSON!"; | |
| 336 return scoped_ptr<AppList>(NULL); | |
| 337 } | |
| 338 return resource.Pass(); | |
| 339 } | |
| 340 | |
| 341 bool AppList::Parse(const base::Value& value) { | |
| 342 base::JSONValueConverter<AppList> converter; | |
| 343 if (!converter.Convert(value, this)) { | |
| 344 LOG(ERROR) << "Unable to parse: Invalid AppList"; | |
| 345 return false; | |
| 346 } | |
| 347 return true; | |
| 348 } | |
| 349 | |
| 350 //////////////////////////////////////////////////////////////////////////////// | |
| 351 // ParentReference implementation | |
| 352 | |
| 353 ParentReference::ParentReference() : is_root_(false) {} | |
| 354 | |
| 355 ParentReference::~ParentReference() {} | |
| 356 | |
| 357 // static | |
| 358 void ParentReference::RegisterJSONConverter( | |
| 359 base::JSONValueConverter<ParentReference>* converter) { | |
| 360 converter->RegisterStringField(kId, &ParentReference::file_id_); | |
| 361 converter->RegisterCustomField<GURL>(kParentLink, | |
| 362 &ParentReference::parent_link_, | |
| 363 GetGURLFromString); | |
| 364 converter->RegisterBoolField(kIsRoot, &ParentReference::is_root_); | |
| 365 } | |
| 366 | |
| 367 // static | |
| 368 scoped_ptr<ParentReference> | |
| 369 ParentReference::CreateFrom(const base::Value& value) { | |
| 370 scoped_ptr<ParentReference> reference(new ParentReference()); | |
| 371 if (!IsResourceKindExpected(value, kParentReferenceKind) || | |
| 372 !reference->Parse(value)) { | |
| 373 LOG(ERROR) << "Unable to create: Invalid ParentRefernce JSON!"; | |
| 374 return scoped_ptr<ParentReference>(NULL); | |
| 375 } | |
| 376 return reference.Pass(); | |
| 377 } | |
| 378 | |
| 379 bool ParentReference::Parse(const base::Value& value) { | |
| 380 base::JSONValueConverter<ParentReference> converter; | |
| 381 if (!converter.Convert(value, this)) { | |
| 382 LOG(ERROR) << "Unable to parse: Invalid ParentReference"; | |
| 383 return false; | |
| 384 } | |
| 385 return true; | |
| 386 } | |
| 387 | |
| 388 //////////////////////////////////////////////////////////////////////////////// | |
| 389 // FileResource implementation | |
| 390 | |
| 391 FileResource::FileResource() : file_size_(0) {} | |
| 392 | |
| 393 FileResource::~FileResource() {} | |
| 394 | |
| 395 // static | |
| 396 void FileResource::RegisterJSONConverter( | |
| 397 base::JSONValueConverter<FileResource>* converter) { | |
| 398 converter->RegisterStringField(kId, &FileResource::file_id_); | |
| 399 converter->RegisterStringField(kETag, &FileResource::etag_); | |
| 400 converter->RegisterCustomField<GURL>(kSelfLink, | |
| 401 &FileResource::self_link_, | |
| 402 GetGURLFromString); | |
| 403 converter->RegisterStringField(kTitle, &FileResource::title_); | |
| 404 converter->RegisterStringField(kMimeType, &FileResource::mime_type_); | |
| 405 converter->RegisterNestedField(kLabels, &FileResource::labels_); | |
| 406 converter->RegisterCustomField<base::Time>( | |
| 407 kCreatedDate, | |
| 408 &FileResource::created_date_, | |
| 409 &gdata::util::GetTimeFromString); | |
| 410 converter->RegisterCustomField<base::Time>( | |
| 411 kModifiedByMeDate, | |
| 412 &FileResource::modified_by_me_date_, | |
| 413 &gdata::util::GetTimeFromString); | |
| 414 converter->RegisterCustomField<GURL>(kDownloadUrl, | |
| 415 &FileResource::download_url_, | |
| 416 GetGURLFromString); | |
| 417 converter->RegisterStringField(kFileExtension, | |
| 418 &FileResource::file_extension_); | |
| 419 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); | |
| 420 converter->RegisterCustomField<int64>(kFileSize, | |
| 421 &FileResource::file_size_, | |
| 422 &base::StringToInt64); | |
| 423 converter->RegisterCustomField<GURL>(kAlternateLink, | |
| 424 &FileResource::alternate_link_, | |
| 425 GetGURLFromString); | |
| 426 converter->RegisterCustomField<GURL>(kEmbedLink, | |
| 427 &FileResource::embed_link_, | |
| 428 GetGURLFromString); | |
| 429 converter->RegisterRepeatedMessage<ParentReference>(kParents, | |
| 430 &FileResource::parents_); | |
| 431 converter->RegisterCustomField<GURL>(kThumbnailLink, | |
| 432 &FileResource::thumbnail_link_, | |
| 433 GetGURLFromString); | |
| 434 converter->RegisterCustomField<GURL>(kWebContentLink, | |
| 435 &FileResource::web_content_link_, | |
| 436 GetGURLFromString); | |
| 437 } | |
| 438 | |
| 439 // static | |
| 440 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { | |
| 441 scoped_ptr<FileResource> resource(new FileResource()); | |
| 442 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { | |
| 443 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; | |
| 444 return scoped_ptr<FileResource>(NULL); | |
| 445 } | |
| 446 return resource.Pass(); | |
| 447 } | |
| 448 | |
| 449 bool FileResource::IsDirectory() const { | |
| 450 return mime_type_ == kDriveFolderMimeType; | |
| 451 } | |
| 452 | |
| 453 DriveEntryKind FileResource::GetKind() const { | |
| 454 if (mime_type() == kGoogleDocumentMimeType) | |
| 455 return ENTRY_KIND_DOCUMENT; | |
| 456 if (mime_type() == kGoogleSpreadsheetMimeType) | |
| 457 return ENTRY_KIND_SPREADSHEET; | |
| 458 if (mime_type() == kGooglePresentationMimeType) | |
| 459 return ENTRY_KIND_PRESENTATION; | |
| 460 if (mime_type() == kGoogleDrawingMimeType) | |
| 461 return ENTRY_KIND_DRAWING; | |
| 462 if (mime_type() == kGoogleTableMimeType) | |
| 463 return ENTRY_KIND_TABLE; | |
| 464 if (mime_type() == kDriveFolderMimeType) | |
| 465 return ENTRY_KIND_FOLDER; | |
| 466 if (mime_type() == "application/pdf") | |
| 467 return ENTRY_KIND_PDF; | |
| 468 return ENTRY_KIND_FILE; | |
| 469 } | |
| 470 | |
| 471 bool FileResource::Parse(const base::Value& value) { | |
| 472 base::JSONValueConverter<FileResource> converter; | |
| 473 if (!converter.Convert(value, this)) { | |
| 474 LOG(ERROR) << "Unable to parse: Invalid FileResource"; | |
| 475 return false; | |
| 476 } | |
| 477 return true; | |
| 478 } | |
| 479 | |
| 480 //////////////////////////////////////////////////////////////////////////////// | |
| 481 // FileList implementation | |
| 482 | |
| 483 FileList::FileList() {} | |
| 484 | |
| 485 FileList::~FileList() {} | |
| 486 | |
| 487 // static | |
| 488 void FileList::RegisterJSONConverter( | |
| 489 base::JSONValueConverter<FileList>* converter) { | |
| 490 converter->RegisterStringField(kETag, &FileList::etag_); | |
| 491 converter->RegisterStringField(kNextPageToken, &FileList::next_page_token_); | |
| 492 converter->RegisterCustomField<GURL>(kNextLink, | |
| 493 &FileList::next_link_, | |
| 494 GetGURLFromString); | |
| 495 converter->RegisterRepeatedMessage<FileResource>(kItems, | |
| 496 &FileList::items_); | |
| 497 } | |
| 498 | |
| 499 // static | |
| 500 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { | |
| 501 scoped_ptr<FileList> resource(new FileList()); | |
| 502 if (!IsResourceKindExpected(value, kFileListKind) || | |
| 503 !resource->Parse(value)) { | |
| 504 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; | |
| 505 return scoped_ptr<FileList>(NULL); | |
| 506 } | |
| 507 return resource.Pass(); | |
| 508 } | |
| 509 | |
| 510 bool FileList::Parse(const base::Value& value) { | |
| 511 base::JSONValueConverter<FileList> converter; | |
| 512 if (!converter.Convert(value, this)) { | |
| 513 LOG(ERROR) << "Unable to parse: Invalid FileList"; | |
| 514 return false; | |
| 515 } | |
| 516 return true; | |
| 517 } | |
| 518 | |
| 519 //////////////////////////////////////////////////////////////////////////////// | |
| 520 // ChangeResource implementation | |
| 521 | |
| 522 ChangeResource::ChangeResource() : change_id_(0), deleted_(false) {} | |
| 523 | |
| 524 ChangeResource::~ChangeResource() {} | |
| 525 | |
| 526 // static | |
| 527 void ChangeResource::RegisterJSONConverter( | |
| 528 base::JSONValueConverter<ChangeResource>* converter) { | |
| 529 converter->RegisterCustomField<int64>(kId, | |
| 530 &ChangeResource::change_id_, | |
| 531 &base::StringToInt64); | |
| 532 converter->RegisterStringField(kFileId, &ChangeResource::file_id_); | |
| 533 converter->RegisterBoolField(kDeleted, &ChangeResource::deleted_); | |
| 534 converter->RegisterNestedField(kFile, &ChangeResource::file_); | |
| 535 } | |
| 536 | |
| 537 // static | |
| 538 scoped_ptr<ChangeResource> | |
| 539 ChangeResource::CreateFrom(const base::Value& value) { | |
| 540 scoped_ptr<ChangeResource> resource(new ChangeResource()); | |
| 541 if (!IsResourceKindExpected(value, kChangeKind) || !resource->Parse(value)) { | |
| 542 LOG(ERROR) << "Unable to create: Invalid ChangeResource JSON!"; | |
| 543 return scoped_ptr<ChangeResource>(NULL); | |
| 544 } | |
| 545 return resource.Pass(); | |
| 546 } | |
| 547 | |
| 548 bool ChangeResource::Parse(const base::Value& value) { | |
| 549 base::JSONValueConverter<ChangeResource> converter; | |
| 550 if (!converter.Convert(value, this)) { | |
| 551 LOG(ERROR) << "Unable to parse: Invalid ChangeResource"; | |
| 552 return false; | |
| 553 } | |
| 554 return true; | |
| 555 } | |
| 556 | |
| 557 //////////////////////////////////////////////////////////////////////////////// | |
| 558 // ChangeList implementation | |
| 559 | |
| 560 ChangeList::ChangeList() : largest_change_id_(0) {} | |
| 561 | |
| 562 ChangeList::~ChangeList() {} | |
| 563 | |
| 564 // static | |
| 565 void ChangeList::RegisterJSONConverter( | |
| 566 base::JSONValueConverter<ChangeList>* converter) { | |
| 567 converter->RegisterStringField(kETag, &ChangeList::etag_); | |
| 568 converter->RegisterStringField(kNextPageToken, &ChangeList::next_page_token_); | |
| 569 converter->RegisterCustomField<GURL>(kNextLink, | |
| 570 &ChangeList::next_link_, | |
| 571 GetGURLFromString); | |
| 572 converter->RegisterCustomField<int64>(kLargestChangeId, | |
| 573 &ChangeList::largest_change_id_, | |
| 574 &base::StringToInt64); | |
| 575 converter->RegisterRepeatedMessage<ChangeResource>(kItems, | |
| 576 &ChangeList::items_); | |
| 577 } | |
| 578 | |
| 579 // static | |
| 580 scoped_ptr<ChangeList> ChangeList::CreateFrom(const base::Value& value) { | |
| 581 scoped_ptr<ChangeList> resource(new ChangeList()); | |
| 582 if (!IsResourceKindExpected(value, kChangeListKind) || | |
| 583 !resource->Parse(value)) { | |
| 584 LOG(ERROR) << "Unable to create: Invalid ChangeList JSON!"; | |
| 585 return scoped_ptr<ChangeList>(NULL); | |
| 586 } | |
| 587 return resource.Pass(); | |
| 588 } | |
| 589 | |
| 590 bool ChangeList::Parse(const base::Value& value) { | |
| 591 base::JSONValueConverter<ChangeList> converter; | |
| 592 if (!converter.Convert(value, this)) { | |
| 593 LOG(ERROR) << "Unable to parse: Invalid ChangeList"; | |
| 594 return false; | |
| 595 } | |
| 596 return true; | |
| 597 } | |
| 598 | |
| 599 | |
| 600 //////////////////////////////////////////////////////////////////////////////// | |
| 601 // FileLabels implementation | |
| 602 | |
| 603 FileLabels::FileLabels() | |
| 604 : starred_(false), | |
| 605 hidden_(false), | |
| 606 trashed_(false), | |
| 607 restricted_(false), | |
| 608 viewed_(false) {} | |
| 609 | |
| 610 FileLabels::~FileLabels() {} | |
| 611 | |
| 612 // static | |
| 613 void FileLabels::RegisterJSONConverter( | |
| 614 base::JSONValueConverter<FileLabels>* converter) { | |
| 615 converter->RegisterBoolField(kLabelStarred, &FileLabels::starred_); | |
| 616 converter->RegisterBoolField(kLabelHidden, &FileLabels::hidden_); | |
| 617 converter->RegisterBoolField(kLabelTrashed, &FileLabels::trashed_); | |
| 618 converter->RegisterBoolField(kLabelRestricted, &FileLabels::restricted_); | |
| 619 converter->RegisterBoolField(kLabelViewed, &FileLabels::viewed_); | |
| 620 } | |
| 621 | |
| 622 // static | |
| 623 scoped_ptr<FileLabels> FileLabels::CreateFrom(const base::Value& value) { | |
| 624 scoped_ptr<FileLabels> resource(new FileLabels()); | |
| 625 if (!resource->Parse(value)) { | |
| 626 LOG(ERROR) << "Unable to create: Invalid FileLabels JSON!"; | |
| 627 return scoped_ptr<FileLabels>(NULL); | |
| 628 } | |
| 629 return resource.Pass(); | |
| 630 } | |
| 631 | |
| 632 bool FileLabels::Parse(const base::Value& value) { | |
| 633 base::JSONValueConverter<FileLabels> converter; | |
| 634 if (!converter.Convert(value, this)) { | |
| 635 LOG(ERROR) << "Unable to parse: Invalid FileLabels"; | |
| 636 return false; | |
| 637 } | |
| 638 return true; | |
| 639 } | |
| 640 | |
| 641 } // namespace gdata | |
| OLD | NEW |