Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Chromium code style for enum classes #26165

Merged
merged 1 commit into from Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions shell/app/electron_content_client.cc
Expand Up @@ -49,29 +49,34 @@ namespace electron {

namespace {

enum class WidevineCdmFileCheck {
kNotChecked,
kFound,
kNotFound,
};

#if defined(WIDEVINE_CDM_AVAILABLE)
bool IsWidevineAvailable(
base::FilePath* cdm_path,
std::vector<media::VideoCodec>* codecs_supported,
base::flat_set<media::CdmSessionType>* session_types_supported,
base::flat_set<media::EncryptionMode>* modes_supported) {
static enum {
NOT_CHECKED,
FOUND,
NOT_FOUND,
} widevine_cdm_file_check = NOT_CHECKED;
static WidevineCdmFileCheck widevine_cdm_file_check =
WidevineCdmFileCheck::kNotChecked;

if (widevine_cdm_file_check == NOT_CHECKED) {
if (widevine_cdm_file_check == WidevineCdmFileCheck::kNotChecked) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
*cdm_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
if (!cdm_path->empty()) {
*cdm_path = cdm_path->AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName));
widevine_cdm_file_check = base::PathExists(*cdm_path) ? FOUND : NOT_FOUND;
widevine_cdm_file_check = base::PathExists(*cdm_path)
? WidevineCdmFileCheck::kFound
: WidevineCdmFileCheck::kNotFound;
}
}

if (widevine_cdm_file_check == FOUND) {
if (widevine_cdm_file_check == WidevineCdmFileCheck::kFound) {
// Add the supported codecs as if they came from the component manifest.
// This list must match the CDM that is being bundled with Chrome.
codecs_supported->push_back(media::VideoCodec::kCodecVP8);
Expand Down
85 changes: 43 additions & 42 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -78,13 +78,13 @@ struct Converter<electron::ProcessIntegrityLevel> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::ProcessIntegrityLevel value) {
switch (value) {
case electron::ProcessIntegrityLevel::Untrusted:
case electron::ProcessIntegrityLevel::kUntrusted:
return StringToV8(isolate, "untrusted");
case electron::ProcessIntegrityLevel::Low:
case electron::ProcessIntegrityLevel::kLow:
return StringToV8(isolate, "low");
case electron::ProcessIntegrityLevel::Medium:
case electron::ProcessIntegrityLevel::kMedium:
return StringToV8(isolate, "medium");
case electron::ProcessIntegrityLevel::High:
case electron::ProcessIntegrityLevel::kHigh:
return StringToV8(isolate, "high");
default:
return StringToV8(isolate, "unknown");
Expand Down Expand Up @@ -127,11 +127,11 @@ struct Converter<JumpListItem::Type> {
return false;

if (item_type == "task")
*out = JumpListItem::Type::TASK;
*out = JumpListItem::Type::kTask;
else if (item_type == "separator")
*out = JumpListItem::Type::SEPARATOR;
*out = JumpListItem::Type::kSeparator;
else if (item_type == "file")
*out = JumpListItem::Type::FILE;
*out = JumpListItem::Type::kFile;
else
return false;

Expand All @@ -142,15 +142,15 @@ struct Converter<JumpListItem::Type> {
JumpListItem::Type val) {
std::string item_type;
switch (val) {
case JumpListItem::Type::TASK:
case JumpListItem::Type::kTask:
item_type = "task";
break;

case JumpListItem::Type::SEPARATOR:
case JumpListItem::Type::kSeparator:
item_type = "separator";
break;

case JumpListItem::Type::FILE:
case JumpListItem::Type::kFile:
item_type = "file";
break;
}
Expand All @@ -171,7 +171,7 @@ struct Converter<JumpListItem> {
return false;

switch (out->type) {
case JumpListItem::Type::TASK:
case JumpListItem::Type::kTask:
if (!dict.Get("program", &(out->path)) ||
!dict.Get("title", &(out->title)))
return false;
Expand All @@ -185,10 +185,10 @@ struct Converter<JumpListItem> {
dict.Get("workingDirectory", &(out->working_dir));
return true;

case JumpListItem::Type::SEPARATOR:
case JumpListItem::Type::kSeparator:
return true;

case JumpListItem::Type::FILE:
case JumpListItem::Type::kFile:
return dict.Get("path", &(out->path));
}

Expand All @@ -202,7 +202,7 @@ struct Converter<JumpListItem> {
dict.Set("type", val.type);

switch (val.type) {
case JumpListItem::Type::TASK:
case JumpListItem::Type::kTask:
dict.Set("program", val.path);
dict.Set("args", val.arguments);
dict.Set("title", val.title);
Expand All @@ -212,10 +212,10 @@ struct Converter<JumpListItem> {
dict.Set("workingDirectory", val.working_dir);
break;

case JumpListItem::Type::SEPARATOR:
case JumpListItem::Type::kSeparator:
break;

case JumpListItem::Type::FILE:
case JumpListItem::Type::kFile:
dict.Set("path", val.path);
break;
}
Expand All @@ -233,13 +233,13 @@ struct Converter<JumpListCategory::Type> {
return false;

if (category_type == "tasks")
*out = JumpListCategory::Type::TASKS;
*out = JumpListCategory::Type::kTasks;
else if (category_type == "frequent")
*out = JumpListCategory::Type::FREQUENT;
*out = JumpListCategory::Type::kFrequent;
else if (category_type == "recent")
*out = JumpListCategory::Type::RECENT;
*out = JumpListCategory::Type::kRecent;
else if (category_type == "custom")
*out = JumpListCategory::Type::CUSTOM;
*out = JumpListCategory::Type::kCustom;
else
return false;

Expand All @@ -250,19 +250,19 @@ struct Converter<JumpListCategory::Type> {
JumpListCategory::Type val) {
std::string category_type;
switch (val) {
case JumpListCategory::Type::TASKS:
case JumpListCategory::Type::kTasks:
category_type = "tasks";
break;

case JumpListCategory::Type::FREQUENT:
case JumpListCategory::Type::kFrequent:
category_type = "frequent";
break;

case JumpListCategory::Type::RECENT:
case JumpListCategory::Type::kRecent:
category_type = "recent";
break;

case JumpListCategory::Type::CUSTOM:
case JumpListCategory::Type::kCustom:
category_type = "custom";
break;
}
Expand All @@ -284,13 +284,13 @@ struct Converter<JumpListCategory> {

if (!dict.Get("type", &(out->type))) {
if (out->name.empty())
out->type = JumpListCategory::Type::TASKS;
out->type = JumpListCategory::Type::kTasks;
else
out->type = JumpListCategory::Type::CUSTOM;
out->type = JumpListCategory::Type::kCustom;
}

if ((out->type == JumpListCategory::Type::TASKS) ||
(out->type == JumpListCategory::Type::CUSTOM)) {
if ((out->type == JumpListCategory::Type::kTasks) ||
(out->type == JumpListCategory::Type::kCustom)) {
if (!dict.Get("items", &(out->items)))
return false;
}
Expand All @@ -305,27 +305,27 @@ struct Converter<JumpListResult> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
std::string result_code;
switch (val) {
case JumpListResult::SUCCESS:
case JumpListResult::kSuccess:
result_code = "ok";
break;

case JumpListResult::ARGUMENT_ERROR:
case JumpListResult::kArgumentError:
result_code = "argumentError";
break;

case JumpListResult::GENERIC_ERROR:
case JumpListResult::kGenericError:
result_code = "error";
break;

case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR:
case JumpListResult::kCustomCategorySeparatorError:
result_code = "invalidSeparatorError";
break;

case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR:
case JumpListResult::kMissingFileTypeRegistrationError:
result_code = "fileTypeRegistrationError";
break;

case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR:
case JumpListResult::kCustomCategoryAccessDeniedError:
result_code = "customCategoryAccessDeniedError";
break;
}
Expand Down Expand Up @@ -1253,19 +1253,19 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
!gin::ConvertFromV8(args->isolate(), val, &categories)) {
gin_helper::ErrorThrower(args->isolate())
.ThrowError("Argument must be null or an array of categories");
return JumpListResult::ARGUMENT_ERROR;
return JumpListResult::kArgumentError;
}

JumpList jump_list(Browser::Get()->GetAppUserModelID());

if (delete_jump_list) {
return jump_list.Delete() ? JumpListResult::SUCCESS
: JumpListResult::GENERIC_ERROR;
return jump_list.Delete() ? JumpListResult::kSuccess
: JumpListResult::kGenericError;
}

// Start a transaction that updates the JumpList of this application.
if (!jump_list.Begin())
return JumpListResult::GENERIC_ERROR;
return JumpListResult::kGenericError;

JumpListResult result = jump_list.AppendCategories(categories);
// AppendCategories may have failed to add some categories, but it's better
Expand All @@ -1275,8 +1275,8 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
// It's more useful to return the earlier error code that might give
// some indication as to why the transaction actually failed, so don't
// overwrite it with a "generic error" code here.
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
if (result == JumpListResult::kSuccess)
result = JumpListResult::kGenericError;
}

return result;
Expand Down Expand Up @@ -1488,9 +1488,10 @@ int DockBounce(gin::Arguments* args) {
args->GetNext(&type);

if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL);
request_id = Browser::Get()->DockBounce(Browser::BounceType::kCritical);
else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL);
request_id =
Browser::Get()->DockBounce(Browser::BounceType::kInformational);
return request_id;
}

Expand Down
18 changes: 9 additions & 9 deletions shell/browser/api/electron_api_protocol.cc
Expand Up @@ -160,13 +160,13 @@ const char* kBuiltinSchemes[] = {
// Convert error code to string.
std::string ErrorCodeToString(ProtocolError error) {
switch (error) {
case ProtocolError::REGISTERED:
case ProtocolError::kRegistered:
return "The scheme has been registered";
case ProtocolError::NOT_REGISTERED:
case ProtocolError::kNotRegistered:
return "The scheme has not been registered";
case ProtocolError::INTERCEPTED:
case ProtocolError::kIntercepted:
return "The scheme has been intercepted";
case ProtocolError::NOT_INTERCEPTED:
case ProtocolError::kNotIntercepted:
return "The scheme has not been intercepted";
default:
return "Unexpected error";
Expand All @@ -184,14 +184,14 @@ ProtocolError Protocol::RegisterProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler) {
bool added = protocol_registry_->RegisterProtocol(type, scheme, handler);
return added ? ProtocolError::OK : ProtocolError::REGISTERED;
return added ? ProtocolError::kOK : ProtocolError::kRegistered;
}

bool Protocol::UnregisterProtocol(const std::string& scheme,
gin::Arguments* args) {
bool removed = protocol_registry_->UnregisterProtocol(scheme);
HandleOptionalCallback(
args, removed ? ProtocolError::OK : ProtocolError::NOT_REGISTERED);
args, removed ? ProtocolError::kOK : ProtocolError::kNotRegistered);
return removed;
}

Expand All @@ -203,14 +203,14 @@ ProtocolError Protocol::InterceptProtocol(ProtocolType type,
const std::string& scheme,
const ProtocolHandler& handler) {
bool added = protocol_registry_->InterceptProtocol(type, scheme, handler);
return added ? ProtocolError::OK : ProtocolError::INTERCEPTED;
return added ? ProtocolError::kOK : ProtocolError::kIntercepted;
}

bool Protocol::UninterceptProtocol(const std::string& scheme,
gin::Arguments* args) {
bool removed = protocol_registry_->UninterceptProtocol(scheme);
HandleOptionalCallback(
args, removed ? ProtocolError::OK : ProtocolError::NOT_INTERCEPTED);
args, removed ? ProtocolError::kOK : ProtocolError::kNotIntercepted);
return removed;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ void Protocol::HandleOptionalCallback(gin::Arguments* args,
env,
"The callback argument of protocol module APIs is no longer needed.",
"ProtocolDeprecateCallback");
if (error == ProtocolError::OK)
if (error == ProtocolError::kOK)
callback.Run(v8::Null(args->isolate()));
else
callback.Run(v8::Exception::Error(
Expand Down
14 changes: 7 additions & 7 deletions shell/browser/api/electron_api_protocol.h
Expand Up @@ -27,11 +27,11 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,

// Possible errors.
enum class ProtocolError {
OK, // no error
REGISTERED,
NOT_REGISTERED,
INTERCEPTED,
NOT_INTERCEPTED,
kOK, // no error
kRegistered,
kNotRegistered,
kIntercepted,
kNotIntercepted,
};

// Protocol implementation based on network services.
Expand Down Expand Up @@ -78,15 +78,15 @@ class Protocol : public gin::Wrappable<Protocol> {
gin::Arguments* args) {
auto result = RegisterProtocol(type, scheme, handler);
HandleOptionalCallback(args, result);
return result == ProtocolError::OK;
return result == ProtocolError::kOK;
}
template <ProtocolType type>
bool InterceptProtocolFor(const std::string& scheme,
const ProtocolHandler& handler,
gin::Arguments* args) {
auto result = InterceptProtocol(type, scheme, handler);
HandleOptionalCallback(args, result);
return result == ProtocolError::OK;
return result == ProtocolError::kOK;
}

// Be compatible with old interface, which accepts optional callback.
Expand Down