OLD | NEW |
---|---|
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 Loading... | |
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 // We can't log if there's no request; fallthrough. | |
84 case m::REQUEST_JOB_ERROR_NO_REQUEST: | |
85 // Obsolete types; fallthrough. | |
86 case m::REQUEST_JOB_ERROR_DESTROYED: | |
87 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: | |
88 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: | |
89 // Invalid type. | |
90 case m::NUM_REQUEST_JOB_RESULT_TYPES: | |
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 Loading... | |
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 Loading... | |
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. | |
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 if (request()) { | |
falken
2015/07/10 01:10:18
Added this check: it looks conceivable for request
| |
418 request()->net_log().AddEvent( | |
419 net::NetLog::TYPE_SERVICE_WORKER_START_REQUEST); | |
420 } | |
421 | |
375 switch (response_type_) { | 422 switch (response_type_) { |
376 case NOT_DETERMINED: | 423 case NOT_DETERMINED: |
377 NOTREACHED(); | 424 NOTREACHED(); |
378 return; | 425 return; |
379 | 426 |
380 case FALLBACK_TO_NETWORK: | 427 case FALLBACK_TO_NETWORK: |
381 // Restart the request to create a new job. Our request handler will | 428 // 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 | 429 // return nullptr, and the default job (which will hit network) should be |
383 // created. | 430 // created. |
384 NotifyRestartRequired(); | 431 NotifyRestartRequired(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
715 ServiceWorkerMetrics::URLRequestJobResult result) { | 762 ServiceWorkerMetrics::URLRequestJobResult result) { |
716 // It violates style guidelines to handle a NOTREACHED() failure but if there | 763 // 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. | 764 // is a bug don't let it corrupt UMA results by double-counting. |
718 if (!ShouldRecordResult()) { | 765 if (!ShouldRecordResult()) { |
719 NOTREACHED(); | 766 NOTREACHED(); |
720 return; | 767 return; |
721 } | 768 } |
722 did_record_result_ = true; | 769 did_record_result_ = true; |
723 ServiceWorkerMetrics::RecordURLRequestJobResult(is_main_resource_load_, | 770 ServiceWorkerMetrics::RecordURLRequestJobResult(is_main_resource_load_, |
724 result); | 771 result); |
772 if (request()) | |
773 request()->net_log().AddEvent(RequestJobResultToNetEventType(result)); | |
725 } | 774 } |
726 | 775 |
727 void ServiceWorkerURLRequestJob::RecordStatusZeroResponseError( | 776 void ServiceWorkerURLRequestJob::RecordStatusZeroResponseError( |
728 blink::WebServiceWorkerResponseError error) { | 777 blink::WebServiceWorkerResponseError error) { |
729 // It violates style guidelines to handle a NOTREACHED() failure but if there | 778 // 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. | 779 // is a bug don't let it corrupt UMA results by double-counting. |
731 if (!ShouldRecordResult()) { | 780 if (!ShouldRecordResult()) { |
732 NOTREACHED(); | 781 NOTREACHED(); |
733 return; | 782 return; |
734 } | 783 } |
(...skipping 14 matching lines...) Expand all Loading... | |
749 } | 798 } |
750 if (!waiting_stream_url_.is_empty()) { | 799 if (!waiting_stream_url_.is_empty()) { |
751 StreamRegistry* stream_registry = | 800 StreamRegistry* stream_registry = |
752 GetStreamContextForResourceContext(resource_context_)->registry(); | 801 GetStreamContextForResourceContext(resource_context_)->registry(); |
753 stream_registry->RemoveRegisterObserver(waiting_stream_url_); | 802 stream_registry->RemoveRegisterObserver(waiting_stream_url_); |
754 stream_registry->AbortPendingStream(waiting_stream_url_); | 803 stream_registry->AbortPendingStream(waiting_stream_url_); |
755 } | 804 } |
756 } | 805 } |
757 | 806 |
758 } // namespace content | 807 } // namespace content |
OLD | NEW |