Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: content/browser/service_worker/service_worker_url_request_job.cc

Issue 1229733003: Add net logging for ServiceWorkerURLRequestJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/log/net_log_event_type_list.h » ('j') | net/log/net_log_event_type_list.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_url_request_job.h" 5 #include "content/browser/service_worker/service_worker_url_request_job.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "content/public/browser/blob_handle.h" 27 #include "content/public/browser/blob_handle.h"
28 #include "content/public/browser/resource_request_info.h" 28 #include "content/public/browser/resource_request_info.h"
29 #include "content/public/browser/service_worker_context.h" 29 #include "content/public/browser/service_worker_context.h"
30 #include "content/public/common/referrer.h" 30 #include "content/public/common/referrer.h"
31 #include "content/public/common/resource_response_info.h" 31 #include "content/public/common/resource_response_info.h"
32 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 #include "net/http/http_request_headers.h" 33 #include "net/http/http_request_headers.h"
34 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
35 #include "net/http/http_response_info.h" 35 #include "net/http/http_response_info.h"
36 #include "net/http/http_util.h" 36 #include "net/http/http_util.h"
37 #include "net/log/net_log.h"
37 #include "storage/browser/blob/blob_data_builder.h" 38 #include "storage/browser/blob/blob_data_builder.h"
38 #include "storage/browser/blob/blob_data_handle.h" 39 #include "storage/browser/blob/blob_data_handle.h"
39 #include "storage/browser/blob/blob_storage_context.h" 40 #include "storage/browser/blob/blob_storage_context.h"
40 #include "storage/browser/blob/blob_url_request_job_factory.h" 41 #include "storage/browser/blob/blob_url_request_job_factory.h"
41 #include "ui/base/page_transition_types.h" 42 #include "ui/base/page_transition_types.h"
42 43
43 namespace content { 44 namespace content {
44 45
46 namespace {
47
48 net::NetLog::EventType RequestJobResultToNetEventType(
49 ServiceWorkerMetrics::URLRequestJobResult result) {
50 using n = net::NetLog;
51 using m = ServiceWorkerMetrics;
52 switch (result) {
53 case m::REQUEST_JOB_FALLBACK_RESPONSE:
54 return n::TYPE_SERVICE_WORKER_FALLBACK_RESPONSE;
55 case m::REQUEST_JOB_FALLBACK_FOR_CORS:
56 return n::TYPE_SERVICE_WORKER_FALLBACK_FOR_CORS;
57 case m::REQUEST_JOB_HEADERS_ONLY_RESPONSE:
58 return n::TYPE_SERVICE_WORKER_HEADERS_ONLY_RESPONSE;
59 case m::REQUEST_JOB_STREAM_RESPONSE:
60 return n::TYPE_SERVICE_WORKER_STREAM_RESPONSE;
61 case m::REQUEST_JOB_BLOB_RESPONSE:
62 return n::TYPE_SERVICE_WORKER_BLOB_RESPONSE;
63 case m::REQUEST_JOB_ERROR_RESPONSE_STATUS_ZERO:
64 return n::TYPE_SERVICE_WORKER_ERROR_RESPONSE_STATUS_ZERO;
65 case m::REQUEST_JOB_ERROR_BAD_BLOB:
66 return n::TYPE_SERVICE_WORKER_ERROR_BAD_BLOB;
67 case m::REQUEST_JOB_ERROR_NO_PROVIDER_HOST:
68 return n::TYPE_SERVICE_WORKER_ERROR_NO_PROVIDER_HOST;
69 case m::REQUEST_JOB_ERROR_NO_ACTIVE_VERSION:
70 return n::TYPE_SERVICE_WORKER_ERROR_NO_ACTIVE_VERSION;
71 case m::REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH:
72 return n::TYPE_SERVICE_WORKER_ERROR_FETCH_EVENT_DISPATCH;
73 case m::REQUEST_JOB_ERROR_BLOB_READ:
74 return n::TYPE_SERVICE_WORKER_ERROR_BLOB_READ;
75 case m::REQUEST_JOB_ERROR_STREAM_ABORTED:
76 return n::TYPE_SERVICE_WORKER_ERROR_STREAM_ABORTED;
77 case m::REQUEST_JOB_ERROR_KILLED:
78 return n::TYPE_SERVICE_WORKER_ERROR_KILLED;
79 case m::REQUEST_JOB_ERROR_KILLED_WITH_BLOB:
80 return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_BLOB;
81 case m::REQUEST_JOB_ERROR_KILLED_WITH_STREAM:
82 return n::TYPE_SERVICE_WORKER_ERROR_KILLED_WITH_STREAM;
83 case m::REQUEST_JOB_ERROR_NO_REQUEST:
84 // Fallthrough: we can't log if there's no request.
85 case m::REQUEST_JOB_ERROR_DESTROYED:
86 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB:
87 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM:
88 // Fallthrough: obsolete types.
89 case m::NUM_REQUEST_JOB_RESULT_TYPES:
90 // Invalid type.
91 NOTREACHED() << result;
92 }
93 NOTREACHED() << result;
94 return n::TYPE_FAILED;
95 }
96
97 } // namespace
98
45 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( 99 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob(
46 net::URLRequest* request, 100 net::URLRequest* request,
47 net::NetworkDelegate* network_delegate, 101 net::NetworkDelegate* network_delegate,
48 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 102 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
49 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, 103 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
50 const ResourceContext* resource_context, 104 const ResourceContext* resource_context,
51 FetchRequestMode request_mode, 105 FetchRequestMode request_mode,
52 FetchCredentialsMode credentials_mode, 106 FetchCredentialsMode credentials_mode,
53 bool is_main_resource_load, 107 bool is_main_resource_load,
54 RequestContextType request_context_type, 108 RequestContextType request_context_type,
(...skipping 28 matching lines...) Expand all
83 response_type_ = FORWARD_TO_SERVICE_WORKER; 137 response_type_ = FORWARD_TO_SERVICE_WORKER;
84 MaybeStartRequest(); 138 MaybeStartRequest();
85 } 139 }
86 140
87 void ServiceWorkerURLRequestJob::Start() { 141 void ServiceWorkerURLRequestJob::Start() {
88 is_started_ = true; 142 is_started_ = true;
89 MaybeStartRequest(); 143 MaybeStartRequest();
90 } 144 }
91 145
92 void ServiceWorkerURLRequestJob::Kill() { 146 void ServiceWorkerURLRequestJob::Kill() {
93 if (ShouldRecordResult()) {
94 ServiceWorkerMetrics::URLRequestJobResult result =
95 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED;
96 if (response_body_type_ == STREAM)
97 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM;
98 else if (response_body_type_ == BLOB)
99 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB;
100 RecordResult(result);
101 }
102
103 net::URLRequestJob::Kill(); 147 net::URLRequestJob::Kill();
104 ClearStream(); 148 ClearStream();
105 fetch_dispatcher_.reset(); 149 fetch_dispatcher_.reset();
106 blob_request_.reset(); 150 blob_request_.reset();
107 weak_factory_.InvalidateWeakPtrs(); 151 weak_factory_.InvalidateWeakPtrs();
108 } 152 }
109 153
110 net::LoadState ServiceWorkerURLRequestJob::GetLoadState() const { 154 net::LoadState ServiceWorkerURLRequestJob::GetLoadState() const {
111 // TODO(kinuko): refine this for better debug. 155 // TODO(kinuko): refine this for better debug.
112 return net::URLRequestJob::GetLoadState(); 156 return net::URLRequestJob::GetLoadState();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 response_info->service_worker_start_time = worker_start_time_; 388 response_info->service_worker_start_time = worker_start_time_;
345 response_info->service_worker_ready_time = worker_ready_time_; 389 response_info->service_worker_ready_time = worker_ready_time_;
346 } 390 }
347 391
348 392
349 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { 393 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() {
350 ClearStream(); 394 ClearStream();
351 395
352 if (!ShouldRecordResult()) 396 if (!ShouldRecordResult())
353 return; 397 return;
354 // TODO(falken): If we don't see many of these, we might merge KILLED and
355 // DESTROYED results together.
kinuko 2015/07/09 13:52:41 So we didn't see many of these?
falken 2015/07/09 14:26:29 Right, there were zero of these.
356 ServiceWorkerMetrics::URLRequestJobResult result = 398 ServiceWorkerMetrics::URLRequestJobResult result =
357 ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED; 399 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED;
358 if (response_body_type_ == STREAM) 400 if (response_body_type_ == STREAM)
359 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM; 401 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM;
360 else if (response_body_type_ == BLOB) 402 else if (response_body_type_ == BLOB)
361 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB; 403 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB;
362 RecordResult(result); 404 RecordResult(result);
363 } 405 }
364 406
365 void ServiceWorkerURLRequestJob::MaybeStartRequest() { 407 void ServiceWorkerURLRequestJob::MaybeStartRequest() {
366 if (is_started_ && response_type_ != NOT_DETERMINED) { 408 if (is_started_ && response_type_ != NOT_DETERMINED) {
367 // Start asynchronously. 409 // Start asynchronously.
368 base::ThreadTaskRunnerHandle::Get()->PostTask( 410 base::ThreadTaskRunnerHandle::Get()->PostTask(
369 FROM_HERE, base::Bind(&ServiceWorkerURLRequestJob::StartRequest, 411 FROM_HERE, base::Bind(&ServiceWorkerURLRequestJob::StartRequest,
370 weak_factory_.GetWeakPtr())); 412 weak_factory_.GetWeakPtr()));
371 } 413 }
372 } 414 }
373 415
374 void ServiceWorkerURLRequestJob::StartRequest() { 416 void ServiceWorkerURLRequestJob::StartRequest() {
417 request()->net_log().AddEvent(net::NetLog::TYPE_SERVICE_WORKER_START_REQUEST);
375 switch (response_type_) { 418 switch (response_type_) {
376 case NOT_DETERMINED: 419 case NOT_DETERMINED:
377 NOTREACHED(); 420 NOTREACHED();
378 return; 421 return;
379 422
380 case FALLBACK_TO_NETWORK: 423 case FALLBACK_TO_NETWORK:
381 // Restart the request to create a new job. Our request handler will 424 // Restart the request to create a new job. Our request handler will
382 // return nullptr, and the default job (which will hit network) should be 425 // return nullptr, and the default job (which will hit network) should be
383 // created. 426 // created.
384 NotifyRestartRequired(); 427 NotifyRestartRequired();
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 ServiceWorkerMetrics::URLRequestJobResult result) { 758 ServiceWorkerMetrics::URLRequestJobResult result) {
716 // It violates style guidelines to handle a NOTREACHED() failure but if there 759 // It violates style guidelines to handle a NOTREACHED() failure but if there
717 // is a bug don't let it corrupt UMA results by double-counting. 760 // is a bug don't let it corrupt UMA results by double-counting.
718 if (!ShouldRecordResult()) { 761 if (!ShouldRecordResult()) {
719 NOTREACHED(); 762 NOTREACHED();
720 return; 763 return;
721 } 764 }
722 did_record_result_ = true; 765 did_record_result_ = true;
723 ServiceWorkerMetrics::RecordURLRequestJobResult(is_main_resource_load_, 766 ServiceWorkerMetrics::RecordURLRequestJobResult(is_main_resource_load_,
724 result); 767 result);
768 if (request())
769 request()->net_log().AddEvent(RequestJobResultToNetEventType(result));
725 } 770 }
726 771
727 void ServiceWorkerURLRequestJob::RecordStatusZeroResponseError( 772 void ServiceWorkerURLRequestJob::RecordStatusZeroResponseError(
728 blink::WebServiceWorkerResponseError error) { 773 blink::WebServiceWorkerResponseError error) {
729 // It violates style guidelines to handle a NOTREACHED() failure but if there 774 // It violates style guidelines to handle a NOTREACHED() failure but if there
730 // is a bug don't let it corrupt UMA results by double-counting. 775 // is a bug don't let it corrupt UMA results by double-counting.
731 if (!ShouldRecordResult()) { 776 if (!ShouldRecordResult()) {
732 NOTREACHED(); 777 NOTREACHED();
733 return; 778 return;
734 } 779 }
(...skipping 14 matching lines...) Expand all
749 } 794 }
750 if (!waiting_stream_url_.is_empty()) { 795 if (!waiting_stream_url_.is_empty()) {
751 StreamRegistry* stream_registry = 796 StreamRegistry* stream_registry =
752 GetStreamContextForResourceContext(resource_context_)->registry(); 797 GetStreamContextForResourceContext(resource_context_)->registry();
753 stream_registry->RemoveRegisterObserver(waiting_stream_url_); 798 stream_registry->RemoveRegisterObserver(waiting_stream_url_);
754 stream_registry->AbortPendingStream(waiting_stream_url_); 799 stream_registry->AbortPendingStream(waiting_stream_url_);
755 } 800 }
756 } 801 }
757 802
758 } // namespace content 803 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | net/log/net_log_event_type_list.h » ('j') | net/log/net_log_event_type_list.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698