Commit 1815d00a authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Store TabGroupData values directly in group_map_

A unique_ptr<> was used inside a std::map, but std::map values are
already stable in memory. We can directly store TabGroupData values
without indirection and still hand out TabGroupData pointers.

Bug: 905491
Change-Id: I250b156e56dc400a83374e57e06958fa5f06864f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1719446
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681069}
parent 7b585a5d
......@@ -15,6 +15,8 @@ class TabGroupData {
public:
// Construct a TabGroupData with placeholder name and random color.
TabGroupData();
TabGroupData(const TabGroupData& other) = default;
TabGroupData(TabGroupData&& other) = default;
~TabGroupData() = default;
base::string16 title() const { return title_; }
......@@ -30,8 +32,6 @@ class TabGroupData {
base::string16 title_;
SkColor color_;
int tab_count_;
DISALLOW_COPY_AND_ASSIGN(TabGroupData);
};
#endif // CHROME_BROWSER_UI_TABS_TAB_GROUP_DATA_H_
......@@ -780,7 +780,7 @@ bool TabStripModel::IsTabBlocked(int index) const {
const TabGroupData* TabStripModel::GetDataForGroup(TabGroupId group) const {
DCHECK(base::Contains(group_data_, group));
return group_data_.at(group).get();
return &group_data_.at(group);
}
base::Optional<TabGroupId> TabStripModel::GetTabGroupForTab(int index) const {
......@@ -1488,7 +1488,7 @@ int TabStripModel::InsertWebContentsAtImpl(
}
data->set_group(group);
if (group.has_value())
group_data_[group.value()]->TabAdded();
group_data_[group.value()].TabAdded();
// TODO(gbillock): Ask the modal dialog manager whether the WebContents should
// be blocked, or just let the modal dialog manager make the blocking call
......@@ -1759,7 +1759,7 @@ void TabStripModel::AddToNewGroupImpl(const std::vector<int>& indices,
contents_data_.cbegin(), contents_data_.cend(),
[new_group](const auto& datum) { return datum->group() == new_group; }));
group_data_[new_group] = std::make_unique<TabGroupData>();
group_data_.emplace(new_group, TabGroupData());
// Find a destination for the first tab that's not inside another group. We
// will stack the rest of the tabs up to its right.
......@@ -1843,7 +1843,7 @@ void TabStripModel::MoveAndSetGroup(int index,
MoveWebContentsAtImpl(index, new_index, false);
contents_data_[new_index]->set_group(new_group);
if (new_group.has_value())
group_data_[new_group.value()]->TabAdded();
group_data_[new_group.value()].TabAdded();
NotifyGroupChange(new_index, old_group, new_group);
}
......@@ -1870,7 +1870,7 @@ base::Optional<TabGroupId> TabStripModel::UngroupTab(int index) {
return base::nullopt;
contents_data_[index]->set_group(base::nullopt);
TabGroupData* group_data = group_data_[group.value()].get();
TabGroupData* group_data = &group_data_[group.value()];
group_data->TabRemoved();
// Delete the group if we just ungrouped the last tab in that group.
if (group_data->empty())
......
......@@ -34,7 +34,6 @@
#endif
class Profile;
class TabGroupData;
class TabStripModelDelegate;
namespace content {
......@@ -325,7 +324,8 @@ class TabStripModel {
// https://crbug.com/915956).
base::Optional<TabGroupId> GetTabGroupForTab(int index) const;
// Returns the TabGroupData instance for the given |group|.
// Returns the TabGroupData instance for the given |group|. The returned
// pointer is valid until all tabs in |group| are destroyed.
const TabGroupData* GetDataForGroup(TabGroupId group) const;
// Returns a list of tab groups that contain at least one tab in this strip.
......@@ -668,7 +668,7 @@ class TabStripModel {
// The data for tab groups hosted within this TabStripModel, indexed by the
// group ID.
std::map<TabGroupId, std::unique_ptr<TabGroupData>> group_data_;
std::map<TabGroupId, TabGroupData> group_data_;
TabStripModelDelegate* delegate_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment