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 16 matching lines...) Expand all Loading... |
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 // Common | 35 // Common |
36 const char kKind[] = "kind"; | 36 const char kKind[] = "kind"; |
| 37 const char kId[] = "id"; |
| 38 const char kETag[] = "etag"; |
| 39 const char kItems[] = "items"; |
37 | 40 |
38 // About Resource: | 41 // About Resource: |
39 const char kAboutKind[] = "drive#about"; | 42 const char kAboutKind[] = "drive#about"; |
40 const char kRootFolderId[] = "rootFolderId"; | 43 const char kRootFolderId[] = "rootFolderId"; |
41 const char kQuotaBytesTotal[] = "quotaBytesTotal"; | 44 const char kQuotaBytesTotal[] = "quotaBytesTotal"; |
42 const char kQuotaBytesUsed[] = "quotaBytesUsed"; | 45 const char kQuotaBytesUsed[] = "quotaBytesUsed"; |
43 const char kLargestChangeId[] = "largestChangeId"; | 46 const char kLargestChangeId[] = "largestChangeId"; |
44 | 47 |
45 // App Icon: | 48 // App Icon: |
46 const char kCategory[] = "category"; | 49 const char kCategory[] = "category"; |
47 const char kSize[] = "size"; | 50 const char kSize[] = "size"; |
48 const char kIconUrl[] = "iconUrl"; | 51 const char kIconUrl[] = "iconUrl"; |
49 | 52 |
50 // Apps Resource: | 53 // Apps Resource: |
51 const char kAppKind[] = "drive#app"; | 54 const char kAppKind[] = "drive#app"; |
52 const char kId[] = "id"; | |
53 const char kETag[] = "etag"; | |
54 const char kName[] = "name"; | 55 const char kName[] = "name"; |
55 const char kObjectType[] = "objectType"; | 56 const char kObjectType[] = "objectType"; |
56 const char kSupportsCreate[] = "supportsCreate"; | 57 const char kSupportsCreate[] = "supportsCreate"; |
57 const char kSupportsImport[] = "supportsImport"; | 58 const char kSupportsImport[] = "supportsImport"; |
58 const char kInstalled[] = "installed"; | 59 const char kInstalled[] = "installed"; |
59 const char kAuthorized[] = "authorized"; | 60 const char kAuthorized[] = "authorized"; |
60 const char kProductUrl[] = "productUrl"; | 61 const char kProductUrl[] = "productUrl"; |
61 const char kPrimaryMimeTypes[] = "primaryMimeTypes"; | 62 const char kPrimaryMimeTypes[] = "primaryMimeTypes"; |
62 const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; | 63 const char kSecondaryMimeTypes[] = "secondaryMimeTypes"; |
63 const char kPrimaryFileExtensions[] = "primaryFileExtensions"; | 64 const char kPrimaryFileExtensions[] = "primaryFileExtensions"; |
64 const char kSecondaryFileExtensions[] = "secondaryFileExtensions"; | 65 const char kSecondaryFileExtensions[] = "secondaryFileExtensions"; |
65 const char kIcons[] = "icons"; | 66 const char kIcons[] = "icons"; |
66 | 67 |
67 // Apps List: | 68 // Apps List: |
68 const char kAppListKind[] = "drive#appList"; | 69 const char kAppListKind[] = "drive#appList"; |
69 const char kItems[] = "items"; | |
70 | 70 |
| 71 // File Resource: |
| 72 const char kFileKind[] = "drive#file"; |
| 73 const char kMimeType[] = "mimeType"; |
| 74 const char kTitle[] = "title"; |
| 75 const char kModifiedByMeDate[] = "modifiedByMeDate"; |
| 76 const char kDownloadUrl[] = "downloadUrl"; |
| 77 const char kFileExtension[] = "fileExtension"; |
| 78 const char kMd5Checksum[] = "md5Checksum"; |
| 79 const char kFileSize[] = "fileSize"; |
| 80 |
| 81 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; |
| 82 |
| 83 // Files List: |
| 84 const char kFileListKind[] = "drive#fileList"; |
| 85 const char kNextPageToken[] = "nextPageToken"; |
| 86 const char kNextLink[] = "nextLink"; |
71 | 87 |
72 // Maps category name to enum IconCategory. | 88 // Maps category name to enum IconCategory. |
73 struct AppIconCategoryMap { | 89 struct AppIconCategoryMap { |
74 gdata::DriveAppIcon::IconCategory category; | 90 gdata::DriveAppIcon::IconCategory category; |
75 const char* category_name; | 91 const char* category_name; |
76 }; | 92 }; |
77 | 93 |
78 const AppIconCategoryMap kAppIconCategoryMap[] = { | 94 const AppIconCategoryMap kAppIconCategoryMap[] = { |
79 { gdata::DriveAppIcon::DOCUMENT, "document" }, | 95 { gdata::DriveAppIcon::DOCUMENT, "document" }, |
80 { gdata::DriveAppIcon::APPLICATION, "application" }, | 96 { gdata::DriveAppIcon::APPLICATION, "application" }, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
199 // AppResource implementation | 215 // AppResource implementation |
200 | 216 |
201 AppResource::AppResource() {} | 217 AppResource::AppResource() {} |
202 | 218 |
203 AppResource::~AppResource() {} | 219 AppResource::~AppResource() {} |
204 | 220 |
205 // static | 221 // static |
206 void AppResource::RegisterJSONConverter( | 222 void AppResource::RegisterJSONConverter( |
207 base::JSONValueConverter<AppResource>* converter) { | 223 base::JSONValueConverter<AppResource>* converter) { |
208 converter->RegisterStringField(kId, &AppResource::id_); | 224 converter->RegisterStringField(kId, &AppResource::application_id_); |
209 converter->RegisterStringField(kName, &AppResource::name_); | 225 converter->RegisterStringField(kName, &AppResource::name_); |
210 converter->RegisterStringField(kObjectType, &AppResource::object_type_); | 226 converter->RegisterStringField(kObjectType, &AppResource::object_type_); |
211 converter->RegisterBoolField(kSupportsCreate, &AppResource::supports_create_); | 227 converter->RegisterBoolField(kSupportsCreate, &AppResource::supports_create_); |
212 converter->RegisterBoolField(kSupportsImport, &AppResource::supports_import_); | 228 converter->RegisterBoolField(kSupportsImport, &AppResource::supports_import_); |
213 converter->RegisterBoolField(kInstalled, &AppResource::installed_); | 229 converter->RegisterBoolField(kInstalled, &AppResource::installed_); |
214 converter->RegisterBoolField(kAuthorized, &AppResource::authorized_); | 230 converter->RegisterBoolField(kAuthorized, &AppResource::authorized_); |
215 converter->RegisterCustomField<GURL>(kProductUrl, | 231 converter->RegisterCustomField<GURL>(kProductUrl, |
216 &AppResource::product_url_, | 232 &AppResource::product_url_, |
217 GetGURLFromString); | 233 GetGURLFromString); |
218 converter->RegisterRepeatedString(kPrimaryMimeTypes, | 234 converter->RegisterRepeatedString(kPrimaryMimeTypes, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 288 |
273 bool AppList::Parse(const base::Value& value) { | 289 bool AppList::Parse(const base::Value& value) { |
274 base::JSONValueConverter<AppList> converter; | 290 base::JSONValueConverter<AppList> converter; |
275 if (!converter.Convert(value, this)) { | 291 if (!converter.Convert(value, this)) { |
276 LOG(ERROR) << "Unable to parse: Invalid AppList"; | 292 LOG(ERROR) << "Unable to parse: Invalid AppList"; |
277 return false; | 293 return false; |
278 } | 294 } |
279 return true; | 295 return true; |
280 } | 296 } |
281 | 297 |
| 298 //////////////////////////////////////////////////////////////////////////////// |
| 299 // FileResource implementation |
| 300 |
| 301 FileResource::FileResource() {} |
| 302 |
| 303 FileResource::~FileResource() {} |
| 304 |
| 305 // static |
| 306 void FileResource::RegisterJSONConverter( |
| 307 base::JSONValueConverter<FileResource>* converter) { |
| 308 converter->RegisterStringField(kId, &FileResource::file_id_); |
| 309 converter->RegisterStringField(kETag, &FileResource::etag_); |
| 310 converter->RegisterStringField(kMimeType, &FileResource::mime_type_); |
| 311 converter->RegisterStringField(kTitle, &FileResource::title_); |
| 312 converter->RegisterCustomField<base::Time>( |
| 313 kModifiedByMeDate, |
| 314 &FileResource::modified_by_me_date_, |
| 315 &gdata::util::GetTimeFromString); |
| 316 converter->RegisterCustomField<GURL>(kDownloadUrl, |
| 317 &FileResource::download_url_, |
| 318 GetGURLFromString); |
| 319 converter->RegisterStringField(kFileExtension, |
| 320 &FileResource::file_extension_); |
| 321 converter->RegisterStringField(kMd5Checksum, &FileResource::md5_checksum_); |
| 322 converter->RegisterCustomField<int64>(kFileSize, |
| 323 &FileResource::file_size_, |
| 324 &base::StringToInt64); |
| 325 } |
| 326 |
| 327 // static |
| 328 scoped_ptr<FileResource> FileResource::CreateFrom(const base::Value& value) { |
| 329 scoped_ptr<FileResource> resource(new FileResource()); |
| 330 if (!IsResourceKindExpected(value, kFileKind) || !resource->Parse(value)) { |
| 331 LOG(ERROR) << "Unable to create: Invalid FileResource JSON!"; |
| 332 return scoped_ptr<FileResource>(NULL); |
| 333 } |
| 334 return resource.Pass(); |
| 335 } |
| 336 |
| 337 bool FileResource::IsDirectory() const { |
| 338 return mime_type_ == kDriveFolderMimeType; |
| 339 } |
| 340 |
| 341 bool FileResource::Parse(const base::Value& value) { |
| 342 base::JSONValueConverter<FileResource> converter; |
| 343 if (!converter.Convert(value, this)) { |
| 344 LOG(ERROR) << "Unable to parse: Invalid FileResource"; |
| 345 return false; |
| 346 } |
| 347 return true; |
| 348 } |
| 349 |
| 350 //////////////////////////////////////////////////////////////////////////////// |
| 351 // FileList implementation |
| 352 |
| 353 FileList::FileList() {} |
| 354 |
| 355 FileList::~FileList() {} |
| 356 |
| 357 // static |
| 358 void FileList::RegisterJSONConverter( |
| 359 base::JSONValueConverter<FileList>* converter) { |
| 360 converter->RegisterStringField(kETag, &FileList::etag_); |
| 361 converter->RegisterStringField(kNextPageToken, &FileList::next_page_token_); |
| 362 converter->RegisterCustomField<GURL>(kNextLink, |
| 363 &FileList::next_link_, |
| 364 GetGURLFromString); |
| 365 converter->RegisterRepeatedMessage<FileResource>(kItems, |
| 366 &FileList::items_); |
| 367 } |
| 368 |
| 369 // static |
| 370 scoped_ptr<FileList> FileList::CreateFrom(const base::Value& value) { |
| 371 scoped_ptr<FileList> resource(new FileList()); |
| 372 if (!IsResourceKindExpected(value, kFileListKind) || |
| 373 !resource->Parse(value)) { |
| 374 LOG(ERROR) << "Unable to create: Invalid FileList JSON!"; |
| 375 return scoped_ptr<FileList>(NULL); |
| 376 } |
| 377 return resource.Pass(); |
| 378 } |
| 379 |
| 380 bool FileList::Parse(const base::Value& value) { |
| 381 base::JSONValueConverter<FileList> converter; |
| 382 if (!converter.Convert(value, this)) { |
| 383 LOG(ERROR) << "Unable to parse: Invalid FileList"; |
| 384 return false; |
| 385 } |
| 386 return true; |
| 387 } |
| 388 |
282 } // namespace gdata | 389 } // namespace gdata |
OLD | NEW |