diff options
author | Matt Falkenhagen <falken@chromium.org> | 2015-07-12 22:10:27 +0900 |
---|---|---|
committer | Matt Falkenhagen <falken@chromium.org> | 2015-07-12 13:11:29 +0000 |
commit | 937db044a289a6adfc33ed0a2e05869e3d7580ab (patch) | |
tree | ef9f3fd0e23b79f046d0a4f2c62537ac0bd4407c | |
parent | 9259b9510ddc204444cbabda1fed500e2b827826 (diff) | |
download | chromium_src-937db044a289a6adfc33ed0a2e05869e3d7580ab.zip chromium_src-937db044a289a6adfc33ed0a2e05869e3d7580ab.tar.gz chromium_src-937db044a289a6adfc33ed0a2e05869e3d7580ab.tar.bz2 |
[M44] Add net logging for ServiceWorkerURLRequestJob.
This patch adds net log types for each ServiceWorkerURLRequestJob result type
(already used for UMA), and logs the result as a net event. This may help
debugging user issues when something goes wrong with Service Worker.
It also folds DESTROYED and KILLED UMAs into just KILLED,
as it turned out we got no DESTROYED UMAs.
BUG=499143
Review URL: https://codereview.chromium.org/1229733003
Cr-Commit-Position: refs/heads/master@{#338207}
(cherry picked from commit adacabbf290abae3e862d21b8549fd3a490e2303)
TBR=mmenke
Review URL: https://codereview.chromium.org/1236763002 .
Cr-Commit-Position: refs/branch-heads/2403@{#488}
Cr-Branched-From: f54b8097a9c45ed4ad308133d49f05325d6c5070-refs/heads/master@{#330231}
-rw-r--r-- | content/browser/service_worker/service_worker_url_request_job.cc | 79 | ||||
-rw-r--r-- | net/log/net_log_event_type_list.h | 69 |
2 files changed, 133 insertions, 15 deletions
diff --git a/content/browser/service_worker/service_worker_url_request_job.cc b/content/browser/service_worker/service_worker_url_request_job.cc index 3a94d85..607c9b0 100644 --- a/content/browser/service_worker/service_worker_url_request_job.cc +++ b/content/browser/service_worker/service_worker_url_request_job.cc @@ -30,6 +30,7 @@ #include "net/http/http_response_headers.h" #include "net/http/http_response_info.h" #include "net/http/http_util.h" +#include "net/log/net_log.h" #include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" @@ -38,6 +39,59 @@ namespace content { +namespace { + +net::NetLog::EventType RequestJobResultToNetEventType( + ServiceWorkerMetrics::URLRequestJobResult result) { + using n = net::NetLog; + using m = ServiceWorkerMetrics; + switch (result) { + case m::REQUEST_JOB_FALLBACK_RESPONSE: + return n::TYPE_SERVICE_WORKER_FALLBACK_RESPONSE; + case m::REQUEST_JOB_FALLBACK_FOR_CORS: + return n::TYPE_SERVICE_WORKER_FALLBACK_FOR_CORS; + case m::REQUEST_JOB_HEADERS_ONLY_RESPONSE: + return n::TYPE_SERVICE_WORKER_HEADERS_ONLY_RESPONSE; + case m::REQUEST_JOB_STREAM_RESPONSE: + return n::TYPE_SERVICE_WORKER_STREAM_RESPONSE; + case m::REQUEST_JOB_BLOB_RESPONSE: + return n::TYPE_SERVICE_WORKER_BLOB_RESPONSE; + case m::REQUEST_JOB_ERROR_RESPONSE_STATUS_ZERO: + return n::TYPE_SERVICE_WORKER_ERROR_RESPONSE_STATUS_ZERO; + case m::REQUEST_JOB_ERROR_BAD_BLOB: + return n::TYPE_SERVICE_WORKER_ERROR_BAD_BLOB; + case m::REQUEST_JOB_ERROR_NO_PROVIDER_HOST: + return n::TYPE_SERVICE_WORKER_ERROR_NO_PROVIDER_HOST; + case m::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION: + return n::TYPE_SERVICE_WORKER_ERROR_NO_ACTIVE_VERSION; + case m::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH: + return n::TYPE_SERVICE_WORKER_ERROR_FETCH_EVENT_DISPATCH; + case m::REQUEST_JOB_ERROR_BLOB_READ: + return n::TYPE_SERVICE_WORKER_ERROR_BLOB_READ; + case m::REQUEST_JOB_ERROR_STREAM_ABORTED: + return n::TYPE_SERVICE_WORKER_ERROR_STREAM_ABORTED; + case m::REQUEST_JOB_ERROR_KILLED: + return n::TYPE_SERVICE_WORKER_ERROR_KILLED; + case m::REQUEST_JOB_ERROR_KILLED_WITH_BLOB: + return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_BLOB; + case m::REQUEST_JOB_ERROR_KILLED_WITH_STREAM: + return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_STREAM; + // We can't log if there's no request; fallthrough. + case m::REQUEST_JOB_ERROR_NO_REQUEST: + // Obsolete types; fallthrough. + case m::REQUEST_JOB_ERROR_DESTROYED: + case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: + case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: + // Invalid type. + case m::NUM_REQUEST_JOB_RESULT_TYPES: + NOTREACHED() << result; + } + NOTREACHED() << result; + return n::TYPE_FAILED; +} + +} // namespace + ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( net::URLRequest* request, net::NetworkDelegate* network_delegate, @@ -86,16 +140,6 @@ void ServiceWorkerURLRequestJob::Start() { } void ServiceWorkerURLRequestJob::Kill() { - if (ShouldRecordResult()) { - ServiceWorkerMetrics::URLRequestJobResult result = - ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; - if (response_body_type_ == STREAM) - result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; - else if (response_body_type_ == BLOB) - result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; - RecordResult(result); - } - net::URLRequestJob::Kill(); ClearStream(); fetch_dispatcher_.reset(); @@ -353,14 +397,12 @@ ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { if (!ShouldRecordResult()) return; - // TODO(falken): If we don't see many of these, we might merge KILLED and - // DESTROYED results together. ServiceWorkerMetrics::URLRequestJobResult result = - ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED; + ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; if (response_body_type_ == STREAM) - result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM; + result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; else if (response_body_type_ == BLOB) - result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB; + result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; RecordResult(result); } @@ -375,6 +417,11 @@ void ServiceWorkerURLRequestJob::MaybeStartRequest() { } void ServiceWorkerURLRequestJob::StartRequest() { + if (request()) { + request()->net_log().AddEvent( + net::NetLog::TYPE_SERVICE_WORKER_START_REQUEST); + } + switch (response_type_) { case NOT_DETERMINED: NOTREACHED(); @@ -726,6 +773,8 @@ void ServiceWorkerURLRequestJob::RecordResult( did_record_result_ = true; ServiceWorkerMetrics::RecordURLRequestJobResult(is_main_resource_load_, result); + if (request()) + request()->net_log().AddEvent(RequestJobResultToNetEventType(result)); } void ServiceWorkerURLRequestJob::ClearStream() { diff --git a/net/log/net_log_event_type_list.h b/net/log/net_log_event_type_list.h index 60f42a3..c582a25 100644 --- a/net/log/net_log_event_type_list.h +++ b/net/log/net_log_event_type_list.h @@ -1795,6 +1795,75 @@ EVENT_TYPE(APPCACHE_DELIVERING_ERROR_RESPONSE) EVENT_TYPE(APPCACHE_DELIVERING_EXECUTABLE_RESPONSE) // ------------------------------------------------------------------------ +// Service Worker +// ------------------------------------------------------------------------ +// This event is emitted when Service Worker starts to handle a request. +EVENT_TYPE(SERVICE_WORKER_START_REQUEST) + +// This event is emitted when Service Worker results in a fallback to network +// response. +EVENT_TYPE(SERVICE_WORKER_FALLBACK_RESPONSE) + +// This event is emitted when Service Worker results in a fallback to network +// response, and asks the renderer rather than the browser to do the fallback +// due to CORS. +EVENT_TYPE(SERVICE_WORKER_FALLBACK_FOR_CORS) + +// This event is emitted when Service Worker responds with a headers-only +// response. +EVENT_TYPE(SERVICE_WORKER_HEADERS_ONLY_RESPONSE) + +// This event is emitted when Service Worker responds with a stream. +EVENT_TYPE(SERVICE_WORKER_STREAM_RESPONSE) + +// This event is emitted when Service Worker responds with a blob. +EVENT_TYPE(SERVICE_WORKER_BLOB_RESPONSE) + +// This event is emitted when Service Worker instructs the browser +// to respond with a network error. +EVENT_TYPE(SERVICE_WORKER_ERROR_RESPONSE_STATUS_ZERO) + +// This event is emitted when Service Worker attempts to respond with +// a blob, but it was not readable. +EVENT_TYPE(SERVICE_WORKER_ERROR_BAD_BLOB) + +// This event is emitted when Service Worker fails to respond because +// the provider host was null. +EVENT_TYPE(SERVICE_WORKER_ERROR_NO_PROVIDER_HOST) + +// This event is emitted when Service Worker fails to respond because +// the registration had no active version. +EVENT_TYPE(SERVICE_WORKER_ERROR_NO_ACTIVE_VERSION) + +// This event is emitted when Service Worker fails to respond because +// the underlying request was detached. +EVENT_TYPE(SERVICE_WORKER_ERROR_NO_REQUEST) + +// This event is emitted when Service Worker fails to respond because +// the fetch event could not be dispatched to the worker. +EVENT_TYPE(SERVICE_WORKER_ERROR_FETCH_EVENT_DISPATCH) + +// This event is emitted when Service Worker fails to respond because +// of an error when reading the blob response. +EVENT_TYPE(SERVICE_WORKER_ERROR_BLOB_READ) + +// This event is emitted when Service Worker fails to respond because +// of an error when reading the stream response. +EVENT_TYPE(SERVICE_WORKER_ERROR_STREAM_ABORTED) + +// This event is emitted when Service Worker is destroyed before it +// responds. +EVENT_TYPE(SERVICE_WORKER_ERROR_KILLED) + +// This event is emitted when Service Worker is destroyed before it +// finishes responding with a blob. +EVENT_TYPE(SERVICE_WORKER_ERROR_KILLED_WITH_BLOB) + +// This event is emitted when Service Worker is destroyed before it +// finishes responding with a stream. +EVENT_TYPE(SERVICE_WORKER_ERROR_KILLED_WITH_STREAM) + +// ------------------------------------------------------------------------ // Global events // ------------------------------------------------------------------------ // These are events which are not grouped by source id, as they have no |