Files
brave-core/app/command_utils.cc.template
T

51 lines
1.5 KiB
Plaintext

// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "brave/app/command_utils.h"
#include <string>
#include "base/containers/fixed_flat_map.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/strings/string_piece.h"
#include "brave/app/brave_command_ids.h"
#include "brave/components/commands/common/features.h"
#include "chrome/app/chrome_command_ids.h"
namespace commands {
namespace {
constexpr auto kCommandInfos =
base::MakeFixedFlatMap<int, base::StringPiece>({
COMMAND_NAMES
});
constexpr int kCommandIds[] = {
COMMAND_IDS
};
} // namespace
base::span<const int> GetCommands() {
DCHECK(base::FeatureList::IsEnabled(features::kBraveCommands))
<< "This should only be used when |kBraveCommands| is enabled.";
return kCommandIds;
}
base::StringPiece GetCommandName(int command_id) {
DCHECK(base::FeatureList::IsEnabled(features::kBraveCommands))
<< "This should only be used when |kBraveCommands| is enabled.";
auto it = kCommandInfos.find(command_id);
CHECK(it != kCommandInfos.end())
<< "Unknown command " << command_id
<< ". This function should only be used for known "
"commands (i.e. commands in |GetCommandInfo|). "
"This command should probably be added.";
return it->second.data();
}
} // namespace commands