Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / drive / drive_api_parser.h
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 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/strings/string_piece.h"
15 #include "base/time/time.h"
16 #include "url/gurl.h"
17
18 namespace base {
19 class Value;
20 template <class StructType>
21 class JSONValueConverter;
22
23 namespace internal {
24 template <class NestedType>
25 class RepeatedMessageConverter;
26 }  // namespace internal
27 }  // namespace base
28
29 namespace google_apis {
30
31 // About resource represents the account information about the current user.
32 // https://developers.google.com/drive/v2/reference/about
33 class AboutResource {
34  public:
35   AboutResource();
36   ~AboutResource();
37
38   // Registers the mapping between JSON field names and the members in this
39   // class.
40   static void RegisterJSONConverter(
41       base::JSONValueConverter<AboutResource>* converter);
42
43   // Creates about resource from parsed JSON.
44   static scoped_ptr<AboutResource> CreateFrom(const base::Value& value);
45
46   // Returns the largest change ID number.
47   int64 largest_change_id() const { return largest_change_id_; }
48   // Returns total number of quota bytes.
49   int64 quota_bytes_total() const { return quota_bytes_total_; }
50   // Returns the number of quota bytes used.
51   int64 quota_bytes_used() const { return quota_bytes_used_; }
52   // Returns root folder ID.
53   const std::string& root_folder_id() const { return root_folder_id_; }
54
55   void set_largest_change_id(int64 largest_change_id) {
56     largest_change_id_ = largest_change_id;
57   }
58   void set_quota_bytes_total(int64 quota_bytes_total) {
59     quota_bytes_total_ = quota_bytes_total;
60   }
61   void set_quota_bytes_used(int64 quota_bytes_used) {
62     quota_bytes_used_ = quota_bytes_used;
63   }
64   void set_root_folder_id(const std::string& root_folder_id) {
65     root_folder_id_ = root_folder_id;
66   }
67
68  private:
69   friend class DriveAPIParserTest;
70   FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser);
71
72   // Parses and initializes data members from content of |value|.
73   // Return false if parsing fails.
74   bool Parse(const base::Value& value);
75
76   int64 largest_change_id_;
77   int64 quota_bytes_total_;
78   int64 quota_bytes_used_;
79   std::string root_folder_id_;
80
81   // This class is copyable on purpose.
82 };
83
84 // DriveAppIcon represents an icon for Drive Application.
85 // https://developers.google.com/drive/v2/reference/apps
86 class DriveAppIcon {
87  public:
88   enum IconCategory {
89     UNKNOWN,          // Uninitialized state.
90     DOCUMENT,         // Icon for a file associated with the app.
91     APPLICATION,      // Icon for the application.
92     SHARED_DOCUMENT,  // Icon for a shared file associated with the app.
93   };
94
95   DriveAppIcon();
96   ~DriveAppIcon();
97
98   // Registers the mapping between JSON field names and the members in this
99   // class.
100   static void RegisterJSONConverter(
101       base::JSONValueConverter<DriveAppIcon>* converter);
102
103   // Creates drive app icon instance from parsed JSON.
104   static scoped_ptr<DriveAppIcon> CreateFrom(const base::Value& value);
105
106   // Category of the icon.
107   IconCategory category() const { return category_; }
108
109   // Size in pixels of one side of the icon (icons are always square).
110   int icon_side_length() const { return icon_side_length_; }
111
112   // Returns URL for this icon.
113   const GURL& icon_url() const { return icon_url_; }
114
115   void set_category(IconCategory category) {
116     category_ = category;
117   }
118   void set_icon_side_length(int icon_side_length) {
119     icon_side_length_ = icon_side_length;
120   }
121   void set_icon_url(const GURL& icon_url) {
122     icon_url_ = icon_url;
123   }
124
125  private:
126   // Parses and initializes data members from content of |value|.
127   // Return false if parsing fails.
128   bool Parse(const base::Value& value);
129
130   // Extracts the icon category from the given string. Returns false and does
131   // not change |result| when |scheme| has an unrecognizable value.
132   static bool GetIconCategory(const base::StringPiece& category,
133                               IconCategory* result);
134
135   friend class base::internal::RepeatedMessageConverter<DriveAppIcon>;
136   friend class AppResource;
137
138   IconCategory category_;
139   int icon_side_length_;
140   GURL icon_url_;
141
142   DISALLOW_COPY_AND_ASSIGN(DriveAppIcon);
143 };
144
145 // AppResource represents a Drive Application.
146 // https://developers.google.com/drive/v2/reference/apps
147 class AppResource {
148  public:
149   ~AppResource();
150   AppResource();
151
152   // Registers the mapping between JSON field names and the members in this
153   // class.
154   static void RegisterJSONConverter(
155       base::JSONValueConverter<AppResource>* converter);
156
157   // Creates app resource from parsed JSON.
158   static scoped_ptr<AppResource> CreateFrom(const base::Value& value);
159
160   // Returns application ID, which is 12-digit decimals (e.g. "123456780123").
161   const std::string& application_id() const { return application_id_; }
162
163   // Returns application name.
164   const std::string& name() const { return name_; }
165
166   // Returns the name of the type of object this application creates.
167   // This is used for displaying in "Create" menu item for this app.
168   // If empty, application name is used instead.
169   const std::string& object_type() const { return object_type_; }
170
171   // Returns the product ID.
172   const std::string& product_id() const { return product_id_; }
173
174   // Returns whether this application supports creating new objects.
175   bool supports_create() const { return supports_create_; }
176
177   // Returns whether this application supports importing Google Docs.
178   bool supports_import() const { return supports_import_; }
179
180   // Returns whether this application is installed.
181   bool is_installed() const { return installed_; }
182
183   // Returns whether this application is authorized to access data on the
184   // user's Drive.
185   bool is_authorized() const { return authorized_; }
186
187   // Returns whether this application is removable by apps.delete API.
188   bool is_removable() const { return removable_; }
189
190   // Returns the create URL, i.e., the URL for opening a new file by the app.
191   const GURL& create_url() const { return create_url_; }
192
193   // List of primary mime types supported by this WebApp. Primary status should
194   // trigger this WebApp becoming the default handler of file instances that
195   // have these mime types.
196   const ScopedVector<std::string>& primary_mimetypes() const {
197     return primary_mimetypes_;
198   }
199
200   // List of secondary mime types supported by this WebApp. Secondary status
201   // should make this WebApp show up in "Open with..." pop-up menu of the
202   // default action menu for file with matching mime types.
203   const ScopedVector<std::string>& secondary_mimetypes() const {
204     return secondary_mimetypes_;
205   }
206
207   // List of primary file extensions supported by this WebApp. Primary status
208   // should trigger this WebApp becoming the default handler of file instances
209   // that match these extensions.
210   const ScopedVector<std::string>& primary_file_extensions() const {
211     return primary_file_extensions_;
212   }
213
214   // List of secondary file extensions supported by this WebApp. Secondary
215   // status should make this WebApp show up in "Open with..." pop-up menu of the
216   // default action menu for file with matching extensions.
217   const ScopedVector<std::string>& secondary_file_extensions() const {
218     return secondary_file_extensions_;
219   }
220
221   // Returns Icons for this application.  An application can have multiple
222   // icons for different purpose (application, document, shared document)
223   // in several sizes.
224   const ScopedVector<DriveAppIcon>& icons() const {
225     return icons_;
226   }
227
228   void set_application_id(const std::string& application_id) {
229     application_id_ = application_id;
230   }
231   void set_name(const std::string& name) { name_ = name; }
232   void set_object_type(const std::string& object_type) {
233     object_type_ = object_type;
234   }
235   void set_product_id(const std::string& id) { product_id_ = id; }
236   void set_supports_create(bool supports_create) {
237     supports_create_ = supports_create;
238   }
239   void set_supports_import(bool supports_import) {
240     supports_import_ = supports_import;
241   }
242   void set_installed(bool installed) { installed_ = installed; }
243   void set_authorized(bool authorized) { authorized_ = authorized; }
244   void set_removable(bool removable) { removable_ = removable; }
245   void set_primary_mimetypes(
246       ScopedVector<std::string> primary_mimetypes) {
247     primary_mimetypes_ = primary_mimetypes.Pass();
248   }
249   void set_secondary_mimetypes(
250       ScopedVector<std::string> secondary_mimetypes) {
251     secondary_mimetypes_ = secondary_mimetypes.Pass();
252   }
253   void set_primary_file_extensions(
254       ScopedVector<std::string> primary_file_extensions) {
255     primary_file_extensions_ = primary_file_extensions.Pass();
256   }
257   void set_secondary_file_extensions(
258       ScopedVector<std::string> secondary_file_extensions) {
259     secondary_file_extensions_ = secondary_file_extensions.Pass();
260   }
261   void set_icons(ScopedVector<DriveAppIcon> icons) {
262     icons_ = icons.Pass();
263   }
264   void set_create_url(const GURL& url) {
265     create_url_ = url;
266   }
267
268  private:
269   friend class base::internal::RepeatedMessageConverter<AppResource>;
270   friend class AppList;
271
272   // Parses and initializes data members from content of |value|.
273   // Return false if parsing fails.
274   bool Parse(const base::Value& value);
275
276   std::string application_id_;
277   std::string name_;
278   std::string object_type_;
279   std::string product_id_;
280   bool supports_create_;
281   bool supports_import_;
282   bool installed_;
283   bool authorized_;
284   bool removable_;
285   GURL create_url_;
286   ScopedVector<std::string> primary_mimetypes_;
287   ScopedVector<std::string> secondary_mimetypes_;
288   ScopedVector<std::string> primary_file_extensions_;
289   ScopedVector<std::string> secondary_file_extensions_;
290   ScopedVector<DriveAppIcon> icons_;
291
292   DISALLOW_COPY_AND_ASSIGN(AppResource);
293 };
294
295 // AppList represents a list of Drive Applications.
296 // https://developers.google.com/drive/v2/reference/apps/list
297 class AppList {
298  public:
299   AppList();
300   ~AppList();
301
302   // Registers the mapping between JSON field names and the members in this
303   // class.
304   static void RegisterJSONConverter(
305       base::JSONValueConverter<AppList>* converter);
306
307   // Creates app list from parsed JSON.
308   static scoped_ptr<AppList> CreateFrom(const base::Value& value);
309
310   // ETag for this resource.
311   const std::string& etag() const { return etag_; }
312
313   // Returns a vector of applications.
314   const ScopedVector<AppResource>& items() const { return items_; }
315
316   void set_etag(const std::string& etag) {
317     etag_ = etag;
318   }
319   void set_items(ScopedVector<AppResource> items) {
320     items_ = items.Pass();
321   }
322
323  private:
324   friend class DriveAPIParserTest;
325   FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser);
326
327   // Parses and initializes data members from content of |value|.
328   // Return false if parsing fails.
329   bool Parse(const base::Value& value);
330
331   std::string etag_;
332   ScopedVector<AppResource> items_;
333
334   DISALLOW_COPY_AND_ASSIGN(AppList);
335 };
336
337 // ParentReference represents a directory.
338 // https://developers.google.com/drive/v2/reference/parents
339 class ParentReference {
340  public:
341   ParentReference();
342   ~ParentReference();
343
344   // Registers the mapping between JSON field names and the members in this
345   // class.
346   static void RegisterJSONConverter(
347       base::JSONValueConverter<ParentReference>* converter);
348
349   // Creates parent reference from parsed JSON.
350   static scoped_ptr<ParentReference> CreateFrom(const base::Value& value);
351
352   // Returns the file id of the reference.
353   const std::string& file_id() const { return file_id_; }
354
355   // Returns the URL for the parent in Drive.
356   const GURL& parent_link() const { return parent_link_; }
357
358   // Returns true if the reference is root directory.
359   bool is_root() const { return is_root_; }
360
361   void set_file_id(const std::string& file_id) { file_id_ = file_id; }
362   void set_parent_link(const GURL& parent_link) {
363     parent_link_ = parent_link;
364   }
365   void set_is_root(bool is_root) { is_root_ = is_root; }
366
367  private:
368   friend class base::internal::RepeatedMessageConverter<ParentReference>;
369
370   // Parses and initializes data members from content of |value|.
371   // Return false if parsing fails.
372   bool Parse(const base::Value& value);
373
374   std::string file_id_;
375   GURL parent_link_;
376   bool is_root_;
377
378   DISALLOW_COPY_AND_ASSIGN(ParentReference);
379 };
380
381 // FileLabels represents labels for file or folder.
382 // https://developers.google.com/drive/v2/reference/files
383 class FileLabels {
384  public:
385   FileLabels();
386   ~FileLabels();
387
388   // Registers the mapping between JSON field names and the members in this
389   // class.
390   static void RegisterJSONConverter(
391       base::JSONValueConverter<FileLabels>* converter);
392
393   // Creates about resource from parsed JSON.
394   static scoped_ptr<FileLabels> CreateFrom(const base::Value& value);
395
396   // Whether this file is starred by the user.
397   bool is_starred() const { return starred_; }
398   // Whether this file is hidden from the user.
399   bool is_hidden() const { return hidden_; }
400   // Whether this file has been trashed.
401   bool is_trashed() const { return trashed_; }
402   // Whether viewers are prevented from downloading this file.
403   bool is_restricted() const { return restricted_; }
404   // Whether this file has been viewed by this user.
405   bool is_viewed() const { return viewed_; }
406
407   void set_starred(bool starred) { starred_ = starred; }
408   void set_hidden(bool hidden) { hidden_ = hidden; }
409   void set_trashed(bool trashed) { trashed_ = trashed; }
410   void set_restricted(bool restricted) { restricted_ = restricted; }
411   void set_viewed(bool viewed) { viewed_ = viewed; }
412
413  private:
414   friend class FileResource;
415
416   // Parses and initializes data members from content of |value|.
417   // Return false if parsing fails.
418   bool Parse(const base::Value& value);
419
420   bool starred_;
421   bool hidden_;
422   bool trashed_;
423   bool restricted_;
424   bool viewed_;
425
426   DISALLOW_COPY_AND_ASSIGN(FileLabels);
427 };
428
429 // ImageMediaMetadata represents image metadata for a file.
430 // https://developers.google.com/drive/v2/reference/files
431 class ImageMediaMetadata {
432  public:
433   ImageMediaMetadata();
434   ~ImageMediaMetadata();
435
436   // Registers the mapping between JSON field names and the members in this
437   // class.
438   static void RegisterJSONConverter(
439       base::JSONValueConverter<ImageMediaMetadata>* converter);
440
441   // Creates about resource from parsed JSON.
442   static scoped_ptr<ImageMediaMetadata> CreateFrom(const base::Value& value);
443
444   // Width of the image in pixels.
445   int width() const { return width_; }
446   // Height of the image in pixels.
447   int height() const { return height_; }
448   // Rotation of the image in clockwise degrees.
449   int rotation() const { return rotation_; }
450
451   void set_width(int width) { width_ = width; }
452   void set_height(int height) { height_ = height; }
453   void set_rotation(int rotation) { rotation_ = rotation; }
454
455  private:
456   friend class FileResource;
457
458   // Parses and initializes data members from content of |value|.
459   // Return false if parsing fails.
460   bool Parse(const base::Value& value);
461
462   int width_;
463   int height_;
464   int rotation_;
465
466   DISALLOW_COPY_AND_ASSIGN(ImageMediaMetadata);
467 };
468
469
470 // FileResource represents a file or folder metadata in Drive.
471 // https://developers.google.com/drive/v2/reference/files
472 class FileResource {
473  public:
474   // Link to open a file resource on a web app with |app_id|.
475   struct OpenWithLink {
476     std::string app_id;
477     GURL open_url;
478   };
479
480   FileResource();
481   ~FileResource();
482
483   // Registers the mapping between JSON field names and the members in this
484   // class.
485   static void RegisterJSONConverter(
486       base::JSONValueConverter<FileResource>* converter);
487
488   // Creates file resource from parsed JSON.
489   static scoped_ptr<FileResource> CreateFrom(const base::Value& value);
490
491   // Returns true if this is a directory.
492   // Note: "folder" is used elsewhere in this file to match Drive API reference,
493   // but outside this file we use "directory" to match HTML5 filesystem API.
494   bool IsDirectory() const;
495
496   // Returns file ID.  This is unique in all files in Google Drive.
497   const std::string& file_id() const { return file_id_; }
498
499   // Returns ETag for this file.
500   const std::string& etag() const { return etag_; }
501
502   // Returns the link to JSON of this file itself.
503   const GURL& self_link() const { return self_link_; }
504
505   // Returns the title of this file.
506   const std::string& title() const { return title_; }
507
508   // Returns MIME type of this file.
509   const std::string& mime_type() const { return mime_type_; }
510
511   // Returns labels for this file.
512   const FileLabels& labels() const { return labels_; }
513
514   // Returns image media metadata for this file.
515   const ImageMediaMetadata& image_media_metadata() const {
516     return image_media_metadata_;
517   }
518
519   // Returns created time of this file.
520   const base::Time& created_date() const { return created_date_; }
521
522   // Returns modified time of this file.
523   const base::Time& modified_date() const { return modified_date_; }
524
525   // Returns modification time by the user.
526   const base::Time& modified_by_me_date() const { return modified_by_me_date_; }
527
528   // Returns last access time by the user.
529   const base::Time& last_viewed_by_me_date() const {
530     return last_viewed_by_me_date_;
531   }
532
533   // Returns time when the file was shared with the user.
534   const base::Time& shared_with_me_date() const {
535     return shared_with_me_date_;
536   }
537
538   // Returns the 'shared' attribute of the file.
539   bool shared() const { return shared_; }
540
541   // Returns the short-lived download URL for the file.  This field exists
542   // only when the file content is stored in Drive.
543   const GURL& download_url() const { return download_url_; }
544
545   // Returns the extension part of the filename.
546   const std::string& file_extension() const { return file_extension_; }
547
548   // Returns MD5 checksum of this file.
549   const std::string& md5_checksum() const { return md5_checksum_; }
550
551   // Returns the size of this file in bytes.
552   int64 file_size() const { return file_size_; }
553
554   // Return the link to open the file in Google editor or viewer.
555   // E.g. Google Document, Google Spreadsheet.
556   const GURL& alternate_link() const { return alternate_link_; }
557
558   // Returns the link for embedding the file.
559   const GURL& embed_link() const { return embed_link_; }
560
561   // Returns parent references (directories) of this file.
562   const ScopedVector<ParentReference>& parents() const { return parents_; }
563   ScopedVector<ParentReference>* mutable_parents() { return &parents_; }
564
565   // Returns the link to the file's thumbnail.
566   const GURL& thumbnail_link() const { return thumbnail_link_; }
567
568   // Returns the link to open its downloadable content, using cookie based
569   // authentication.
570   const GURL& web_content_link() const { return web_content_link_; }
571
572   // Returns the list of links to open the resource with a web app.
573   const std::vector<OpenWithLink>& open_with_links() const {
574     return open_with_links_;
575   }
576
577   void set_file_id(const std::string& file_id) {
578     file_id_ = file_id;
579   }
580   void set_etag(const std::string& etag) {
581     etag_ = etag;
582   }
583   void set_self_link(const GURL& self_link) {
584     self_link_ = self_link;
585   }
586   void set_title(const std::string& title) {
587     title_ = title;
588   }
589   void set_mime_type(const std::string& mime_type) {
590     mime_type_ = mime_type;
591   }
592   FileLabels* mutable_labels() {
593     return &labels_;
594   }
595   ImageMediaMetadata* mutable_image_media_metadata() {
596     return &image_media_metadata_;
597   }
598   void set_created_date(const base::Time& created_date) {
599     created_date_ = created_date;
600   }
601   void set_modified_date(const base::Time& modified_date) {
602     modified_date_ = modified_date;
603   }
604   void set_modified_by_me_date(const base::Time& modified_by_me_date) {
605     modified_by_me_date_ = modified_by_me_date;
606   }
607   void set_last_viewed_by_me_date(const base::Time& last_viewed_by_me_date) {
608     last_viewed_by_me_date_ = last_viewed_by_me_date;
609   }
610   void set_shared_with_me_date(const base::Time& shared_with_me_date) {
611     shared_with_me_date_ = shared_with_me_date;
612   }
613   void set_shared(bool shared) {
614     shared_ = shared;
615   }
616   void set_download_url(const GURL& download_url) {
617     download_url_ = download_url;
618   }
619   void set_file_extension(const std::string& file_extension) {
620     file_extension_ = file_extension;
621   }
622   void set_md5_checksum(const std::string& md5_checksum) {
623     md5_checksum_ = md5_checksum;
624   }
625   void set_file_size(int64 file_size) {
626     file_size_ = file_size;
627   }
628   void set_alternate_link(const GURL& alternate_link) {
629     alternate_link_ = alternate_link;
630   }
631   void set_embed_link(const GURL& embed_link) {
632     embed_link_ = embed_link;
633   }
634   void set_parents(ScopedVector<ParentReference> parents) {
635     parents_ = parents.Pass();
636   }
637   void set_thumbnail_link(const GURL& thumbnail_link) {
638     thumbnail_link_ = thumbnail_link;
639   }
640   void set_web_content_link(const GURL& web_content_link) {
641     web_content_link_ = web_content_link;
642   }
643
644  private:
645   friend class base::internal::RepeatedMessageConverter<FileResource>;
646   friend class ChangeResource;
647   friend class FileList;
648
649   // Parses and initializes data members from content of |value|.
650   // Return false if parsing fails.
651   bool Parse(const base::Value& value);
652
653   std::string file_id_;
654   std::string etag_;
655   GURL self_link_;
656   std::string title_;
657   std::string mime_type_;
658   FileLabels labels_;
659   ImageMediaMetadata image_media_metadata_;
660   base::Time created_date_;
661   base::Time modified_date_;
662   base::Time modified_by_me_date_;
663   base::Time last_viewed_by_me_date_;
664   base::Time shared_with_me_date_;
665   bool shared_;
666   GURL download_url_;
667   std::string file_extension_;
668   std::string md5_checksum_;
669   int64 file_size_;
670   GURL alternate_link_;
671   GURL embed_link_;
672   ScopedVector<ParentReference> parents_;
673   GURL thumbnail_link_;
674   GURL web_content_link_;
675   std::vector<OpenWithLink> open_with_links_;
676
677   DISALLOW_COPY_AND_ASSIGN(FileResource);
678 };
679
680 // FileList represents a collection of files and folders.
681 // https://developers.google.com/drive/v2/reference/files/list
682 class FileList {
683  public:
684   FileList();
685   ~FileList();
686
687   // Registers the mapping between JSON field names and the members in this
688   // class.
689   static void RegisterJSONConverter(
690       base::JSONValueConverter<FileList>* converter);
691
692   // Returns true if the |value| has kind field for FileList.
693   static bool HasFileListKind(const base::Value& value);
694
695   // Creates file list from parsed JSON.
696   static scoped_ptr<FileList> CreateFrom(const base::Value& value);
697
698   // Returns the ETag of the list.
699   const std::string& etag() const { return etag_; }
700
701   // Returns the page token for the next page of files, if the list is large
702   // to fit in one response.  If this is empty, there is no more file lists.
703   const std::string& next_page_token() const { return next_page_token_; }
704
705   // Returns a link to the next page of files.  The URL includes the next page
706   // token.
707   const GURL& next_link() const { return next_link_; }
708
709   // Returns a set of files in this list.
710   const ScopedVector<FileResource>& items() const { return items_; }
711
712   void set_etag(const std::string& etag) {
713     etag_ = etag;
714   }
715   void set_next_page_token(const std::string& next_page_token) {
716     next_page_token_ = next_page_token;
717   }
718   void set_next_link(const GURL& next_link) {
719     next_link_ = next_link;
720   }
721   void set_items(ScopedVector<FileResource> items) {
722     items_ = items.Pass();
723   }
724
725  private:
726   friend class DriveAPIParserTest;
727   FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, FileListParser);
728
729   // Parses and initializes data members from content of |value|.
730   // Return false if parsing fails.
731   bool Parse(const base::Value& value);
732
733   std::string etag_;
734   std::string next_page_token_;
735   GURL next_link_;
736   ScopedVector<FileResource> items_;
737
738   DISALLOW_COPY_AND_ASSIGN(FileList);
739 };
740
741 // ChangeResource represents a change in a file.
742 // https://developers.google.com/drive/v2/reference/changes
743 class ChangeResource {
744  public:
745   ChangeResource();
746   ~ChangeResource();
747
748   // Registers the mapping between JSON field names and the members in this
749   // class.
750   static void RegisterJSONConverter(
751       base::JSONValueConverter<ChangeResource>* converter);
752
753   // Creates change resource from parsed JSON.
754   static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value);
755
756   // Returns change ID for this change.  This is a monotonically increasing
757   // number.
758   int64 change_id() const { return change_id_; }
759
760   // Returns a string file ID for corresponding file of the change.
761   const std::string& file_id() const { return file_id_; }
762
763   // Returns true if this file is deleted in the change.
764   bool is_deleted() const { return deleted_; }
765
766   // Returns FileResource of the file which the change refers to.
767   const FileResource* file() const { return file_.get(); }
768   FileResource* mutable_file() { return file_.get(); }
769
770   void set_change_id(int64 change_id) {
771     change_id_ = change_id;
772   }
773   void set_file_id(const std::string& file_id) {
774     file_id_ = file_id;
775   }
776   void set_deleted(bool deleted) {
777     deleted_ = deleted;
778   }
779   void set_file(scoped_ptr<FileResource> file) {
780     file_ = file.Pass();
781   }
782
783  private:
784   friend class base::internal::RepeatedMessageConverter<ChangeResource>;
785   friend class ChangeList;
786
787   // Parses and initializes data members from content of |value|.
788   // Return false if parsing fails.
789   bool Parse(const base::Value& value);
790
791   int64 change_id_;
792   std::string file_id_;
793   bool deleted_;
794   scoped_ptr<FileResource> file_;
795
796   DISALLOW_COPY_AND_ASSIGN(ChangeResource);
797 };
798
799 // ChangeList represents a set of changes in the drive.
800 // https://developers.google.com/drive/v2/reference/changes/list
801 class ChangeList {
802  public:
803   ChangeList();
804   ~ChangeList();
805
806   // Registers the mapping between JSON field names and the members in this
807   // class.
808   static void RegisterJSONConverter(
809       base::JSONValueConverter<ChangeList>* converter);
810
811   // Returns true if the |value| has kind field for ChangeList.
812   static bool HasChangeListKind(const base::Value& value);
813
814   // Creates change list from parsed JSON.
815   static scoped_ptr<ChangeList> CreateFrom(const base::Value& value);
816
817   // Returns the ETag of the list.
818   const std::string& etag() const { return etag_; }
819
820   // Returns the page token for the next page of files, if the list is large
821   // to fit in one response.  If this is empty, there is no more file lists.
822   const std::string& next_page_token() const { return next_page_token_; }
823
824   // Returns a link to the next page of files.  The URL includes the next page
825   // token.
826   const GURL& next_link() const { return next_link_; }
827
828   // Returns the largest change ID number.
829   int64 largest_change_id() const { return largest_change_id_; }
830
831   // Returns a set of changes in this list.
832   const ScopedVector<ChangeResource>& items() const { return items_; }
833
834   void set_etag(const std::string& etag) {
835     etag_ = etag;
836   }
837   void set_next_page_token(const std::string& next_page_token) {
838     next_page_token_ = next_page_token;
839   }
840   void set_next_link(const GURL& next_link) {
841     next_link_ = next_link;
842   }
843   void set_largest_change_id(int64 largest_change_id) {
844     largest_change_id_ = largest_change_id;
845   }
846   void set_items(ScopedVector<ChangeResource> items) {
847     items_ = items.Pass();
848   }
849
850  private:
851   friend class DriveAPIParserTest;
852   FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser);
853
854   // Parses and initializes data members from content of |value|.
855   // Return false if parsing fails.
856   bool Parse(const base::Value& value);
857
858   std::string etag_;
859   std::string next_page_token_;
860   GURL next_link_;
861   int64 largest_change_id_;
862   ScopedVector<ChangeResource> items_;
863
864   DISALLOW_COPY_AND_ASSIGN(ChangeList);
865 };
866
867 }  // namespace google_apis
868
869 #endif  // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_