Chromium Code Reviews| Index: content/common/service_worker/service_worker_status_code_traits.cc |
| diff --git a/content/common/service_worker/service_worker_status_code_traits.cc b/content/common/service_worker/service_worker_status_code_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..65f26ae52e9b4832acdf839cefa3d9982787d5d0 |
| --- /dev/null |
| +++ b/content/common/service_worker/service_worker_status_code_traits.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/service_worker/service_worker_status_code_traits.h" |
| + |
| +#include "base/logging.h" |
| +#include "content/common/service_worker/service_worker_status_code.h" |
| +#include "third_party/WebKit/public/platform/modules/serviceworker/service_worker_event_status.mojom.h" |
| + |
| +namespace mojo { |
| + |
| +// static |
| +blink::mojom::ServiceWorkerEventStatus EnumTraits< |
| + blink::mojom::ServiceWorkerEventStatus, |
| + content::ServiceWorkerStatusCode>::ToMojom(content::ServiceWorkerStatusCode |
| + input) { |
| + switch (input) { |
| + case content::SERVICE_WORKER_OK: |
| + return blink::mojom::ServiceWorkerEventStatus::COMPLETED; |
| + case content::SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: |
| + return blink::mojom::ServiceWorkerEventStatus::REJECTED; |
| + case content::SERVICE_WORKER_ERROR_ABORT: |
| + return blink::mojom::ServiceWorkerEventStatus::ABORTED; |
| + default: |
| + NOTREACHED() << "Unexpected ServiceWorkerStatusCode: " << input; |
| + return blink::mojom::ServiceWorkerEventStatus::ABORTED; |
|
shimazu
2016/09/23 08:15:03
Do we have some rules for 'default'?
Which patter
horo
2016/09/23 09:13:35
We need a "default" case.
The compiler checks it.
|
| + } |
| +} |
| + |
| +// static |
| +bool EnumTraits<blink::mojom::ServiceWorkerEventStatus, |
| + content::ServiceWorkerStatusCode>:: |
| + FromMojom(blink::mojom::ServiceWorkerEventStatus input, |
| + content::ServiceWorkerStatusCode* out) { |
| + switch (input) { |
| + case blink::mojom::ServiceWorkerEventStatus::COMPLETED: |
| + *out = content::SERVICE_WORKER_OK; |
| + return true; |
| + case blink::mojom::ServiceWorkerEventStatus::REJECTED: |
| + *out = content::SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; |
| + return true; |
| + case blink::mojom::ServiceWorkerEventStatus::ABORTED: |
| + *out = content::SERVICE_WORKER_ERROR_ABORT; |
| + return true; |
| + } |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| +} // namespace content |