send_tab_to_self_entry.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2018 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_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_
  5. #define COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_
  6. #include <string>
  7. #include "base/time/time.h"
  8. #include "url/gurl.h"
  9. namespace sync_pb {
  10. class SendTabToSelfSpecifics;
  11. }
  12. namespace send_tab_to_self {
  13. constexpr base::TimeDelta kExpiryTime = base::Days(10);
  14. class SendTabToSelfLocal;
  15. // A tab that is being shared. The URL is a unique identifier for an entry, as
  16. // such it should not be empty and is the only thing considered when comparing
  17. // entries.
  18. // The java version of this class: SendTabToSelfEntry.java
  19. class SendTabToSelfEntry {
  20. public:
  21. // Creates a SendTabToSelf entry. |url| and |title| are the main fields of the
  22. // entry.
  23. // |now| is used to fill the |creation_time_us_| and all the update timestamp
  24. // fields.
  25. SendTabToSelfEntry(const std::string& guid,
  26. const GURL& url,
  27. const std::string& title,
  28. base::Time shared_time,
  29. const std::string& device_name,
  30. const std::string& target_device_sync_cache_guid);
  31. SendTabToSelfEntry(const SendTabToSelfEntry&);
  32. SendTabToSelfEntry& operator=(const SendTabToSelfEntry&) = delete;
  33. ~SendTabToSelfEntry();
  34. // The unique random id for the entry.
  35. const std::string& GetGUID() const;
  36. // The URL of the page the user would like to send to themselves.
  37. const GURL& GetURL() const;
  38. // The title of the entry. Might be empty.
  39. const std::string& GetTitle() const;
  40. // The time that the tab was shared.
  41. base::Time GetSharedTime() const;
  42. // The name of the device that originated the sent tab.
  43. const std::string& GetDeviceName() const;
  44. // The cache guid of of the device that this tab is shared with.
  45. const std::string& GetTargetDeviceSyncCacheGuid() const;
  46. // The opened state of the entry.
  47. bool IsOpened() const;
  48. // Sets the opened state of the entry to true.
  49. void MarkOpened();
  50. // The state of this entry's notification: if it has been |dismissed|.
  51. void SetNotificationDismissed(bool notification_dismissed);
  52. bool GetNotificationDismissed() const;
  53. // Returns a protobuf encoding the content of this SendTabToSelfEntry for
  54. // local storage.
  55. SendTabToSelfLocal AsLocalProto() const;
  56. // Creates a SendTabToSelfEntry from the protobuf format.
  57. // If creation time is not set, it will be set to |now|.
  58. static std::unique_ptr<SendTabToSelfEntry> FromProto(
  59. const sync_pb::SendTabToSelfSpecifics& pb_entry,
  60. base::Time now);
  61. // Creates a SendTabToSelfEntry from the protobuf format.
  62. // If creation time is not set, it will be set to |now|.
  63. static std::unique_ptr<SendTabToSelfEntry> FromLocalProto(
  64. const SendTabToSelfLocal& pb_entry,
  65. base::Time now);
  66. // Returns if the Entry has expired based on the |current_time|.
  67. bool IsExpired(base::Time current_time) const;
  68. // Creates a SendTabToSelfEntry consisting of only the required fields.
  69. // This entry will have an expired SharedTime and therefor this function
  70. // should only be used for testing.
  71. static std::unique_ptr<SendTabToSelfEntry> FromRequiredFields(
  72. const std::string& guid,
  73. const GURL& url,
  74. const std::string& target_device_sync_cache_guid);
  75. private:
  76. std::string guid_;
  77. GURL url_;
  78. std::string title_;
  79. std::string device_name_;
  80. std::string target_device_sync_cache_guid_;
  81. base::Time shared_time_;
  82. bool notification_dismissed_;
  83. bool opened_;
  84. };
  85. } // namespace send_tab_to_self
  86. #endif // COMPONENTS_SEND_TAB_TO_SELF_SEND_TAB_TO_SELF_ENTRY_H_