offline_page_item.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2015 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. #ifndef COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_ITEM_H_
  5. #define COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_ITEM_H_
  6. #include <stdint.h>
  7. #include <iosfwd>
  8. #include <string>
  9. #include "base/files/file_path.h"
  10. #include "base/time/time.h"
  11. #include "components/offline_pages/core/client_id.h"
  12. #include "url/gurl.h"
  13. namespace offline_pages {
  14. // Metadata of the offline page.
  15. struct OfflinePageItem {
  16. public:
  17. // Note that this should match with Flags enum in offline_pages.proto.
  18. enum Flags {
  19. NO_FLAG = 0,
  20. MARKED_FOR_DELETION = 0x1,
  21. };
  22. OfflinePageItem();
  23. OfflinePageItem(const GURL& url,
  24. int64_t offline_id,
  25. const ClientId& client_id,
  26. const base::FilePath& file_path,
  27. int64_t file_size);
  28. OfflinePageItem(const GURL& url,
  29. int64_t offline_id,
  30. const ClientId& client_id,
  31. const base::FilePath& file_path,
  32. int64_t file_size,
  33. const base::Time& creation_time);
  34. OfflinePageItem(const OfflinePageItem& other);
  35. OfflinePageItem(OfflinePageItem&& other);
  36. ~OfflinePageItem();
  37. OfflinePageItem& operator=(const OfflinePageItem&);
  38. OfflinePageItem& operator=(OfflinePageItem&&);
  39. bool operator==(const OfflinePageItem& other) const;
  40. bool operator<(const OfflinePageItem& other) const;
  41. const GURL& GetOriginalUrl() const {
  42. return original_url_if_different.is_empty() ? url
  43. : original_url_if_different;
  44. }
  45. // The URL of the page. This is the last committed URL. In the case that
  46. // redirects occur, access |original_url| for the original URL.
  47. GURL url;
  48. // The primary key/ID for this page in offline pages internal database.
  49. int64_t offline_id = 0;
  50. // The Client ID (external) related to the offline page. This is opaque
  51. // to our system, but useful for users of offline pages who want to map
  52. // their ids to our saved pages.
  53. ClientId client_id;
  54. // The file path to the archive with a local copy of the page.
  55. base::FilePath file_path;
  56. // The size of the offline copy.
  57. int64_t file_size = 0;
  58. // The time when the offline archive was created.
  59. base::Time creation_time;
  60. // The time when the offline archive was last accessed.
  61. base::Time last_access_time;
  62. // Number of times that the offline archive has been accessed.
  63. int access_count = 0;
  64. // The title of the page at the time it was saved.
  65. std::u16string title;
  66. // Flags about the state and behavior of the offline page.
  67. Flags flags = NO_FLAG;
  68. // The original URL of the page if not empty. Otherwise, this is set to empty
  69. // and |url| should be accessed instead.
  70. GURL original_url_if_different;
  71. // The app, if any, that the item was saved on behalf of.
  72. // Empty string implies Chrome.
  73. std::string request_origin;
  74. // System download id.
  75. int64_t system_download_id = 0;
  76. // The most recent time when the file was discovered missing.
  77. // NULL time implies the file is not missing.
  78. base::Time file_missing_time;
  79. // Digest of the page calculated when page is saved, in order to tell if the
  80. // page can be trusted. This field will always be an empty string for
  81. // temporary and shared pages.
  82. std::string digest;
  83. // Snippet from the article.
  84. std::string snippet;
  85. // Text indicating the article's publisher.
  86. std::string attribution;
  87. };
  88. // This operator is for testing only, see offline_page_test_utils.cc.
  89. // This is provided here to avoid ODR problems.
  90. std::ostream& operator<<(std::ostream& out, const OfflinePageItem& value);
  91. } // namespace offline_pages
  92. #endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_ITEM_H_