offline_page_types.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2016 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_TYPES_H_
  5. #define COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_TYPES_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <set>
  9. #include <vector>
  10. #include "base/callback.h"
  11. #include "components/offline_pages/core/offline_page_item.h"
  12. #include "components/offline_pages/core/offline_page_visuals.h"
  13. class GURL;
  14. // This file contains common callbacks used by OfflinePageModel and is a
  15. // temporary step to refactor and interface of the model out of the
  16. // implementation.
  17. namespace offline_pages {
  18. // Result of saving a page offline. Must be kept with sync with
  19. // OfflinePagesSavePageResult in metrics' enum.xml
  20. // A Java counterpart will be generated for this enum.
  21. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.offlinepages
  22. enum class SavePageResult {
  23. SUCCESS = 0,
  24. CANCELLED = 1,
  25. DEVICE_FULL = 2,
  26. CONTENT_UNAVAILABLE = 3,
  27. ARCHIVE_CREATION_FAILED = 4,
  28. STORE_FAILURE = 5,
  29. ALREADY_EXISTS = 6,
  30. // Certain pages, i.e. file URL or NTP, will not be saved because these
  31. // are already locally accessible.
  32. SKIPPED = 7,
  33. DEPRECATED_SECURITY_CERTIFICATE_ERROR = 8,
  34. DEPRECATED_ERROR_PAGE = 9,
  35. DEPRECATED_INTERSTITIAL_PAGE = 10,
  36. // Failed to compute digest for the archive file.
  37. DIGEST_CALCULATION_FAILED = 11,
  38. // Unable to move the file into a public directory.
  39. FILE_MOVE_FAILED = 12,
  40. // Unable to add the file to the system download manager.
  41. ADD_TO_DOWNLOAD_MANAGER_FAILED = 13,
  42. // Unable to get write permission on public directory.
  43. STORAGE_PERMISSION_DENIED = 14,
  44. // The URL from the tab or saved page doesn't match the requested page URL.
  45. INCORRECT_URL = 15,
  46. kMaxValue = INCORRECT_URL,
  47. };
  48. // Result of adding an offline page.
  49. enum class AddPageResult {
  50. SUCCESS,
  51. STORE_FAILURE,
  52. ALREADY_EXISTS,
  53. kMaxValue = ALREADY_EXISTS,
  54. };
  55. // Result of deleting an offline page. Must be kept with sync with
  56. // OfflinePagesDeletePageResult in metrics' enum.xml.
  57. // A Java counterpart will be generated for this enum.
  58. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.offlinepages
  59. enum class DeletePageResult {
  60. SUCCESS,
  61. CANCELLED,
  62. STORE_FAILURE,
  63. DEVICE_FAILURE,
  64. // Deprecated. Deleting pages which are not in metadata store would be
  65. // returing |SUCCESS|. Should not be used anymore.
  66. DEPRECATED_NOT_FOUND,
  67. kMaxValue = DEPRECATED_NOT_FOUND,
  68. };
  69. // The result when trying to share offline page to other apps.
  70. enum class ShareResult {
  71. // Successfully shared.
  72. kSuccess,
  73. // Failed due to no file access permission.
  74. kFileAccessPermissionDenied,
  75. };
  76. struct VisualsAvailability {
  77. bool has_thumbnail;
  78. bool has_favicon;
  79. bool operator==(const VisualsAvailability& rhs) const {
  80. return has_thumbnail == rhs.has_thumbnail && has_favicon == rhs.has_favicon;
  81. }
  82. };
  83. typedef std::vector<int64_t> MultipleOfflineIdResult;
  84. typedef std::vector<OfflinePageItem> MultipleOfflinePageItemResult;
  85. typedef base::OnceCallback<void(SavePageResult, int64_t)> SavePageCallback;
  86. typedef base::OnceCallback<void(AddPageResult, int64_t)> AddPageCallback;
  87. typedef base::OnceCallback<void(DeletePageResult)> DeletePageCallback;
  88. typedef base::OnceCallback<void(const MultipleOfflineIdResult&)>
  89. MultipleOfflineIdCallback;
  90. typedef base::OnceCallback<void(const OfflinePageItem*)>
  91. SingleOfflinePageItemCallback;
  92. typedef base::OnceCallback<void(const MultipleOfflinePageItemResult&)>
  93. MultipleOfflinePageItemCallback;
  94. typedef base::RepeatingCallback<bool(const GURL&)> UrlPredicate;
  95. typedef base::OnceCallback<void(int64_t)> SizeInBytesCallback;
  96. typedef base::OnceCallback<void(std::unique_ptr<OfflinePageVisuals>)>
  97. GetVisualsCallback;
  98. typedef base::OnceCallback<void(bool)> CleanupVisualsCallback;
  99. // Callbacks used for publishing an offline page.
  100. using PublishPageCallback =
  101. base::OnceCallback<void(const base::FilePath&, SavePageResult)>;
  102. } // namespace offline_pages
  103. #endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_TYPES_H_