1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_registration_status.h"
9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h"
14 using blink::WebServiceWorkerError
;
16 void GetServiceWorkerRegistrationStatusResponse(
17 ServiceWorkerStatusCode status
,
18 const std::string
& status_message
,
19 blink::WebServiceWorkerError::ErrorType
* error_type
,
20 base::string16
* message
) {
21 *error_type
= WebServiceWorkerError::ErrorTypeUnknown
;
22 if (!status_message
.empty())
23 *message
= base::UTF8ToUTF16(status_message
);
25 *message
= base::ASCIIToUTF16(ServiceWorkerStatusToString(status
));
27 case SERVICE_WORKER_OK
:
28 NOTREACHED() << "Calling this when status == OK is not allowed";
31 case SERVICE_WORKER_ERROR_START_WORKER_FAILED
:
32 case SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED
:
33 case SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND
:
34 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED
:
35 case SERVICE_WORKER_ERROR_REDUNDANT
:
36 case SERVICE_WORKER_ERROR_DISALLOWED
:
37 *error_type
= WebServiceWorkerError::ErrorTypeInstall
;
40 case SERVICE_WORKER_ERROR_NOT_FOUND
:
41 *error_type
= WebServiceWorkerError::ErrorTypeNotFound
;
44 case SERVICE_WORKER_ERROR_NETWORK
:
45 *error_type
= WebServiceWorkerError::ErrorTypeNetwork
;
48 case SERVICE_WORKER_ERROR_SECURITY
:
49 *error_type
= WebServiceWorkerError::ErrorTypeSecurity
;
52 case SERVICE_WORKER_ERROR_TIMEOUT
:
53 *error_type
= WebServiceWorkerError::ErrorTypeTimeout
;
56 case SERVICE_WORKER_ERROR_ABORT
:
57 *error_type
= WebServiceWorkerError::ErrorTypeAbort
;
60 case SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED
:
61 case SERVICE_WORKER_ERROR_IPC_FAILED
:
62 case SERVICE_WORKER_ERROR_FAILED
:
63 case SERVICE_WORKER_ERROR_EXISTS
:
64 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED
:
65 case SERVICE_WORKER_ERROR_STATE
:
66 case SERVICE_WORKER_ERROR_DISK_CACHE
:
67 case SERVICE_WORKER_ERROR_MAX_VALUE
:
68 // Unexpected, or should have bailed out before calling this, or we don't
69 // have a corresponding blink error code yet.
70 break; // Fall through to NOTREACHED().
72 NOTREACHED() << "Got unexpected error code: "
73 << status
<< " " << ServiceWorkerStatusToString(status
);
76 } // namespace content