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