saved_tab_group_tab.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2022 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_SAVED_TAB_GROUPS_SAVED_TAB_GROUP_TAB_H_
  5. #define COMPONENTS_SAVED_TAB_GROUPS_SAVED_TAB_GROUP_TAB_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/guid.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "base/time/time.h"
  11. #include "components/sync/protocol/saved_tab_group_specifics.pb.h"
  12. #include "components/tab_groups/tab_group_color.h"
  13. #include "components/tab_groups/tab_group_id.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. #include "ui/gfx/image/image.h"
  16. #include "url/gurl.h"
  17. class SavedTabGroup;
  18. // A SavedTabGroupTab stores the url, title, and favicon of a tab.
  19. class SavedTabGroupTab {
  20. public:
  21. SavedTabGroupTab(const GURL& url,
  22. const base::GUID& group_guid,
  23. SavedTabGroup* group = nullptr,
  24. absl::optional<base::GUID> guid = absl::nullopt,
  25. absl::optional<base::Time>
  26. creation_time_windows_epoch_micros = absl::nullopt,
  27. absl::optional<base::Time> update_time_windows_epoch_micros =
  28. absl::nullopt,
  29. absl::optional<std::u16string> title = absl::nullopt,
  30. absl::optional<gfx::Image> favicon = absl::nullopt);
  31. SavedTabGroupTab(const SavedTabGroupTab& other);
  32. ~SavedTabGroupTab();
  33. // Accessors.
  34. const base::GUID& guid() const { return guid_; }
  35. const base::GUID& group_guid() const { return group_guid_; }
  36. SavedTabGroup* saved_tab_group() const { return saved_tab_group_; }
  37. const GURL& url() const { return url_; }
  38. const absl::optional<std::u16string>& title() const { return title_; }
  39. const absl::optional<gfx::Image>& favicon() const { return favicon_; }
  40. const base::Time& creation_time_windows_epoch_micros() const {
  41. return creation_time_windows_epoch_micros_;
  42. }
  43. const base::Time& update_time_windows_epoch_micros() const {
  44. return update_time_windows_epoch_micros_;
  45. }
  46. // Mutators.
  47. SavedTabGroupTab& SetSavedTabGroup(SavedTabGroup* saved_tab_group) {
  48. saved_tab_group_ = saved_tab_group;
  49. return *this;
  50. }
  51. SavedTabGroupTab& SetURL(GURL url) {
  52. url_ = url;
  53. return *this;
  54. }
  55. SavedTabGroupTab& SetTitle(std::u16string title) {
  56. title_ = title;
  57. return *this;
  58. }
  59. SavedTabGroupTab& SetFavicon(absl::optional<gfx::Image> favicon) {
  60. favicon_ = favicon;
  61. return *this;
  62. }
  63. // Converts a `SavedTabGroupSpecifics` retrieved from sync into a
  64. // `SavedTabGroupTab`.
  65. static SavedTabGroupTab FromSpecifics(
  66. const sync_pb::SavedTabGroupSpecifics& specific);
  67. // Converts this `SavedTabGroupTab` into a `SavedTabGroupSpecifics` for sync.
  68. std::unique_ptr<sync_pb::SavedTabGroupSpecifics> ToSpecifics();
  69. private:
  70. // The ID used to represent the tab in sync.
  71. base::GUID guid_;
  72. // The ID used to represent the tab in sync. This must not be null. It
  73. base::GUID group_guid_;
  74. // The Group which owns this tab, this can be null if sync hasn't sent the
  75. // group over yet.
  76. raw_ptr<SavedTabGroup> saved_tab_group_;
  77. // The link to navigate with.
  78. GURL url_;
  79. // The title of the website this urls is associated with.
  80. absl::optional<std::u16string> title_;
  81. // The favicon of the website this SavedTabGroupTab represents.
  82. absl::optional<gfx::Image> favicon_;
  83. // Timestamp for when the tab was created using windows epoch microseconds.
  84. base::Time creation_time_windows_epoch_micros_;
  85. // Timestamp for when the tab was last updated using windows epoch
  86. // microseconds.
  87. base::Time update_time_windows_epoch_micros_;
  88. };
  89. #endif // COMPONENTS_SAVED_TAB_GROUPS_SAVED_TAB_GROUP_TAB_H_