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.
5 #ifndef GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_
6 #define GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/strings/string_piece.h"
16 #include "base/time/time.h"
17 #include "google_apis/drive/drive_entry_kinds.h"
22 class DictionaryValue
;
25 template <class StructType
>
26 class JSONValueConverter
;
29 template <class NestedType
>
30 class RepeatedMessageConverter
;
31 } // namespace internal
35 // Defines data elements of Google Documents API as described in
36 // http://code.google.com/apis/documents/.
37 namespace google_apis
{
39 // Defines link (URL) of an entity (document, file, feed...). Each entity could
40 // have more than one link representing it.
56 LINK_RESUMABLE_EDIT_MEDIA
,
57 LINK_RESUMABLE_CREATE_MEDIA
,
70 // Registers the mapping between JSON field names and the members in
72 static void RegisterJSONConverter(base::JSONValueConverter
<Link
>* converter
);
75 LinkType
type() const { return type_
; }
78 const GURL
& href() const { return href_
; }
81 const std::string
& title() const { return title_
; }
83 // For OPEN_WITH links, this contains the application ID. For all other link
84 // types, it is the empty string.
85 const std::string
& app_id() const { return app_id_
; }
88 const std::string
& mime_type() const { return mime_type_
; }
90 void set_type(LinkType type
) { type_
= type
; }
91 void set_href(const GURL
& href
) { href_
= href
; }
92 void set_title(const std::string
& title
) { title_
= title
; }
93 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
94 void set_mime_type(const std::string
& mime_type
) { mime_type_
= mime_type
; }
97 friend class ResourceEntry
;
98 // Converts value of link.rel into LinkType. Outputs to |type| and returns
99 // true when |rel| has a valid value. Otherwise does nothing and returns
101 static bool GetLinkType(const base::StringPiece
& rel
, LinkType
* type
);
103 // Converts value of link.rel to application ID, if there is one embedded in
104 // the link.rel field. Outputs to |app_id| and returns true when |rel| has a
105 // valid value. Otherwise does nothing and returns false.
106 static bool GetAppID(const base::StringPiece
& rel
, std::string
* app_id
);
112 std::string mime_type_
;
114 DISALLOW_COPY_AND_ASSIGN(Link
);
117 // Feed links define links (URLs) to special list of entries (i.e. list of
118 // previous document revisions).
121 enum ResourceLinkType
{
128 // Registers the mapping between JSON field names and the members in
130 static void RegisterJSONConverter(
131 base::JSONValueConverter
<ResourceLink
>* converter
);
133 // MIME type of the feed.
134 ResourceLinkType
type() const { return type_
; }
137 const GURL
& href() const { return href_
; }
139 void set_type(ResourceLinkType type
) { type_
= type
; }
140 void set_href(const GURL
& href
) { href_
= href
; }
143 friend class ResourceEntry
;
144 // Converts value of gd$feedLink.rel into ResourceLinkType enum.
145 // Outputs to |result| and returns true when |rel| has a valid
146 // value. Otherwise does nothing and returns false.
147 static bool GetFeedLinkType(
148 const base::StringPiece
& rel
, ResourceLinkType
* result
);
150 ResourceLinkType type_
;
153 DISALLOW_COPY_AND_ASSIGN(ResourceLink
);
156 // Author represents an author of an entity.
161 // Registers the mapping between JSON field names and the members in
163 static void RegisterJSONConverter(
164 base::JSONValueConverter
<Author
>* converter
);
167 const std::string
& name() const { return name_
; }
168 const std::string
& email() const { return email_
; }
170 void set_name(const std::string
& name
) { name_
= name
; }
171 void set_email(const std::string
& email
) { email_
= email
; }
174 friend class ResourceEntry
;
179 DISALLOW_COPY_AND_ASSIGN(Author
);
194 // Registers the mapping between JSON field names and the members in
196 static void RegisterJSONConverter(
197 base::JSONValueConverter
<Category
>* converter
);
200 const std::string
& label() const { return label_
; }
203 CategoryType
type() const { return type_
; }
206 const std::string
& term() const { return term_
; }
208 void set_label(const std::string
& label
) { label_
= label
; }
209 void set_type(CategoryType type
) { type_
= type
; }
210 void set_term(const std::string
& term
) { term_
= term
; }
213 friend class ResourceEntry
;
214 // Converts category scheme into CategoryType enum. For example,
215 // http://schemas.google.com/g/2005#kind => Category::CATEGORY_KIND
216 // Returns false and does not change |result| when |scheme| has an
217 // unrecognizable value.
218 static bool GetCategoryTypeFromScheme(
219 const base::StringPiece
& scheme
, CategoryType
* result
);
225 DISALLOW_COPY_AND_ASSIGN(Category
);
228 // Content details of a resource: mime-type, url, and so on.
233 // Registers the mapping between JSON field names and the members in
235 static void RegisterJSONConverter(
236 base::JSONValueConverter
<Content
>* converter
);
238 // The URL to download the file content.
239 // Note that the url can expire, so we'll fetch the latest resource
240 // entry before starting a download to get the download URL.
241 const GURL
& url() const { return url_
; }
242 const std::string
& mime_type() const { return mime_type_
; }
244 void set_url(const GURL
& url
) { url_
= url
; }
245 void set_mime_type(const std::string
& mime_type
) { mime_type_
= mime_type
; }
248 friend class ResourceEntry
;
251 std::string mime_type_
;
254 // This stores a representation of an application icon as registered with the
255 // installed applications section of the account metadata feed. There can be
256 // multiple icons registered for each application, differing in size, category
261 ICON_UNKNOWN
, // Uninitialized state
262 ICON_DOCUMENT
, // Document icon for various MIME types
263 ICON_APPLICATION
, // Application icon for various MIME types
264 ICON_SHARED_DOCUMENT
, // Icon for documents that are shared from other
271 // Registers the mapping between JSON field names and the members in
273 static void RegisterJSONConverter(
274 base::JSONValueConverter
<AppIcon
>* converter
);
276 // Category of the icon.
277 IconCategory
category() const { return category_
; }
279 // Size in pixels of one side of the icon (icons are always square).
280 int icon_side_length() const { return icon_side_length_
; }
282 // Get a list of links available for this AppIcon.
283 const ScopedVector
<Link
>& links() const { return links_
; }
285 // Get the icon URL from the internal list of links. Returns the first
286 // icon URL found in the list.
287 GURL
GetIconURL() const;
289 void set_category(IconCategory category
) { category_
= category
; }
290 void set_icon_side_length(int icon_side_length
) {
291 icon_side_length_
= icon_side_length
;
293 void set_links(ScopedVector
<Link
> links
) { links_
= links
.Pass(); }
296 // Extracts the icon category from the given string. Returns false and does
297 // not change |result| when |scheme| has an unrecognizable value.
298 static bool GetIconCategory(const base::StringPiece
& category
,
299 IconCategory
* result
);
301 IconCategory category_
;
302 int icon_side_length_
;
303 ScopedVector
<Link
> links_
;
305 DISALLOW_COPY_AND_ASSIGN(AppIcon
);
308 // Base class for feed entries. This class defines fields commonly used by
310 class CommonMetadata
{
313 virtual ~CommonMetadata();
315 // Returns a link of a given |type| for this entry. If not found, it returns
317 const Link
* GetLinkByType(Link::LinkType type
) const;
319 // Entry update time.
320 base::Time
updated_time() const { return updated_time_
; }
323 const std::string
& etag() const { return etag_
; }
325 // List of entry authors.
326 const ScopedVector
<Author
>& authors() const { return authors_
; }
328 // List of entry links.
329 const ScopedVector
<Link
>& links() const { return links_
; }
330 ScopedVector
<Link
>* mutable_links() { return &links_
; }
332 // List of entry categories.
333 const ScopedVector
<Category
>& categories() const { return categories_
; }
335 void set_etag(const std::string
& etag
) { etag_
= etag
; }
336 void set_authors(ScopedVector
<Author
> authors
) {
337 authors_
= authors
.Pass();
339 void set_links(ScopedVector
<Link
> links
) {
340 links_
= links
.Pass();
342 void set_categories(ScopedVector
<Category
> categories
) {
343 categories_
= categories
.Pass();
345 void set_updated_time(const base::Time
& updated_time
) {
346 updated_time_
= updated_time
;
350 // Registers the mapping between JSON field names and the members in
352 template<typename CommonMetadataDescendant
>
353 static void RegisterJSONConverter(
354 base::JSONValueConverter
<CommonMetadataDescendant
>* converter
);
357 ScopedVector
<Author
> authors_
;
358 ScopedVector
<Link
> links_
;
359 ScopedVector
<Category
> categories_
;
360 base::Time updated_time_
;
362 DISALLOW_COPY_AND_ASSIGN(CommonMetadata
);
365 // This class represents a resource entry. A resource is a generic term which
366 // refers to a file and a directory.
367 class ResourceEntry
: public CommonMetadata
{
370 virtual ~ResourceEntry();
372 // Extracts "entry" dictionary from the JSON value, and parse the contents,
373 // using CreateFrom(). Returns NULL on failure. The input JSON data, coming
374 // from the gdata server, looks like:
377 // "encoding": "UTF-8",
378 // "entry": { ... }, // This function will extract this and parse.
382 // The caller should delete the returned object.
383 static scoped_ptr
<ResourceEntry
> ExtractAndParse(const base::Value
& value
);
385 // Creates resource entry from parsed JSON Value. You should call
386 // this instead of instantiating JSONValueConverter by yourself
387 // because this method does some post-process for some fields. See
388 // FillRemainingFields comment and implementation for the details.
389 static scoped_ptr
<ResourceEntry
> CreateFrom(const base::Value
& value
);
391 // Returns name of entry node.
392 static std::string
GetEntryNodeName();
394 // Registers the mapping between JSON field names and the members in
396 static void RegisterJSONConverter(
397 base::JSONValueConverter
<ResourceEntry
>* converter
);
399 // Sets true to |result| if the field exists.
400 // Always returns true even when the field does not exist.
401 static bool HasFieldPresent(const base::Value
* value
, bool* result
);
403 // Parses |value| as int64 and sets it to |result|. If the field does not
404 // exist, sets 0 to |result| as default value.
405 // Returns true if |value| is NULL or it is parsed as int64 successfully.
406 static bool ParseChangestamp(const base::Value
* value
, int64
* result
);
408 // The resource ID is used to identify a resource, which looks like:
409 // file:d41d8cd98f00b204e9800998ecf8
410 const std::string
& resource_id() const { return resource_id_
; }
412 // This is a URL looks like:
413 // https://docs.google.com/feeds/id/file%3Ad41d8cd98f00b204e9800998ecf8.
414 // The URL is currently not used.
415 const std::string
& id() const { return id_
; }
417 DriveEntryKind
kind() const { return kind_
; }
418 const std::string
& title() const { return title_
; }
419 base::Time
published_time() const { return published_time_
; }
420 base::Time
last_viewed_time() const { return last_viewed_time_
; }
421 const std::vector
<std::string
>& labels() const { return labels_
; }
423 // The URL to download a file content.
424 // Search for 'download_url' in gdata_wapi_requests.h for details.
425 const GURL
& download_url() const { return content_
.url(); }
427 const std::string
& content_mime_type() const { return content_
.mime_type(); }
429 // The resource links contain extra links for revisions and access control,
430 // etc. Note that links() contain more basic links like edit URL,
431 // alternative URL, etc.
432 const ScopedVector
<ResourceLink
>& resource_links() const {
433 return resource_links_
;
436 // File name (exists only for kinds FILE and PDF).
437 const std::string
& filename() const { return filename_
; }
439 // Suggested file name (exists only for kinds FILE and PDF).
440 const std::string
& suggested_filename() const { return suggested_filename_
; }
442 // File content MD5 (exists only for kinds FILE and PDF).
443 const std::string
& file_md5() const { return file_md5_
; }
445 // File size (exists only for kinds FILE and PDF).
446 int64
file_size() const { return file_size_
; }
448 // True if the file or directory is deleted (applicable to change list only).
449 bool deleted() const { return deleted_
|| removed_
; }
451 // Changestamp (exists only for change query results).
452 // If not exists, defaults to 0.
453 int64
changestamp() const { return changestamp_
; }
455 // Image width (exists only for images).
456 // If doesn't exist, then equals -1.
457 int64
image_width() const { return image_width_
; }
459 // Image height (exists only for images).
460 // If doesn't exist, then equals -1.
461 int64
image_height() const { return image_height_
; }
463 // Image rotation in clockwise degrees (exists only for images).
464 // If doesn't exist, then equals -1.
465 int64
image_rotation() const { return image_rotation_
; }
467 // Text version of resource entry kind. Returns an empty string for
468 // unknown entry kind.
469 std::string
GetEntryKindText() const;
471 // Returns preferred file extension for hosted documents. If entry is not
472 // a hosted document, this call returns an empty string.
473 std::string
GetHostedDocumentExtension() const;
475 // True if resource entry is remotely hosted.
476 bool is_hosted_document() const {
477 return (ClassifyEntryKind(kind_
) & KIND_OF_HOSTED_DOCUMENT
) > 0;
479 // True if resource entry hosted by Google Documents.
480 bool is_google_document() const {
481 return (ClassifyEntryKind(kind_
) & KIND_OF_GOOGLE_DOCUMENT
) > 0;
483 // True if resource entry is hosted by an external application.
484 bool is_external_document() const {
485 return (ClassifyEntryKind(kind_
) & KIND_OF_EXTERNAL_DOCUMENT
) > 0;
487 // True if resource entry is a folder (collection).
488 bool is_folder() const {
489 return (ClassifyEntryKind(kind_
) & KIND_OF_FOLDER
) > 0;
491 // True if resource entry is regular file.
492 bool is_file() const {
493 return (ClassifyEntryKind(kind_
) & KIND_OF_FILE
) > 0;
495 // True if resource entry can't be mapped to the file system.
496 bool is_special() const {
497 return !is_file() && !is_folder() && !is_hosted_document();
500 // The following constructs are exposed for unit tests.
502 // Classes of EntryKind. Used for ClassifyEntryKind().
503 enum EntryKindClass
{
505 KIND_OF_HOSTED_DOCUMENT
= 1,
506 KIND_OF_GOOGLE_DOCUMENT
= 1 << 1,
507 KIND_OF_EXTERNAL_DOCUMENT
= 1 << 2,
508 KIND_OF_FOLDER
= 1 << 3,
509 KIND_OF_FILE
= 1 << 4,
512 // Returns the kind enum corresponding to the extension in form ".xxx".
513 static DriveEntryKind
GetEntryKindFromExtension(const std::string
& extension
);
515 // Classifies the EntryKind. The returned value is a bitmask of
516 // EntryKindClass. For example, DOCUMENT is classified as
517 // KIND_OF_HOSTED_DOCUMENT and KIND_OF_GOOGLE_DOCUMENT, hence the returned
518 // value is KIND_OF_HOSTED_DOCUMENT | KIND_OF_GOOGLE_DOCUMENT.
519 static int ClassifyEntryKind(DriveEntryKind kind
);
521 // Classifies the EntryKind by the file extension of specific path. The
522 // returned value is a bitmask of EntryKindClass. See also ClassifyEntryKind.
523 static int ClassifyEntryKindByFileExtension(const base::FilePath
& file
);
525 void set_resource_id(const std::string
& resource_id
) {
526 resource_id_
= resource_id
;
528 void set_id(const std::string
& id
) { id_
= id
; }
529 void set_kind(DriveEntryKind kind
) { kind_
= kind
; }
530 void set_title(const std::string
& title
) { title_
= title
; }
531 void set_published_time(const base::Time
& published_time
) {
532 published_time_
= published_time
;
534 void set_last_viewed_time(const base::Time
& last_viewed_time
) {
535 last_viewed_time_
= last_viewed_time
;
537 void set_labels(const std::vector
<std::string
>& labels
) {
540 void set_content(const Content
& content
) {
543 void set_resource_links(ScopedVector
<ResourceLink
> resource_links
) {
544 resource_links_
= resource_links
.Pass();
546 void set_filename(const std::string
& filename
) { filename_
= filename
; }
547 void set_suggested_filename(const std::string
& suggested_filename
) {
548 suggested_filename_
= suggested_filename
;
550 void set_file_md5(const std::string
& file_md5
) { file_md5_
= file_md5
; }
551 void set_file_size(int64 file_size
) { file_size_
= file_size
; }
552 void set_deleted(bool deleted
) { deleted_
= deleted
; }
553 void set_removed(bool removed
) { removed_
= removed
; }
554 void set_changestamp(int64 changestamp
) { changestamp_
= changestamp
; }
555 void set_image_width(int64 image_width
) { image_width_
= image_width
; }
556 void set_image_height(int64 image_height
) { image_height_
= image_height
; }
557 void set_image_rotation(int64 image_rotation
) {
558 image_rotation_
= image_rotation
;
561 // Fills the remaining fields where JSONValueConverter cannot catch.
562 // Currently, sets |kind_| and |labels_| based on the |categories_| in the
564 void FillRemainingFields();
567 friend class base::internal::RepeatedMessageConverter
<ResourceEntry
>;
568 friend class ResourceList
;
569 friend class ResumeUploadRequest
;
571 // Converts categories.term into DriveEntryKind enum.
572 static DriveEntryKind
GetEntryKindFromTerm(const std::string
& term
);
573 // Converts |kind| into its text identifier equivalent.
574 static const char* GetEntryKindDescription(DriveEntryKind kind
);
576 std::string resource_id_
;
578 DriveEntryKind kind_
;
580 base::Time published_time_
;
581 // Last viewed value may be unreliable. See: crbug.com/152628.
582 base::Time last_viewed_time_
;
583 std::vector
<std::string
> labels_
;
585 ScopedVector
<ResourceLink
> resource_links_
;
586 // Optional fields for files only.
587 std::string filename_
;
588 std::string suggested_filename_
;
589 std::string file_md5_
;
596 int64 image_rotation_
;
598 DISALLOW_COPY_AND_ASSIGN(ResourceEntry
);
601 // This class represents a list of resource entries with some extra metadata
602 // such as the root upload URL. The feed is paginated and the rest of the
603 // feed can be fetched by retrieving the remaining parts of the feed from
604 // URLs provided by GetNextFeedURL() method.
605 class ResourceList
: public CommonMetadata
{
608 virtual ~ResourceList();
610 // Extracts "feed" dictionary from the JSON value, and parse the contents,
611 // using CreateFrom(). Returns NULL on failure. The input JSON data, coming
612 // from the gdata server, looks like:
615 // "encoding": "UTF-8",
616 // "feed": { ... }, // This function will extract this and parse.
619 static scoped_ptr
<ResourceList
> ExtractAndParse(const base::Value
& value
);
621 // Creates feed from parsed JSON Value. You should call this
622 // instead of instantiating JSONValueConverter by yourself because
623 // this method does some post-process for some fields. See
624 // FillRemainingFields comment and implementation in ResourceEntry
625 // class for the details.
626 static scoped_ptr
<ResourceList
> CreateFrom(const base::Value
& value
);
628 // Registers the mapping between JSON field names and the members in
630 static void RegisterJSONConverter(
631 base::JSONValueConverter
<ResourceList
>* converter
);
633 // Returns true and passes|url| of the next feed if the current entry list
634 // does not completed this feed.
635 bool GetNextFeedURL(GURL
* url
) const;
637 // List of resource entries.
638 const ScopedVector
<ResourceEntry
>& entries() const { return entries_
; }
639 ScopedVector
<ResourceEntry
>* mutable_entries() { return &entries_
; }
641 // Releases entries_ into |entries|. This is a transfer of ownership, so the
642 // caller is responsible for deleting the elements of |entries|.
643 void ReleaseEntries(std::vector
<ResourceEntry
*>* entries
);
645 // Start index of the resource entry list.
646 int start_index() const { return start_index_
; }
648 // Number of items per feed of the resource entry list.
649 int items_per_page() const { return items_per_page_
; }
651 // The largest changestamp. Next time the resource list should be fetched
652 // from this changestamp.
653 int64
largest_changestamp() const { return largest_changestamp_
; }
655 // Resource entry list title.
656 const std::string
& title() { return title_
; }
658 void set_entries(ScopedVector
<ResourceEntry
> entries
) {
659 entries_
= entries
.Pass();
661 void set_start_index(int start_index
) {
662 start_index_
= start_index
;
664 void set_items_per_page(int items_per_page
) {
665 items_per_page_
= items_per_page
;
667 void set_title(const std::string
& title
) {
670 void set_largest_changestamp(int64 largest_changestamp
) {
671 largest_changestamp_
= largest_changestamp
;
675 // Parses and initializes data members from content of |value|.
676 // Return false if parsing fails.
677 bool Parse(const base::Value
& value
);
679 ScopedVector
<ResourceEntry
> entries_
;
683 int64 largest_changestamp_
;
685 DISALLOW_COPY_AND_ASSIGN(ResourceList
);
688 // Metadata representing installed Google Drive application.
691 typedef std::vector
<std::pair
<int, GURL
> > IconList
;
694 virtual ~InstalledApp();
697 const std::string
& app_name() const { return app_name_
; }
700 const std::string
& app_id() const { return app_id_
; }
702 // Object (file) type name that is generated by this WebApp.
703 const std::string
& object_type() const { return object_type_
; }
705 // True if WebApp supports creation of new file instances.
706 bool supports_create() const { return supports_create_
; }
708 // List of primary mime types supported by this WebApp. Primary status should
709 // trigger this WebApp becoming the default handler of file instances that
710 // have these mime types.
711 const ScopedVector
<std::string
>& primary_mimetypes() const {
712 return primary_mimetypes_
;
715 // List of secondary mime types supported by this WebApp. Secondary status
716 // should make this WebApp show up in "Open with..." pop-up menu of the
717 // default action menu for file with matching mime types.
718 const ScopedVector
<std::string
>& secondary_mimetypes() const {
719 return secondary_mimetypes_
;
722 // List of primary file extensions supported by this WebApp. Primary status
723 // should trigger this WebApp becoming the default handler of file instances
724 // that match these extensions.
725 const ScopedVector
<std::string
>& primary_extensions() const {
726 return primary_extensions_
;
729 // List of secondary file extensions supported by this WebApp. Secondary
730 // status should make this WebApp show up in "Open with..." pop-up menu of the
731 // default action menu for file with matching extensions.
732 const ScopedVector
<std::string
>& secondary_extensions() const {
733 return secondary_extensions_
;
736 // List of entry links.
737 const ScopedVector
<Link
>& links() const { return links_
; }
739 // Returns a list of icons associated with this installed application.
740 const ScopedVector
<AppIcon
>& app_icons() const {
744 // Convenience function for getting the icon URLs for a particular |category|
745 // of icon. Icons are returned in a sorted list, from smallest to largest.
746 IconList
GetIconsForCategory(AppIcon::IconCategory category
) const;
748 // Retrieves product URL from the link collection.
749 GURL
GetProductUrl() const;
751 // Registers the mapping between JSON field names and the members in
753 static void RegisterJSONConverter(
754 base::JSONValueConverter
<InstalledApp
>* converter
);
756 void set_app_id(const std::string
& app_id
) { app_id_
= app_id
; }
757 void set_app_name(const std::string
& app_name
) { app_name_
= app_name
; }
758 void set_object_type(const std::string
& object_type
) {
759 object_type_
= object_type
;
761 void set_supports_create(bool supports_create
) {
762 supports_create_
= supports_create
;
764 void set_primary_mimetypes(
765 ScopedVector
<std::string
> primary_mimetypes
) {
766 primary_mimetypes_
= primary_mimetypes
.Pass();
768 void set_secondary_mimetypes(
769 ScopedVector
<std::string
> secondary_mimetypes
) {
770 secondary_mimetypes_
= secondary_mimetypes
.Pass();
772 void set_primary_extensions(
773 ScopedVector
<std::string
> primary_extensions
) {
774 primary_extensions_
= primary_extensions
.Pass();
776 void set_secondary_extensions(
777 ScopedVector
<std::string
> secondary_extensions
) {
778 secondary_extensions_
= secondary_extensions
.Pass();
780 void set_links(ScopedVector
<Link
> links
) {
781 links_
= links
.Pass();
783 void set_app_icons(ScopedVector
<AppIcon
> app_icons
) {
784 app_icons_
= app_icons
.Pass();
788 // Extracts "$t" value from the dictionary |value| and returns it in |result|.
789 // If the string value can't be found, it returns false.
790 static bool GetValueString(const base::Value
* value
,
791 std::string
* result
);
794 std::string app_name_
;
795 std::string object_type_
;
796 bool supports_create_
;
797 ScopedVector
<std::string
> primary_mimetypes_
;
798 ScopedVector
<std::string
> secondary_mimetypes_
;
799 ScopedVector
<std::string
> primary_extensions_
;
800 ScopedVector
<std::string
> secondary_extensions_
;
801 ScopedVector
<Link
> links_
;
802 ScopedVector
<AppIcon
> app_icons_
;
805 // Account metadata feed represents the metadata object attached to the user's
807 class AccountMetadata
{
810 virtual ~AccountMetadata();
812 // Creates feed from parsed JSON Value. You should call this
813 // instead of instantiating JSONValueConverter by yourself because
814 // this method does some post-process for some fields. See
815 // FillRemainingFields comment and implementation in ResourceEntry
816 // class for the details.
817 static scoped_ptr
<AccountMetadata
> CreateFrom(const base::Value
& value
);
819 int64
quota_bytes_total() const {
820 return quota_bytes_total_
;
823 int64
quota_bytes_used() const {
824 return quota_bytes_used_
;
827 int64
largest_changestamp() const {
828 return largest_changestamp_
;
831 const ScopedVector
<InstalledApp
>& installed_apps() const {
832 return installed_apps_
;
835 void set_quota_bytes_total(int64 quota_bytes_total
) {
836 quota_bytes_total_
= quota_bytes_total
;
838 void set_quota_bytes_used(int64 quota_bytes_used
) {
839 quota_bytes_used_
= quota_bytes_used
;
841 void set_largest_changestamp(int64 largest_changestamp
) {
842 largest_changestamp_
= largest_changestamp
;
844 void set_installed_apps(ScopedVector
<InstalledApp
> installed_apps
) {
845 installed_apps_
= installed_apps
.Pass();
848 // Registers the mapping between JSON field names and the members in
850 static void RegisterJSONConverter(
851 base::JSONValueConverter
<AccountMetadata
>* converter
);
854 // Parses and initializes data members from content of |value|.
855 // Return false if parsing fails.
856 bool Parse(const base::Value
& value
);
858 int64 quota_bytes_total_
;
859 int64 quota_bytes_used_
;
860 int64 largest_changestamp_
;
861 ScopedVector
<InstalledApp
> installed_apps_
;
863 DISALLOW_COPY_AND_ASSIGN(AccountMetadata
);
867 } // namespace google_apis
869 #endif // GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_