offline_page_client_policy.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_CLIENT_POLICY_H_
  5. #define COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_CLIENT_POLICY_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/time/time.h"
  10. namespace offline_pages {
  11. static const size_t kUnlimitedPages = 0;
  12. // Enum whose values specify the lifetime characteristics of pages pertaining to
  13. // a given client.
  14. enum class LifetimeType {
  15. // A temporary offline page, which is automatically downloaded and cleaned
  16. // up when storage limits are reached or when caches are cleared. They are
  17. // normally stored in Chrome internal directories, not directly accessible to
  18. // the user.
  19. TEMPORARY,
  20. // A persistent offline page, manually downloaded by the user. It is stored in
  21. // the public Downloads directory and only the user can delete it.
  22. PERSISTENT,
  23. };
  24. // The struct describing policies for offline pages' clients (Bookmark, Last-N
  25. // etc.) describing how their pages are handled by the offline page model.
  26. struct OfflinePageClientPolicy {
  27. OfflinePageClientPolicy(std::string namespace_val,
  28. LifetimeType lifetime_type_val);
  29. static OfflinePageClientPolicy CreateTemporary(
  30. const std::string& name_space,
  31. const base::TimeDelta& expiration_period);
  32. static OfflinePageClientPolicy CreatePersistent(
  33. const std::string& name_space);
  34. OfflinePageClientPolicy(const OfflinePageClientPolicy& other);
  35. ~OfflinePageClientPolicy();
  36. // Namespace that uniquely identifies this client.
  37. std::string name_space;
  38. // Lifetime type for the pages saved by this client.
  39. LifetimeType lifetime_type = LifetimeType::TEMPORARY;
  40. // The time after which pages expire. A zero value (default) means pages from
  41. // this client never expire.
  42. base::TimeDelta expiration_period;
  43. // The maximum number of pages allowed to be saved for this client.
  44. // |kUnlimitedPages| (default) means no limit is set.
  45. size_t page_limit = kUnlimitedPages;
  46. // The maximum number of pages for the same URL that can be stored for this
  47. // client. |kUnlimitedPages| (default) means no limit is set.
  48. size_t pages_allowed_per_url = kUnlimitedPages;
  49. // Whether pages are shown in the Downloads UI.
  50. bool is_supported_by_download = false;
  51. // Whether pages can only be viewed in a specific tab. Pages controlled by
  52. // this policy must have their ClientId::id field set to their assigned tab's
  53. // id.
  54. bool is_restricted_to_tab_from_client_id = false;
  55. // Whether this client should be "disabled" if any of these user settings are
  56. // set to:
  57. // * 3rd party cookies are blocked (prefs::kBlockThirdPartyCookies).
  58. // * Network predictions (prefs::kNetworkPredictionOptions) are fully
  59. // disabled.
  60. bool requires_specific_user_settings = false;
  61. // Whether the pages originate from suggestion engines like the Feed.
  62. bool is_suggested = false;
  63. // Whether a background page download is allowed to be converted to a regular
  64. // download if the URL turns out to point to a file (i.e. a PDF).
  65. bool allows_conversion_to_background_file_download = false;
  66. // Whether background fetches are deferred while the active tab matches the
  67. // SavePageRequestURL.
  68. bool defer_background_fetch_while_page_is_active = false;
  69. };
  70. // Get the client policy for |name_space|.
  71. const OfflinePageClientPolicy& GetPolicy(const std::string& name_space);
  72. // Returns a list of all known namespaces.
  73. const std::vector<std::string>& GetAllPolicyNamespaces();
  74. // Returns a list of all temporary namespaces.
  75. const std::vector<std::string>& GetTemporaryPolicyNamespaces();
  76. // Returns a list of all persistent namespaces.
  77. const std::vector<std::string>& GetPersistentPolicyNamespaces();
  78. } // namespace offline_pages
  79. #endif // COMPONENTS_OFFLINE_PAGES_CORE_OFFLINE_PAGE_CLIENT_POLICY_H_