refactor: Chromium code style for enum classes (#26165)

This commit is contained in:
Milan Burda 2020-10-27 18:51:45 +01:00 committed by GitHub
parent dbf2931f0e
commit 1c99a9b425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 300 additions and 295 deletions

View file

@ -83,7 +83,7 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
DCHECK(shell_link);
DCHECK(item);
item->type = JumpListItem::Type::TASK;
item->type = JumpListItem::Type::kTask;
wchar_t path[MAX_PATH];
if (FAILED(shell_link->GetPath(path, base::size(path), nullptr, 0)))
return false;
@ -134,7 +134,7 @@ void ConvertRemovedJumpListItems(IObjectArray* in,
IShellLink* shell_link;
for (UINT i = 0; i < removed_count; ++i) {
if (SUCCEEDED(in->GetAt(i, IID_PPV_ARGS(&shell_item)))) {
item.type = JumpListItem::Type::FILE;
item.type = JumpListItem::Type::kFile;
GetShellItemFileName(shell_item, &item.path);
out->push_back(item);
shell_item->Release();
@ -217,22 +217,22 @@ bool JumpList::Delete() {
JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
DCHECK(destinations_);
if (!destinations_)
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
if (category.items.empty())
return JumpListResult::SUCCESS;
return JumpListResult::kSuccess;
CComPtr<IObjectCollection> collection;
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection))) {
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
}
auto result = JumpListResult::SUCCESS;
auto result = JumpListResult::kSuccess;
// Keep track of how many items were actually appended to the category.
int appended_count = 0;
for (const auto& item : category.items) {
switch (item.type) {
case JumpListItem::Type::TASK:
case JumpListItem::Type::kTask:
if (AppendTask(item, collection))
++appended_count;
else
@ -241,8 +241,8 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
"to Jump List.";
break;
case JumpListItem::Type::SEPARATOR:
if (category.type == JumpListCategory::Type::TASKS) {
case JumpListItem::Type::kSeparator:
if (category.type == JumpListCategory::Type::kTasks) {
if (AppendSeparator(collection))
++appended_count;
} else {
@ -250,11 +250,11 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
<< "'" << category.name << "'. "
<< "Separators are only allowed in the standard 'Tasks' "
"Jump List category.";
result = JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR;
result = JumpListResult::kCustomCategorySeparatorError;
}
break;
case JumpListItem::Type::FILE:
case JumpListItem::Type::kFile:
if (AppendFile(item, collection))
++appended_count;
else
@ -269,17 +269,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
return result;
if ((static_cast<size_t>(appended_count) < category.items.size()) &&
(result == JumpListResult::SUCCESS)) {
result = JumpListResult::GENERIC_ERROR;
(result == JumpListResult::kSuccess)) {
result = JumpListResult::kGenericError;
}
CComQIPtr<IObjectArray> items(collection);
if (category.type == JumpListCategory::Type::TASKS) {
if (category.type == JumpListCategory::Type::kTasks) {
if (FAILED(destinations_->AddUserTasks(items))) {
LOG(ERROR) << "Failed to append items to the standard Tasks category.";
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
if (result == JumpListResult::kSuccess)
result = JumpListResult::kGenericError;
}
} else {
HRESULT hr = destinations_->AppendCategory(category.name.c_str(), items);
@ -288,17 +288,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' "
<< "to Jump List due to missing file type registration.";
result = JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR;
result = JumpListResult::kMissingFileTypeRegistrationError;
} else if (hr == E_ACCESSDENIED) {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' "
<< "to Jump List due to system privacy settings.";
result = JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR;
result = JumpListResult::kCustomCategoryAccessDeniedError;
} else {
LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' to Jump List.";
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
if (result == JumpListResult::kSuccess)
result = JumpListResult::kGenericError;
}
}
}
@ -313,36 +313,36 @@ JumpListResult JumpList::AppendCategories(
const std::vector<JumpListCategory>& categories) {
DCHECK(destinations_);
if (!destinations_)
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;
auto result = JumpListResult::SUCCESS;
auto result = JumpListResult::kSuccess;
for (const auto& category : categories) {
auto latestResult = JumpListResult::SUCCESS;
auto latestResult = JumpListResult::kSuccess;
switch (category.type) {
case JumpListCategory::Type::TASKS:
case JumpListCategory::Type::CUSTOM:
case JumpListCategory::Type::kTasks:
case JumpListCategory::Type::kCustom:
latestResult = AppendCategory(category);
break;
case JumpListCategory::Type::RECENT:
case JumpListCategory::Type::kRecent:
if (FAILED(destinations_->AppendKnownCategory(KDC_RECENT))) {
LOG(ERROR) << "Failed to append Recent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR;
latestResult = JumpListResult::kGenericError;
}
break;
case JumpListCategory::Type::FREQUENT:
case JumpListCategory::Type::kFrequent:
if (FAILED(destinations_->AppendKnownCategory(KDC_FREQUENT))) {
LOG(ERROR) << "Failed to append Frequent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR;
latestResult = JumpListResult::kGenericError;
}
break;
}
// Keep the first non-generic error code as only one can be returned from
// the function (so try to make it the most useful one).
if (((result == JumpListResult::SUCCESS) ||
(result == JumpListResult::GENERIC_ERROR)) &&
(latestResult != JumpListResult::SUCCESS))
if (((result == JumpListResult::kSuccess) ||
(result == JumpListResult::kGenericError)) &&
(latestResult != JumpListResult::kSuccess))
result = latestResult;
}
return result;

View file

@ -15,34 +15,34 @@
namespace electron {
enum class JumpListResult : int {
SUCCESS = 0,
kSuccess = 0,
// In JS code this error will manifest as an exception.
ARGUMENT_ERROR = 1,
kArgumentError = 1,
// Generic error, the runtime logs may provide some clues.
GENERIC_ERROR = 2,
kGenericError = 2,
// Custom categories can't contain separators.
CUSTOM_CATEGORY_SEPARATOR_ERROR = 3,
kCustomCategorySeparatorError = 3,
// The app isn't registered to handle a file type found in a custom category.
MISSING_FILE_TYPE_REGISTRATION_ERROR = 4,
kMissingFileTypeRegistrationError = 4,
// Custom categories can't be created due to user privacy settings.
CUSTOM_CATEGORY_ACCESS_DENIED_ERROR = 5,
kCustomCategoryAccessDeniedError = 5,
};
struct JumpListItem {
enum class Type {
// A task will launch an app (usually the one that created the Jump List)
// with specific arguments.
TASK,
kTask,
// Separators can only be inserted between items in the standard Tasks
// category, they can't appear in custom categories.
SEPARATOR,
kSeparator,
// A file link will open a file using the app that created the Jump List,
// for this to work the app must be registered as a handler for the file
// type (though the app doesn't have to be the default handler).
FILE
kFile
};
Type type = Type::TASK;
Type type = Type::kTask;
// For tasks this is the path to the program executable, for file links this
// is the full filename.
base::FilePath path;
@ -61,18 +61,18 @@ struct JumpListItem {
struct JumpListCategory {
enum class Type {
// A custom category can contain tasks and files, but not separators.
CUSTOM,
kCustom,
// Frequent/Recent categories are managed by the OS, their name and items
// can't be set by the app (though items can be set indirectly).
FREQUENT,
RECENT,
kFrequent,
kRecent,
// The standard Tasks category can't be renamed by the app, but the app
// can set the items that should appear in this category, and those items
// can include tasks, files, and separators.
TASKS
kTasks
};
Type type = Type::TASKS;
Type type = Type::kTasks;
base::string16 name;
std::vector<JumpListItem> items;

View file

@ -25,15 +25,15 @@ namespace {
UINT ConvertIconType(electron::TrayIcon::IconType type) {
using IconType = electron::TrayIcon::IconType;
switch (type) {
case IconType::None:
case IconType::kNone:
return NIIF_NONE;
case IconType::Info:
case IconType::kInfo:
return NIIF_INFO;
case IconType::Warning:
case IconType::kWarning:
return NIIF_WARNING;
case IconType::Error:
case IconType::kError:
return NIIF_ERROR;
case IconType::Custom:
case IconType::kCustom:
return NIIF_USER;
default:
NOTREACHED() << "Invalid icon type";