Commit e2f14475 authored by xiaofeng.zhang's avatar xiaofeng.zhang Committed by Commit bot

[ServiceWorker] Some code clean-up for content::ServiceWorkerContextClient

Using switch is the best option here to get compile time verification, and
we can catch it if WebServiceWorkerEventResult gains a new type later.

Here also replace some if-return with DCHECK.

BUG=None

Review-Url: https://codereview.chromium.org/2606303002
Cr-Commit-Position: refs/heads/master@{#442822}
parent 9b3dd2bc
......@@ -730,6 +730,7 @@ William Xie <william.xie@chromium.com>
William Xie <william.xie@intel.com>
Xiang Long <xiang.long@intel.com>
Xiangze Zhang <xiangze.zhang@intel.com>
Xiaofeng Zhang <xiaofeng.zhang@intel.com>
Xiaolei Yu <dreifachstein@gmail.com>
Xiaoyin Liu <xiaoyin.l@outlook.com>
Xinchao He <hexinchao@gmail.com>
......
......@@ -114,6 +114,18 @@ class WebServiceWorkerNetworkProviderImpl
}
};
ServiceWorkerStatusCode EventResultToStatus(
blink::WebServiceWorkerEventResult result) {
switch (result) {
case blink::WebServiceWorkerEventResultCompleted:
return SERVICE_WORKER_OK;
case blink::WebServiceWorkerEventResultRejected:
return SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
}
NOTREACHED() << "Got invalid result: " << result;
return SERVICE_WORKER_ERROR_FAILED;
}
void SendPostMessageToClientOnMainThread(
ThreadSafeSender* sender,
int routing_id,
......@@ -674,13 +686,8 @@ void ServiceWorkerContextClient::didHandleExtendableMessageEvent(
const DispatchExtendableMessageEventCallback* callback =
context_->message_event_callbacks.Lookup(request_id);
DCHECK(callback);
if (result == blink::WebServiceWorkerEventResultCompleted) {
callback->Run(SERVICE_WORKER_OK,
base::Time::FromDoubleT(event_dispatch_time));
} else {
callback->Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
base::Time::FromDoubleT(event_dispatch_time));
}
callback->Run(EventResultToStatus(result),
base::Time::FromDoubleT(event_dispatch_time));
context_->message_event_callbacks.Remove(request_id);
}
......@@ -725,12 +732,8 @@ void ServiceWorkerContextClient::didHandleFetchEvent(
}
const FetchCallback* callback =
context_->fetch_event_callbacks.Lookup(fetch_event_id);
if (!callback)
return;
callback->Run(result == blink::WebServiceWorkerEventResultCompleted
? SERVICE_WORKER_OK
: SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
DCHECK(callback);
callback->Run(EventResultToStatus(result),
base::Time::FromDoubleT(event_dispatch_time));
context_->fetch_event_callbacks.Remove(fetch_event_id);
}
......@@ -768,15 +771,9 @@ void ServiceWorkerContextClient::didHandleSyncEvent(
double event_dispatch_time) {
const SyncCallback* callback =
context_->sync_event_callbacks.Lookup(request_id);
if (!callback)
return;
if (result == blink::WebServiceWorkerEventResultCompleted) {
callback->Run(SERVICE_WORKER_OK,
base::Time::FromDoubleT(event_dispatch_time));
} else {
callback->Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
base::Time::FromDoubleT(event_dispatch_time));
}
DCHECK(callback);
callback->Run(EventResultToStatus(result),
base::Time::FromDoubleT(event_dispatch_time));
context_->sync_event_callbacks.Remove(request_id);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment