| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ |
| 6 #define GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ | 6 #define GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "google_apis/drive/drive_entry_kinds.h" | |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 19 | 18 |
| 20 namespace base { | 19 namespace base { |
| 21 class FilePath; | 20 class FilePath; |
| 22 class DictionaryValue; | 21 class DictionaryValue; |
| 23 class Value; | 22 class Value; |
| 24 | 23 |
| 25 template <class StructType> | 24 template <class StructType> |
| 26 class JSONValueConverter; | 25 class JSONValueConverter; |
| 27 | 26 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 ScopedVector<Category> categories_; | 304 ScopedVector<Category> categories_; |
| 306 base::Time updated_time_; | 305 base::Time updated_time_; |
| 307 | 306 |
| 308 DISALLOW_COPY_AND_ASSIGN(CommonMetadata); | 307 DISALLOW_COPY_AND_ASSIGN(CommonMetadata); |
| 309 }; | 308 }; |
| 310 | 309 |
| 311 // This class represents a resource entry. A resource is a generic term which | 310 // This class represents a resource entry. A resource is a generic term which |
| 312 // refers to a file and a directory. | 311 // refers to a file and a directory. |
| 313 class ResourceEntry : public CommonMetadata { | 312 class ResourceEntry : public CommonMetadata { |
| 314 public: | 313 public: |
| 314 enum ResourceEntryKind { |
| 315 ENTRY_KIND_UNKNOWN, |
| 316 ENTRY_KIND_FOLDER, |
| 317 ENTRY_KIND_FILE |
| 318 }; |
| 315 ResourceEntry(); | 319 ResourceEntry(); |
| 316 virtual ~ResourceEntry(); | 320 virtual ~ResourceEntry(); |
| 317 | 321 |
| 318 // Extracts "entry" dictionary from the JSON value, and parse the contents, | 322 // Extracts "entry" dictionary from the JSON value, and parse the contents, |
| 319 // using CreateFrom(). Returns NULL on failure. The input JSON data, coming | 323 // using CreateFrom(). Returns NULL on failure. The input JSON data, coming |
| 320 // from the gdata server, looks like: | 324 // from the gdata server, looks like: |
| 321 // | 325 // |
| 322 // { | 326 // { |
| 323 // "encoding": "UTF-8", | 327 // "encoding": "UTF-8", |
| 324 // "entry": { ... }, // This function will extract this and parse. | 328 // "entry": { ... }, // This function will extract this and parse. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 353 | 357 |
| 354 // The resource ID is used to identify a resource, which looks like: | 358 // The resource ID is used to identify a resource, which looks like: |
| 355 // file:d41d8cd98f00b204e9800998ecf8 | 359 // file:d41d8cd98f00b204e9800998ecf8 |
| 356 const std::string& resource_id() const { return resource_id_; } | 360 const std::string& resource_id() const { return resource_id_; } |
| 357 | 361 |
| 358 // This is a URL looks like: | 362 // This is a URL looks like: |
| 359 // https://docs.google.com/feeds/id/file%3Ad41d8cd98f00b204e9800998ecf8. | 363 // https://docs.google.com/feeds/id/file%3Ad41d8cd98f00b204e9800998ecf8. |
| 360 // The URL is currently not used. | 364 // The URL is currently not used. |
| 361 const std::string& id() const { return id_; } | 365 const std::string& id() const { return id_; } |
| 362 | 366 |
| 363 DriveEntryKind kind() const { return kind_; } | 367 ResourceEntryKind kind() const { return kind_; } |
| 364 const std::string& title() const { return title_; } | 368 const std::string& title() const { return title_; } |
| 365 base::Time published_time() const { return published_time_; } | 369 base::Time published_time() const { return published_time_; } |
| 366 base::Time last_viewed_time() const { return last_viewed_time_; } | 370 base::Time last_viewed_time() const { return last_viewed_time_; } |
| 367 const std::vector<std::string>& labels() const { return labels_; } | 371 const std::vector<std::string>& labels() const { return labels_; } |
| 368 | 372 |
| 369 // The URL to download a file content. | 373 // The URL to download a file content. |
| 370 // Search for 'download_url' in gdata_wapi_requests.h for details. | 374 // Search for 'download_url' in gdata_wapi_requests.h for details. |
| 371 const GURL& download_url() const { return content_.url(); } | 375 const GURL& download_url() const { return content_.url(); } |
| 372 | 376 |
| 373 const std::string& content_mime_type() const { return content_.mime_type(); } | 377 const std::string& content_mime_type() const { return content_.mime_type(); } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 int64 image_rotation() const { return image_rotation_; } | 415 int64 image_rotation() const { return image_rotation_; } |
| 412 | 416 |
| 413 // The time of this modification. | 417 // The time of this modification. |
| 414 // Note: This property is filled only when converted from ChangeResource. | 418 // Note: This property is filled only when converted from ChangeResource. |
| 415 const base::Time& modification_date() const { return modification_date_; } | 419 const base::Time& modification_date() const { return modification_date_; } |
| 416 | 420 |
| 417 // Text version of resource entry kind. Returns an empty string for | 421 // Text version of resource entry kind. Returns an empty string for |
| 418 // unknown entry kind. | 422 // unknown entry kind. |
| 419 std::string GetEntryKindText() const; | 423 std::string GetEntryKindText() const; |
| 420 | 424 |
| 421 // Returns preferred file extension for hosted documents. If entry is not | |
| 422 // a hosted document, this call returns an empty string. | |
| 423 static std::string GetHostedDocumentExtension(DriveEntryKind kind); | |
| 424 | |
| 425 // True if resource entry is remotely hosted. | |
| 426 bool is_hosted_document() const { | |
| 427 return (ClassifyEntryKind(kind_) & KIND_OF_HOSTED_DOCUMENT) > 0; | |
| 428 } | |
| 429 // True if resource entry hosted by Google Documents. | |
| 430 bool is_google_document() const { | |
| 431 return (ClassifyEntryKind(kind_) & KIND_OF_GOOGLE_DOCUMENT) > 0; | |
| 432 } | |
| 433 // True if resource entry is hosted by an external application. | |
| 434 bool is_external_document() const { | |
| 435 return (ClassifyEntryKind(kind_) & KIND_OF_EXTERNAL_DOCUMENT) > 0; | |
| 436 } | |
| 437 // True if resource entry is a folder (collection). | 425 // True if resource entry is a folder (collection). |
| 438 bool is_folder() const { | 426 bool is_folder() const { |
| 439 return (ClassifyEntryKind(kind_) & KIND_OF_FOLDER) > 0; | 427 return kind_ == ENTRY_KIND_FOLDER; |
| 440 } | 428 } |
| 441 // True if resource entry is regular file. | 429 // True if resource entry is regular file. |
| 442 bool is_file() const { | 430 bool is_file() const { |
| 443 return (ClassifyEntryKind(kind_) & KIND_OF_FILE) > 0; | 431 return kind_ == ENTRY_KIND_FILE; |
| 444 } | 432 } |
| 445 // True if resource entry can't be mapped to the file system. | |
| 446 bool is_special() const { | |
| 447 return !is_file() && !is_folder() && !is_hosted_document(); | |
| 448 } | |
| 449 | |
| 450 // The following constructs are exposed for unit tests. | |
| 451 | |
| 452 // Classes of EntryKind. Used for ClassifyEntryKind(). | |
| 453 enum EntryKindClass { | |
| 454 KIND_OF_NONE = 0, | |
| 455 KIND_OF_HOSTED_DOCUMENT = 1, | |
| 456 KIND_OF_GOOGLE_DOCUMENT = 1 << 1, | |
| 457 KIND_OF_EXTERNAL_DOCUMENT = 1 << 2, | |
| 458 KIND_OF_FOLDER = 1 << 3, | |
| 459 KIND_OF_FILE = 1 << 4, | |
| 460 }; | |
| 461 | |
| 462 // Returns the kind enum corresponding to the extension in form ".xxx". | |
| 463 static DriveEntryKind GetEntryKindFromExtension(const std::string& extension); | |
| 464 | |
| 465 // Classifies the EntryKind. The returned value is a bitmask of | |
| 466 // EntryKindClass. For example, DOCUMENT is classified as | |
| 467 // KIND_OF_HOSTED_DOCUMENT and KIND_OF_GOOGLE_DOCUMENT, hence the returned | |
| 468 // value is KIND_OF_HOSTED_DOCUMENT | KIND_OF_GOOGLE_DOCUMENT. | |
| 469 static int ClassifyEntryKind(DriveEntryKind kind); | |
| 470 | |
| 471 // Classifies the EntryKind by the file extension of specific path. The | |
| 472 // returned value is a bitmask of EntryKindClass. See also ClassifyEntryKind. | |
| 473 static int ClassifyEntryKindByFileExtension(const base::FilePath& file); | |
| 474 | 433 |
| 475 void set_resource_id(const std::string& resource_id) { | 434 void set_resource_id(const std::string& resource_id) { |
| 476 resource_id_ = resource_id; | 435 resource_id_ = resource_id; |
| 477 } | 436 } |
| 478 void set_id(const std::string& id) { id_ = id; } | 437 void set_id(const std::string& id) { id_ = id; } |
| 479 void set_kind(DriveEntryKind kind) { kind_ = kind; } | 438 void set_kind(ResourceEntryKind kind) { kind_ = kind; } |
| 480 void set_title(const std::string& title) { title_ = title; } | 439 void set_title(const std::string& title) { title_ = title; } |
| 481 void set_published_time(const base::Time& published_time) { | 440 void set_published_time(const base::Time& published_time) { |
| 482 published_time_ = published_time; | 441 published_time_ = published_time; |
| 483 } | 442 } |
| 484 void set_last_viewed_time(const base::Time& last_viewed_time) { | 443 void set_last_viewed_time(const base::Time& last_viewed_time) { |
| 485 last_viewed_time_ = last_viewed_time; | 444 last_viewed_time_ = last_viewed_time; |
| 486 } | 445 } |
| 487 void set_labels(const std::vector<std::string>& labels) { | 446 void set_labels(const std::vector<std::string>& labels) { |
| 488 labels_ = labels; | 447 labels_ = labels; |
| 489 } | 448 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 514 // Fills the remaining fields where JSONValueConverter cannot catch. | 473 // Fills the remaining fields where JSONValueConverter cannot catch. |
| 515 // Currently, sets |kind_| and |labels_| based on the |categories_| in the | 474 // Currently, sets |kind_| and |labels_| based on the |categories_| in the |
| 516 // class. | 475 // class. |
| 517 void FillRemainingFields(); | 476 void FillRemainingFields(); |
| 518 | 477 |
| 519 private: | 478 private: |
| 520 friend class base::internal::RepeatedMessageConverter<ResourceEntry>; | 479 friend class base::internal::RepeatedMessageConverter<ResourceEntry>; |
| 521 friend class ResourceList; | 480 friend class ResourceList; |
| 522 friend class ResumeUploadRequest; | 481 friend class ResumeUploadRequest; |
| 523 | 482 |
| 524 // Converts categories.term into DriveEntryKind enum. | 483 // Converts categories.term into ResourceEntryKind enum. |
| 525 static DriveEntryKind GetEntryKindFromTerm(const std::string& term); | 484 static ResourceEntryKind GetEntryKindFromTerm(const std::string& term); |
| 526 // Converts |kind| into its text identifier equivalent. | |
| 527 static const char* GetEntryKindDescription(DriveEntryKind kind); | |
| 528 | 485 |
| 529 std::string resource_id_; | 486 std::string resource_id_; |
| 530 std::string id_; | 487 std::string id_; |
| 531 DriveEntryKind kind_; | 488 ResourceEntryKind kind_; |
| 532 std::string title_; | 489 std::string title_; |
| 533 base::Time published_time_; | 490 base::Time published_time_; |
| 534 // Last viewed value may be unreliable. See: crbug.com/152628. | 491 // Last viewed value may be unreliable. See: crbug.com/152628. |
| 535 base::Time last_viewed_time_; | 492 base::Time last_viewed_time_; |
| 536 std::vector<std::string> labels_; | 493 std::vector<std::string> labels_; |
| 537 Content content_; | 494 Content content_; |
| 538 ScopedVector<ResourceLink> resource_links_; | 495 ScopedVector<ResourceLink> resource_links_; |
| 539 // Optional fields for files only. | 496 // Optional fields for files only. |
| 540 std::string filename_; | 497 std::string filename_; |
| 541 std::string suggested_filename_; | 498 std::string suggested_filename_; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 int items_per_page_; | 593 int items_per_page_; |
| 637 std::string title_; | 594 std::string title_; |
| 638 int64 largest_changestamp_; | 595 int64 largest_changestamp_; |
| 639 | 596 |
| 640 DISALLOW_COPY_AND_ASSIGN(ResourceList); | 597 DISALLOW_COPY_AND_ASSIGN(ResourceList); |
| 641 }; | 598 }; |
| 642 | 599 |
| 643 } // namespace google_apis | 600 } // namespace google_apis |
| 644 | 601 |
| 645 #endif // GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ | 602 #endif // GOOGLE_APIS_DRIVE_GDATA_WAPI_PARSER_H_ |
| OLD | NEW |