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