Commit 0cfb9adb authored by Connie Wan's avatar Connie Wan Committed by Commit Bot

Add a CreateEmpty() constructor to TabGroupId

This is useful for the extensions API, where it's helpful to have something like:

    tab_groups::TabGroupId group = tab_groups::TabGroupId::CreateEmpty();
    GetGroupFromId(id, &group);  // Populates group by reference, with an existing value.
    if (!group.is_empty()) {
      // Logic handling the group
    }

Having CreateEmpty() and is_empty() helps make this pattern intentional without accidentally creating empty groups and breaking assumptions in the tabstrip.

Change-Id: Ibb217edfd8ba599023488ea3d1a33277b49d8284
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415573Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Commit-Queue: Connie Wan <connily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808028}
parent 38a2229c
...@@ -16,6 +16,11 @@ TabGroupId TabGroupId::FromRawToken(base::Token token) { ...@@ -16,6 +16,11 @@ TabGroupId TabGroupId::FromRawToken(base::Token token) {
return TabGroupId(token); return TabGroupId(token);
} }
// static
TabGroupId TabGroupId::CreateEmpty() {
return TabGroupId(base::Token());
}
TabGroupId::TabGroupId(const TabGroupId& other) = default; TabGroupId::TabGroupId(const TabGroupId& other) = default;
TabGroupId& TabGroupId::operator=(const TabGroupId& other) = default; TabGroupId& TabGroupId::operator=(const TabGroupId& other) = default;
......
...@@ -18,6 +18,11 @@ class COMPONENT_EXPORT(TAB_GROUPS) TabGroupId { ...@@ -18,6 +18,11 @@ class COMPONENT_EXPORT(TAB_GROUPS) TabGroupId {
// call on a valid TabGroupId. // call on a valid TabGroupId.
static TabGroupId FromRawToken(base::Token token); static TabGroupId FromRawToken(base::Token token);
// Should only be used if intending to populate the TabGroupId by reference,
// using a valid existing ID. Primarily needed for the Tab Groups extensions
// API.
static TabGroupId CreateEmpty();
TabGroupId(const TabGroupId& other); TabGroupId(const TabGroupId& other);
TabGroupId& operator=(const TabGroupId& other); TabGroupId& operator=(const TabGroupId& other);
...@@ -28,6 +33,8 @@ class COMPONENT_EXPORT(TAB_GROUPS) TabGroupId { ...@@ -28,6 +33,8 @@ class COMPONENT_EXPORT(TAB_GROUPS) TabGroupId {
const base::Token& token() const { return token_; } const base::Token& token() const { return token_; }
bool is_empty() { return token_.is_zero(); }
std::string ToString() const; std::string ToString() const;
private: private:
......
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