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"
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
12 using blink::WebServiceWorkerError
;
14 void GetServiceWorkerRegistrationStatusResponse(
15 ServiceWorkerStatusCode status
,
16 const std::string
& status_message
,
17 blink::WebServiceWorkerError::ErrorType
* error_type
,
18 base::string16
* message
) {
19 *error_type
= WebServiceWorkerError::ErrorTypeUnknown
;
20 if (!status_message
.empty())
21 *message
= base::UTF8ToUTF16(status_message
);
23 *message
= base::ASCIIToUTF16(ServiceWorkerStatusToString(status
));
25 case SERVICE_WORKER_OK
:
26 NOTREACHED() << "Calling this when status == OK is not allowed";
29 case SERVICE_WORKER_ERROR_START_WORKER_FAILED
:
30 case SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED
:
31 *error_type
= WebServiceWorkerError::ErrorTypeInstall
;
34 case SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED
:
35 *error_type
= WebServiceWorkerError::ErrorTypeActivate
;
38 case SERVICE_WORKER_ERROR_NOT_FOUND
:
39 *error_type
= WebServiceWorkerError::ErrorTypeNotFound
;
42 case SERVICE_WORKER_ERROR_NETWORK
:
43 *error_type
= WebServiceWorkerError::ErrorTypeNetwork
;
46 case SERVICE_WORKER_ERROR_SECURITY
:
47 *error_type
= WebServiceWorkerError::ErrorTypeSecurity
;
50 case SERVICE_WORKER_ERROR_ABORT
:
51 case SERVICE_WORKER_ERROR_IPC_FAILED
:
52 case SERVICE_WORKER_ERROR_FAILED
:
53 case SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND
:
54 case SERVICE_WORKER_ERROR_EXISTS
:
55 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED
:
56 // Unexpected, or should have bailed out before calling this, or we don't
57 // have a corresponding blink error code yet.
58 break; // Fall through to NOTREACHED().
60 NOTREACHED() << "Got unexpected error code: "
61 << status
<< " " << ServiceWorkerStatusToString(status
);
64 } // namespace content