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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 // Parses and initializes data members from content of |value|. | 251 // Parses and initializes data members from content of |value|. |
252 // Return false if parsing fails. | 252 // Return false if parsing fails. |
253 bool Parse(const base::Value& value); | 253 bool Parse(const base::Value& value); |
254 | 254 |
255 std::string etag_; | 255 std::string etag_; |
256 ScopedVector<AppResource> items_; | 256 ScopedVector<AppResource> items_; |
257 | 257 |
258 DISALLOW_COPY_AND_ASSIGN(AppList); | 258 DISALLOW_COPY_AND_ASSIGN(AppList); |
259 }; | 259 }; |
260 | 260 |
261 // FileResource reporesents a file or folder metadata in Drive. | 261 // ParentReference represents a directory. |
262 // https://developers.google.com/drive/v2/reference/parents | |
263 class ParentReference { | |
264 public: | |
265 ~ParentReference(); | |
266 | |
267 // Registers the mapping between JSON field names and the members in this | |
268 // class. | |
269 static void RegisterJSONConverter( | |
270 base::JSONValueConverter<ParentReference>* converter); | |
271 | |
272 // Creates parent reference from parsed JSON. | |
273 static scoped_ptr<ParentReference> CreateFrom(const base::Value& value); | |
274 | |
275 // Returns the file id of the reference. | |
276 const std::string& file_id() const { return file_id_; } | |
277 | |
278 // Returns true if the reference is root directory. | |
279 bool is_root() const { return is_root_; } | |
280 | |
281 private: | |
282 friend class base::internal::RepeatedMessageConverter<ParentReference>; | |
283 ParentReference(); | |
284 | |
285 // Parses and initializes data members from content of |value|. | |
286 // Return false if parsing fails. | |
287 bool Parse(const base::Value& value); | |
288 | |
289 std::string file_id_; | |
290 bool is_root_; | |
291 | |
292 DISALLOW_COPY_AND_ASSIGN(ParentReference); | |
293 }; | |
294 | |
295 // FileResource represents a file or folder metadata in Drive. | |
262 // https://developers.google.com/drive/v2/reference/files | 296 // https://developers.google.com/drive/v2/reference/files |
263 class FileResource { | 297 class FileResource { |
264 public: | 298 public: |
265 ~FileResource(); | 299 ~FileResource(); |
266 | 300 |
267 // Registers the mapping between JSON field names and the members in this | 301 // Registers the mapping between JSON field names and the members in this |
268 // class. | 302 // class. |
269 static void RegisterJSONConverter( | 303 static void RegisterJSONConverter( |
270 base::JSONValueConverter<FileResource>* converter); | 304 base::JSONValueConverter<FileResource>* converter); |
305 | |
306 // Creates file resource from parsed JSON. | |
271 static scoped_ptr<FileResource> CreateFrom(const base::Value& value); | 307 static scoped_ptr<FileResource> CreateFrom(const base::Value& value); |
272 | 308 |
273 // Returns true if this is a directory. | 309 // Returns true if this is a directory. |
274 // Note: "folder" is used elsewhere in this file to match Drive API reference, | 310 // Note: "folder" is used elsewhere in this file to match Drive API reference, |
275 // but outside this file we use "directory" to match HTML5 filesystem API. | 311 // but outside this file we use "directory" to match HTML5 filesystem API. |
276 bool IsDirectory() const; | 312 bool IsDirectory() const; |
277 | 313 |
278 // Returns file ID. This is unique in all files in Google Drive. | 314 // Returns file ID. This is unique in all files in Google Drive. |
279 const std::string& file_id() const { return file_id_; } | 315 const std::string& file_id() const { return file_id_; } |
280 | 316 |
281 // Returns ETag for this file. | 317 // Returns ETag for this file. |
282 const std::string& etag() const { return etag_; } | 318 const std::string& etag() const { return etag_; } |
283 | 319 |
284 // Returns MIME type of this file. | 320 // Returns MIME type of this file. |
285 const std::string& mime_type() const { return mime_type_; } | 321 const std::string& mime_type() const { return mime_type_; } |
286 | 322 |
287 // Returns the title of this file. | 323 // Returns the title of this file. |
288 const std::string& title() const { return title_; } | 324 const std::string& title() const { return title_; } |
289 | 325 |
290 // Returns modification time by the user. | 326 // Returns modification time by the user. |
291 const base::Time& modified_by_me_date() const { return modified_by_me_date_; } | 327 const base::Time& modified_by_me_date() const { return modified_by_me_date_; } |
292 | 328 |
329 // Returns parent references (directories) of this file. | |
330 const ScopedVector<ParentReference>& parents() const { return parents_; } | |
331 | |
293 // Returns the download URL. | 332 // Returns the download URL. |
294 const GURL& download_url() const { return download_url_; } | 333 const GURL& download_url() const { return download_url_; } |
295 | 334 |
296 // Returns the extension part of the filename. | 335 // Returns the extension part of the filename. |
297 const std::string& file_extension() const { return file_extension_; } | 336 const std::string& file_extension() const { return file_extension_; } |
298 | 337 |
299 // Returns MD5 checksum of this file. | 338 // Returns MD5 checksum of this file. |
300 const std::string& md5_checksum() const { return md5_checksum_; } | 339 const std::string& md5_checksum() const { return md5_checksum_; } |
301 | 340 |
302 // Returns the size of this file in bytes. | 341 // Returns the size of this file in bytes. |
303 int64 file_size() const { return file_size_; } | 342 int64 file_size() const { return file_size_; } |
304 | 343 |
305 private: | 344 private: |
306 friend class base::internal::RepeatedMessageConverter<FileResource>; | 345 friend class base::internal::RepeatedMessageConverter<FileResource>; |
346 friend class ChangeResource; | |
307 friend class FileList; | 347 friend class FileList; |
308 FileResource(); | 348 FileResource(); |
309 | 349 |
310 // Parses and initializes data members from content of |value|. | 350 // Parses and initializes data members from content of |value|. |
311 // Return false if parsing fails. | 351 // Return false if parsing fails. |
312 bool Parse(const base::Value& value); | 352 bool Parse(const base::Value& value); |
313 | 353 |
314 std::string file_id_; | 354 std::string file_id_; |
315 std::string etag_; | 355 std::string etag_; |
316 std::string mime_type_; | 356 std::string mime_type_; |
317 std::string title_; | 357 std::string title_; |
318 base::Time modified_by_me_date_; | 358 base::Time modified_by_me_date_; |
359 ScopedVector<ParentReference> parents_; | |
319 GURL download_url_; | 360 GURL download_url_; |
320 std::string file_extension_; | 361 std::string file_extension_; |
321 std::string md5_checksum_; | 362 std::string md5_checksum_; |
322 int64 file_size_; | 363 int64 file_size_; |
323 | 364 |
324 DISALLOW_COPY_AND_ASSIGN(FileResource); | 365 DISALLOW_COPY_AND_ASSIGN(FileResource); |
325 }; | 366 }; |
326 | 367 |
327 // FileList represents a collection of files and folders. | 368 // FileList represents a collection of files and folders. |
328 // https://developers.google.com/drive/v2/reference/files/list | 369 // https://developers.google.com/drive/v2/reference/files/list |
329 class FileList { | 370 class FileList { |
330 public: | 371 public: |
331 ~FileList(); | 372 ~FileList(); |
332 | 373 |
333 // Registers the mapping between JSON field names and the members in this | 374 // Registers the mapping between JSON field names and the members in this |
334 // class. | 375 // class. |
335 static void RegisterJSONConverter( | 376 static void RegisterJSONConverter( |
336 base::JSONValueConverter<FileList>* converter); | 377 base::JSONValueConverter<FileList>* converter); |
378 | |
379 // Creates file list from parsed JSON. | |
337 static scoped_ptr<FileList> CreateFrom(const base::Value& value); | 380 static scoped_ptr<FileList> CreateFrom(const base::Value& value); |
338 | 381 |
339 // Returns the ETag of the list. | 382 // Returns the ETag of the list. |
340 const std::string& etag() const { return etag_; } | 383 const std::string& etag() const { return etag_; } |
341 | 384 |
342 // Returns the page token for the next page of files, if the list is large | 385 // Returns the page token for the next page of files, if the list is large |
343 // to fit in one response. If this is empty, there is no more file lists. | 386 // to fit in one response. If this is empty, there is no more file lists. |
344 const std::string& next_page_token() const { return next_page_token_; } | 387 const std::string& next_page_token() const { return next_page_token_; } |
345 | 388 |
346 // Returns a link to the next page of files. The URL includes the next page | 389 // Returns a link to the next page of files. The URL includes the next page |
(...skipping 13 matching lines...) Expand all Loading... | |
360 bool Parse(const base::Value& value); | 403 bool Parse(const base::Value& value); |
361 | 404 |
362 std::string etag_; | 405 std::string etag_; |
363 std::string next_page_token_; | 406 std::string next_page_token_; |
364 GURL next_link_; | 407 GURL next_link_; |
365 ScopedVector<FileResource> items_; | 408 ScopedVector<FileResource> items_; |
366 | 409 |
367 DISALLOW_COPY_AND_ASSIGN(FileList); | 410 DISALLOW_COPY_AND_ASSIGN(FileList); |
368 }; | 411 }; |
369 | 412 |
413 // ChangeResource represents a change in a file. | |
414 // https://developers.google.com/drive/v2/reference/changes | |
415 class ChangeResource { | |
416 public: | |
417 ~ChangeResource(); | |
418 | |
419 // Registers the mapping between JSON field names and the members in this | |
420 // class. | |
421 static void RegisterJSONConverter( | |
422 base::JSONValueConverter<ChangeResource>* converter); | |
423 | |
424 // Creates change resource from parsed JSON. | |
425 static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value); | |
426 | |
427 // Returns change ID for this change. This is a monotonically increasing | |
428 // number. | |
429 int64 change_id() const { return change_id_; } | |
satorux1
2012/08/02 19:39:18
please add a blank line between accessors.
| |
430 // Returns a string file ID for corresponding file of the change. | |
431 const std::string& file_id() const { return file_id_; } | |
432 // Returns true if this file is deleted in the change. | |
433 bool is_deleted() const { return deleted_; } | |
434 // Returns FileResource of the file which the change refers to. | |
435 const FileResource& file() const { return file_; } | |
436 | |
437 private: | |
438 friend class base::internal::RepeatedMessageConverter<ChangeResource>; | |
439 friend class ChangeList; | |
440 ChangeResource(); | |
441 | |
442 // Parses and initializes data members from content of |value|. | |
443 // Return false if parsing fails. | |
444 bool Parse(const base::Value& value); | |
445 | |
446 int64 change_id_; | |
447 std::string file_id_; | |
448 bool deleted_; | |
449 FileResource file_; | |
450 | |
451 DISALLOW_COPY_AND_ASSIGN(ChangeResource); | |
452 }; | |
453 | |
454 // ChangeList represents a set of changes in the drive. | |
455 // https://developers.google.com/drive/v2/reference/changes/list | |
456 class ChangeList { | |
457 public: | |
458 ~ChangeList(); | |
459 | |
460 // Registers the mapping between JSON field names and the members in this | |
461 // class. | |
462 static void RegisterJSONConverter( | |
463 base::JSONValueConverter<ChangeList>* converter); | |
464 | |
465 // Creates change list from parsed JSON. | |
466 static scoped_ptr<ChangeList> CreateFrom(const base::Value& value); | |
467 | |
468 // Returns the ETag of the list. | |
469 const std::string& etag() const { return etag_; } | |
470 | |
471 // Returns the page token for the next page of files, if the list is large | |
472 // to fit in one response. If this is empty, there is no more file lists. | |
473 const std::string& next_page_token() const { return next_page_token_; } | |
474 | |
475 // Returns a link to the next page of files. The URL includes the next page | |
476 // token. | |
477 const GURL& next_link() const { return next_link_; } | |
478 | |
479 // Returns the largest change ID number. | |
480 int64 largest_change_id() const { return largest_change_id_; } | |
481 | |
482 // Returns a set of changes in this list. | |
483 const ScopedVector<ChangeResource>& items() const { return items_; } | |
484 | |
485 private: | |
486 friend class DriveAPIParserTest; | |
487 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); | |
488 ChangeList(); | |
489 | |
490 // Parses and initializes data members from content of |value|. | |
491 // Return false if parsing fails. | |
492 bool Parse(const base::Value& value); | |
493 | |
494 std::string etag_; | |
495 std::string next_page_token_; | |
496 GURL next_link_; | |
497 int64 largest_change_id_; | |
498 ScopedVector<ChangeResource> items_; | |
499 | |
500 DISALLOW_COPY_AND_ASSIGN(ChangeList); | |
501 }; | |
502 | |
370 } // namespace gdata | 503 } // namespace gdata |
371 | 504 |
372 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 505 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
OLD | NEW |