refactor: convert more C++ enums to C++11 enum classes (#26850)
This commit is contained in:
parent
3bc220db29
commit
c9b813a1f9
4 changed files with 48 additions and 38 deletions
|
@ -26,7 +26,7 @@ namespace electron {
|
|||
namespace api {
|
||||
|
||||
#if defined(OS_MAC)
|
||||
enum NotificationCenterKind {
|
||||
enum class NotificationCenterKind {
|
||||
kNSDistributedNotificationCenter = 0,
|
||||
kNSNotificationCenter,
|
||||
kNSWorkspaceNotificationCenter,
|
||||
|
|
|
@ -140,12 +140,13 @@ void SystemPreferences::PostNotification(const std::string& name,
|
|||
int SystemPreferences::SubscribeNotification(
|
||||
const std::string& name,
|
||||
const NotificationCallback& callback) {
|
||||
return DoSubscribeNotification(name, callback,
|
||||
kNSDistributedNotificationCenter);
|
||||
return DoSubscribeNotification(
|
||||
name, callback, NotificationCenterKind::kNSDistributedNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::UnsubscribeNotification(int request_id) {
|
||||
DoUnsubscribeNotification(request_id, kNSDistributedNotificationCenter);
|
||||
DoUnsubscribeNotification(
|
||||
request_id, NotificationCenterKind::kNSDistributedNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::PostLocalNotification(const std::string& name,
|
||||
|
@ -159,11 +160,13 @@ void SystemPreferences::PostLocalNotification(const std::string& name,
|
|||
int SystemPreferences::SubscribeLocalNotification(
|
||||
const std::string& name,
|
||||
const NotificationCallback& callback) {
|
||||
return DoSubscribeNotification(name, callback, kNSNotificationCenter);
|
||||
return DoSubscribeNotification(name, callback,
|
||||
NotificationCenterKind::kNSNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::UnsubscribeLocalNotification(int request_id) {
|
||||
DoUnsubscribeNotification(request_id, kNSNotificationCenter);
|
||||
DoUnsubscribeNotification(request_id,
|
||||
NotificationCenterKind::kNSNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::PostWorkspaceNotification(
|
||||
|
@ -179,12 +182,13 @@ void SystemPreferences::PostWorkspaceNotification(
|
|||
int SystemPreferences::SubscribeWorkspaceNotification(
|
||||
const std::string& name,
|
||||
const NotificationCallback& callback) {
|
||||
return DoSubscribeNotification(name, callback,
|
||||
kNSWorkspaceNotificationCenter);
|
||||
return DoSubscribeNotification(
|
||||
name, callback, NotificationCenterKind::kNSWorkspaceNotificationCenter);
|
||||
}
|
||||
|
||||
void SystemPreferences::UnsubscribeWorkspaceNotification(int request_id) {
|
||||
DoUnsubscribeNotification(request_id, kNSWorkspaceNotificationCenter);
|
||||
DoUnsubscribeNotification(
|
||||
request_id, NotificationCenterKind::kNSWorkspaceNotificationCenter);
|
||||
}
|
||||
|
||||
int SystemPreferences::DoSubscribeNotification(
|
||||
|
@ -195,13 +199,13 @@ int SystemPreferences::DoSubscribeNotification(
|
|||
__block NotificationCallback copied_callback = callback;
|
||||
NSNotificationCenter* center;
|
||||
switch (kind) {
|
||||
case kNSDistributedNotificationCenter:
|
||||
case NotificationCenterKind::kNSDistributedNotificationCenter:
|
||||
center = [NSDistributedNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSNotificationCenter:
|
||||
case NotificationCenterKind::kNSNotificationCenter:
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSWorkspaceNotificationCenter:
|
||||
case NotificationCenterKind::kNSWorkspaceNotificationCenter:
|
||||
center = [[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
break;
|
||||
default:
|
||||
|
@ -239,13 +243,13 @@ void SystemPreferences::DoUnsubscribeNotification(int request_id,
|
|||
id observer = iter->second;
|
||||
NSNotificationCenter* center;
|
||||
switch (kind) {
|
||||
case kNSDistributedNotificationCenter:
|
||||
case NotificationCenterKind::kNSDistributedNotificationCenter:
|
||||
center = [NSDistributedNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSNotificationCenter:
|
||||
case NotificationCenterKind::kNSNotificationCenter:
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
break;
|
||||
case kNSWorkspaceNotificationCenter:
|
||||
case NotificationCenterKind::kNSWorkspaceNotificationCenter:
|
||||
center = [[NSWorkspace sharedWorkspace] notificationCenter];
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -257,21 +257,26 @@ WebRequest::~WebRequest() {
|
|||
gin::ObjectTemplateBuilder WebRequest::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return gin::Wrappable<WebRequest>::GetObjectTemplateBuilder(isolate)
|
||||
.SetMethod("onBeforeRequest",
|
||||
&WebRequest::SetResponseListener<kOnBeforeRequest>)
|
||||
.SetMethod("onBeforeSendHeaders",
|
||||
&WebRequest::SetResponseListener<kOnBeforeSendHeaders>)
|
||||
.SetMethod("onHeadersReceived",
|
||||
&WebRequest::SetResponseListener<kOnHeadersReceived>)
|
||||
.SetMethod(
|
||||
"onBeforeRequest",
|
||||
&WebRequest::SetResponseListener<ResponseEvent::kOnBeforeRequest>)
|
||||
.SetMethod(
|
||||
"onBeforeSendHeaders",
|
||||
&WebRequest::SetResponseListener<ResponseEvent::kOnBeforeSendHeaders>)
|
||||
.SetMethod(
|
||||
"onHeadersReceived",
|
||||
&WebRequest::SetResponseListener<ResponseEvent::kOnHeadersReceived>)
|
||||
.SetMethod("onSendHeaders",
|
||||
&WebRequest::SetSimpleListener<kOnSendHeaders>)
|
||||
&WebRequest::SetSimpleListener<SimpleEvent::kOnSendHeaders>)
|
||||
.SetMethod("onBeforeRedirect",
|
||||
&WebRequest::SetSimpleListener<kOnBeforeRedirect>)
|
||||
.SetMethod("onResponseStarted",
|
||||
&WebRequest::SetSimpleListener<kOnResponseStarted>)
|
||||
&WebRequest::SetSimpleListener<SimpleEvent::kOnBeforeRedirect>)
|
||||
.SetMethod(
|
||||
"onResponseStarted",
|
||||
&WebRequest::SetSimpleListener<SimpleEvent::kOnResponseStarted>)
|
||||
.SetMethod("onErrorOccurred",
|
||||
&WebRequest::SetSimpleListener<kOnErrorOccurred>)
|
||||
.SetMethod("onCompleted", &WebRequest::SetSimpleListener<kOnCompleted>);
|
||||
&WebRequest::SetSimpleListener<SimpleEvent::kOnErrorOccurred>)
|
||||
.SetMethod("onCompleted",
|
||||
&WebRequest::SetSimpleListener<SimpleEvent::kOnCompleted>);
|
||||
}
|
||||
|
||||
const char* WebRequest::GetTypeName() {
|
||||
|
@ -286,8 +291,8 @@ int WebRequest::OnBeforeRequest(extensions::WebRequestInfo* info,
|
|||
const network::ResourceRequest& request,
|
||||
net::CompletionOnceCallback callback,
|
||||
GURL* new_url) {
|
||||
return HandleResponseEvent(kOnBeforeRequest, info, std::move(callback),
|
||||
new_url, request);
|
||||
return HandleResponseEvent(ResponseEvent::kOnBeforeRequest, info,
|
||||
std::move(callback), new_url, request);
|
||||
}
|
||||
|
||||
int WebRequest::OnBeforeSendHeaders(extensions::WebRequestInfo* info,
|
||||
|
@ -295,7 +300,7 @@ int WebRequest::OnBeforeSendHeaders(extensions::WebRequestInfo* info,
|
|||
BeforeSendHeadersCallback callback,
|
||||
net::HttpRequestHeaders* headers) {
|
||||
return HandleResponseEvent(
|
||||
kOnBeforeSendHeaders, info,
|
||||
ResponseEvent::kOnBeforeSendHeaders, info,
|
||||
base::BindOnce(std::move(callback), std::set<std::string>(),
|
||||
std::set<std::string>()),
|
||||
headers, request, *headers);
|
||||
|
@ -312,25 +317,26 @@ int WebRequest::OnHeadersReceived(
|
|||
original_response_headers ? original_response_headers->GetStatusLine()
|
||||
: std::string();
|
||||
return HandleResponseEvent(
|
||||
kOnHeadersReceived, info, std::move(callback),
|
||||
ResponseEvent::kOnHeadersReceived, info, std::move(callback),
|
||||
std::make_pair(override_response_headers, status_line), request);
|
||||
}
|
||||
|
||||
void WebRequest::OnSendHeaders(extensions::WebRequestInfo* info,
|
||||
const network::ResourceRequest& request,
|
||||
const net::HttpRequestHeaders& headers) {
|
||||
HandleSimpleEvent(kOnSendHeaders, info, request, headers);
|
||||
HandleSimpleEvent(SimpleEvent::kOnSendHeaders, info, request, headers);
|
||||
}
|
||||
|
||||
void WebRequest::OnBeforeRedirect(extensions::WebRequestInfo* info,
|
||||
const network::ResourceRequest& request,
|
||||
const GURL& new_location) {
|
||||
HandleSimpleEvent(kOnBeforeRedirect, info, request, new_location);
|
||||
HandleSimpleEvent(SimpleEvent::kOnBeforeRedirect, info, request,
|
||||
new_location);
|
||||
}
|
||||
|
||||
void WebRequest::OnResponseStarted(extensions::WebRequestInfo* info,
|
||||
const network::ResourceRequest& request) {
|
||||
HandleSimpleEvent(kOnResponseStarted, info, request);
|
||||
HandleSimpleEvent(SimpleEvent::kOnResponseStarted, info, request);
|
||||
}
|
||||
|
||||
void WebRequest::OnErrorOccurred(extensions::WebRequestInfo* info,
|
||||
|
@ -338,7 +344,7 @@ void WebRequest::OnErrorOccurred(extensions::WebRequestInfo* info,
|
|||
int net_error) {
|
||||
callbacks_.erase(info->id);
|
||||
|
||||
HandleSimpleEvent(kOnErrorOccurred, info, request, net_error);
|
||||
HandleSimpleEvent(SimpleEvent::kOnErrorOccurred, info, request, net_error);
|
||||
}
|
||||
|
||||
void WebRequest::OnCompleted(extensions::WebRequestInfo* info,
|
||||
|
@ -346,7 +352,7 @@ void WebRequest::OnCompleted(extensions::WebRequestInfo* info,
|
|||
int net_error) {
|
||||
callbacks_.erase(info->id);
|
||||
|
||||
HandleSimpleEvent(kOnCompleted, info, request, net_error);
|
||||
HandleSimpleEvent(SimpleEvent::kOnCompleted, info, request, net_error);
|
||||
}
|
||||
|
||||
void WebRequest::OnRequestWillBeDestroyed(extensions::WebRequestInfo* info) {
|
||||
|
|
|
@ -86,14 +86,14 @@ class WebRequest : public gin::Wrappable<WebRequest>, public WebRequestAPI {
|
|||
WebRequest(v8::Isolate* isolate, content::BrowserContext* browser_context);
|
||||
~WebRequest() override;
|
||||
|
||||
enum SimpleEvent {
|
||||
enum class SimpleEvent {
|
||||
kOnSendHeaders,
|
||||
kOnBeforeRedirect,
|
||||
kOnResponseStarted,
|
||||
kOnCompleted,
|
||||
kOnErrorOccurred,
|
||||
};
|
||||
enum ResponseEvent {
|
||||
enum class ResponseEvent {
|
||||
kOnBeforeRequest,
|
||||
kOnBeforeSendHeaders,
|
||||
kOnHeadersReceived,
|
||||
|
|
Loading…
Reference in a new issue