saved_tab_group.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_H_
  5. #define COMPONENTS_SAVED_TAB_GROUPS_SAVED_TAB_GROUP_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/guid.h"
  9. #include "components/saved_tab_groups/saved_tab_group_tab.h"
  10. #include "components/sync/protocol/saved_tab_group_specifics.pb.h"
  11. #include "components/tab_groups/tab_group_color.h"
  12. #include "components/tab_groups/tab_group_id.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. #include "ui/gfx/image/image.h"
  15. #include "url/gurl.h"
  16. // Preserves the state of a Tab group that was saved from the
  17. // tab_group_editor_bubble_view's save toggle button. Additionally, these values
  18. // may change if the tab groups name, color, or urls are changed from the
  19. // tab_group_editor_bubble_view.
  20. class SavedTabGroup {
  21. public:
  22. SavedTabGroup(
  23. const std::u16string& title,
  24. const tab_groups::TabGroupColorId& color,
  25. const std::vector<SavedTabGroupTab>& urls,
  26. absl::optional<base::GUID> saved_guid = absl::nullopt,
  27. absl::optional<tab_groups::TabGroupId> tab_group_id = absl::nullopt,
  28. absl::optional<base::Time> creation_time_windows_epoch_micros =
  29. absl::nullopt,
  30. absl::optional<base::Time> update_time_windows_epoch_micros =
  31. absl::nullopt);
  32. SavedTabGroup(const SavedTabGroup& other);
  33. ~SavedTabGroup();
  34. // Metadata accessors.
  35. const base::GUID& saved_guid() const { return saved_guid_; }
  36. const absl::optional<tab_groups::TabGroupId>& tab_group_id() const {
  37. return tab_group_id_;
  38. }
  39. const base::Time& creation_time_windows_epoch_micros() const {
  40. return creation_time_windows_epoch_micros_;
  41. }
  42. const base::Time& update_time_windows_epoch_micros() const {
  43. return update_time_windows_epoch_micros_;
  44. }
  45. const std::u16string& title() const { return title_; }
  46. const tab_groups::TabGroupColorId& color() const { return color_; }
  47. const std::vector<SavedTabGroupTab>& saved_tabs() const {
  48. return saved_tabs_;
  49. }
  50. // Metadata mutators.
  51. SavedTabGroup& SetTitle(std::u16string title) {
  52. title_ = title;
  53. return *this;
  54. };
  55. SavedTabGroup& SetColor(tab_groups::TabGroupColorId color) {
  56. color_ = color;
  57. return *this;
  58. };
  59. SavedTabGroup& SetLocalGroupId(
  60. absl::optional<tab_groups::TabGroupId> tab_group_id) {
  61. tab_group_id_ = tab_group_id;
  62. return *this;
  63. }
  64. // Converts a `SavedTabGroupSpecifics` retrieved from sync into a
  65. // `SavedTabGroupTab`.
  66. static SavedTabGroup FromSpecifics(
  67. const sync_pb::SavedTabGroupSpecifics& specific);
  68. // Converts a `SavedTabGroupTab` into a `SavedTabGroupSpecifics` for sync.
  69. std::unique_ptr<sync_pb::SavedTabGroupSpecifics> ToSpecifics();
  70. // Converts tab group color ids into the sync data type for saved tab group
  71. // colors.
  72. static ::sync_pb::SavedTabGroup_SavedTabGroupColor TabGroupColorToSyncColor(
  73. const tab_groups::TabGroupColorId color);
  74. // Converts sync group colors into tab group colors ids.
  75. static tab_groups::TabGroupColorId SyncColorToTabGroupColor(
  76. const sync_pb::SavedTabGroup::SavedTabGroupColor color);
  77. private:
  78. // The ID used to represent the group in sync.
  79. base::GUID saved_guid_;
  80. // The ID of the tab group in the tab strip which is associated with the saved
  81. // tab group object. This can be null if the saved tab group is not in any tab
  82. // strip.
  83. absl::optional<tab_groups::TabGroupId> tab_group_id_;
  84. // The title of the saved tab group.
  85. std::u16string title_;
  86. // The color of the saved tab group.
  87. tab_groups::TabGroupColorId color_;
  88. // The URLS and later webcontents (such as favicons) of the saved tab group.
  89. std::vector<SavedTabGroupTab> saved_tabs_;
  90. // Timestamp for when the tab was created using windows epoch microseconds.
  91. base::Time creation_time_windows_epoch_micros_;
  92. // Timestamp for when the tab was last updated using windows epoch
  93. // microseconds.
  94. base::Time update_time_windows_epoch_micros_;
  95. };
  96. #endif // COMPONENTS_SAVED_TAB_GROUPS_SAVED_TAB_GROUP_H_