Skip to content

Commit

Permalink
[Shortcut] Make shortcut id strong alias.
Browse files Browse the repository at this point in the history
This CL makes the shortcut id a strong alias of the std::string to
avoid confusion between different ids.

BUG=1412708

Change-Id: I578620b19b887253600104f32a6cc76ce003c72b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4323498
Reviewed-by: Tim Sergeant <tsergeant@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115565}
  • Loading branch information
Maggie Cai authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent c216e58 commit 21c8760
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion components/services/app_service/public/cpp/app_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "components/services/app_service/public/cpp/macros.h"
#include "components/services/app_service/public/cpp/permission.h"
#include "components/services/app_service/public/cpp/run_on_os_login_types.h"
#include "components/services/app_service/public/cpp/shortcut.h"
#include "components/services/app_service/public/protos/app_types.pb.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

Expand Down
5 changes: 4 additions & 1 deletion components/services/app_service/public/cpp/shortcut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

namespace apps {

Shortcut::Shortcut(const std::string& shortcut_id,
Shortcut::Shortcut(const ShortcutId& shortcut_id,
const std::string& name,
uint8_t position)
: shortcut_id(shortcut_id), name(name), position(position) {}

Shortcut::~Shortcut() = default;

Shortcut::Shortcut(Shortcut&&) = default;
Shortcut& Shortcut::operator=(Shortcut&&) = default;

bool Shortcut::operator==(const Shortcut& other) const {
return shortcut_id == other.shortcut_id && name == other.name &&
position == other.position;
Expand Down
15 changes: 9 additions & 6 deletions components/services/app_service/public/cpp/shortcut.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
#include <vector>

#include "base/component_export.h"
#include "base/types/strong_alias.h"
#include "components/services/app_service/public/cpp/macros.h"

namespace apps {

using ShortcutId = base::StrongAlias<class ShortcutIdTag, std::string>;

struct COMPONENT_EXPORT(APP_TYPES) Shortcut {
Shortcut(const std::string& shortcut_id,
Shortcut(const ShortcutId& shortcut_id,
const std::string& name,
uint8_t position = 0);

Shortcut(const Shortcut&) = delete;
Shortcut& operator=(const Shortcut&) = delete;
Shortcut(Shortcut&&) = default;
Shortcut& operator=(Shortcut&&) = default;
Shortcut(Shortcut&&);
Shortcut& operator=(Shortcut&&);

~Shortcut();

Expand All @@ -39,9 +42,9 @@ struct COMPONENT_EXPORT(APP_TYPES) Shortcut {
// - position: 0
std::string ToString() const;

// Represents a particular shortcut in an app. Needs to be unique within an
// app as calls will be made using both app_id and shortcut_id.
std::string shortcut_id;
// Represents the unique identifier for a shortcut. This identifier should be
// unique within a profile, and stable across different user sessions.
ShortcutId shortcut_id;
// Name of the shortcut.
std::string name;
// "Position" of a shortcut, which is a non-negative, sequential
Expand Down

0 comments on commit 21c8760

Please sign in to comment.