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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/json/json_value_converter.h" | 8 #include "base/json/json_value_converter.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 const char kKind[] = "kind"; | 92 const char kKind[] = "kind"; |
93 const char kId[] = "id"; | 93 const char kId[] = "id"; |
94 const char kETag[] = "etag"; | 94 const char kETag[] = "etag"; |
95 const char kItems[] = "items"; | 95 const char kItems[] = "items"; |
96 const char kLargestChangeId[] = "largestChangeId"; | 96 const char kLargestChangeId[] = "largestChangeId"; |
97 | 97 |
98 // About Resource | 98 // About Resource |
99 // https://developers.google.com/drive/v2/reference/about | 99 // https://developers.google.com/drive/v2/reference/about |
100 const char kAboutKind[] = "drive#about"; | 100 const char kAboutKind[] = "drive#about"; |
101 const char kQuotaBytesTotal[] = "quotaBytesTotal"; | 101 const char kQuotaBytesTotal[] = "quotaBytesTotal"; |
102 const char kQuotaBytesUsed[] = "quotaBytesUsed"; | 102 const char kQuotaBytesUsedAggregate[] = "quotaBytesUsedAggregate"; |
103 const char kRootFolderId[] = "rootFolderId"; | 103 const char kRootFolderId[] = "rootFolderId"; |
104 | 104 |
105 // App Icon | 105 // App Icon |
106 // https://developers.google.com/drive/v2/reference/apps | 106 // https://developers.google.com/drive/v2/reference/apps |
107 const char kCategory[] = "category"; | 107 const char kCategory[] = "category"; |
108 const char kSize[] = "size"; | 108 const char kSize[] = "size"; |
109 const char kIconUrl[] = "iconUrl"; | 109 const char kIconUrl[] = "iconUrl"; |
110 | 110 |
111 // Apps Resource | 111 // Apps Resource |
112 // https://developers.google.com/drive/v2/reference/apps | 112 // https://developers.google.com/drive/v2/reference/apps |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 } | 202 } |
203 | 203 |
204 } // namespace | 204 } // namespace |
205 | 205 |
206 //////////////////////////////////////////////////////////////////////////////// | 206 //////////////////////////////////////////////////////////////////////////////// |
207 // AboutResource implementation | 207 // AboutResource implementation |
208 | 208 |
209 AboutResource::AboutResource() | 209 AboutResource::AboutResource() |
210 : largest_change_id_(0), | 210 : largest_change_id_(0), |
211 quota_bytes_total_(0), | 211 quota_bytes_total_(0), |
212 quota_bytes_used_(0) {} | 212 quota_bytes_used_aggregate_(0) {} |
213 | 213 |
214 AboutResource::~AboutResource() {} | 214 AboutResource::~AboutResource() {} |
215 | 215 |
216 // static | 216 // static |
217 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { | 217 scoped_ptr<AboutResource> AboutResource::CreateFrom(const base::Value& value) { |
218 scoped_ptr<AboutResource> resource(new AboutResource()); | 218 scoped_ptr<AboutResource> resource(new AboutResource()); |
219 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { | 219 if (!IsResourceKindExpected(value, kAboutKind) || !resource->Parse(value)) { |
220 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; | 220 LOG(ERROR) << "Unable to create: Invalid About resource JSON!"; |
221 return scoped_ptr<AboutResource>(); | 221 return scoped_ptr<AboutResource>(); |
222 } | 222 } |
223 return resource.Pass(); | 223 return resource.Pass(); |
224 } | 224 } |
225 | 225 |
226 // static | 226 // static |
227 void AboutResource::RegisterJSONConverter( | 227 void AboutResource::RegisterJSONConverter( |
228 base::JSONValueConverter<AboutResource>* converter) { | 228 base::JSONValueConverter<AboutResource>* converter) { |
229 converter->RegisterCustomField<int64>(kLargestChangeId, | 229 converter->RegisterCustomField<int64>(kLargestChangeId, |
230 &AboutResource::largest_change_id_, | 230 &AboutResource::largest_change_id_, |
231 &base::StringToInt64); | 231 &base::StringToInt64); |
232 converter->RegisterCustomField<int64>(kQuotaBytesTotal, | 232 converter->RegisterCustomField<int64>(kQuotaBytesTotal, |
233 &AboutResource::quota_bytes_total_, | 233 &AboutResource::quota_bytes_total_, |
234 &base::StringToInt64); | 234 &base::StringToInt64); |
235 converter->RegisterCustomField<int64>(kQuotaBytesUsed, | 235 converter->RegisterCustomField<int64>( |
236 &AboutResource::quota_bytes_used_, | 236 kQuotaBytesUsedAggregate, |
237 &base::StringToInt64); | 237 &AboutResource::quota_bytes_used_aggregate_, |
| 238 &base::StringToInt64); |
238 converter->RegisterStringField(kRootFolderId, | 239 converter->RegisterStringField(kRootFolderId, |
239 &AboutResource::root_folder_id_); | 240 &AboutResource::root_folder_id_); |
240 } | 241 } |
241 | 242 |
242 bool AboutResource::Parse(const base::Value& value) { | 243 bool AboutResource::Parse(const base::Value& value) { |
243 base::JSONValueConverter<AboutResource> converter; | 244 base::JSONValueConverter<AboutResource> converter; |
244 if (!converter.Convert(value, this)) { | 245 if (!converter.Convert(value, this)) { |
245 LOG(ERROR) << "Unable to parse: Invalid About resource JSON!"; | 246 LOG(ERROR) << "Unable to parse: Invalid About resource JSON!"; |
246 return false; | 247 return false; |
247 } | 248 } |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 bool ImageMediaMetadata::Parse(const base::Value& value) { | 702 bool ImageMediaMetadata::Parse(const base::Value& value) { |
702 base::JSONValueConverter<ImageMediaMetadata> converter; | 703 base::JSONValueConverter<ImageMediaMetadata> converter; |
703 if (!converter.Convert(value, this)) { | 704 if (!converter.Convert(value, this)) { |
704 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; | 705 LOG(ERROR) << "Unable to parse: Invalid ImageMediaMetadata."; |
705 return false; | 706 return false; |
706 } | 707 } |
707 return true; | 708 return true; |
708 } | 709 } |
709 | 710 |
710 } // namespace google_apis | 711 } // namespace google_apis |
OLD | NEW |