Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | |
| 13 #include <string> | 12 #include <string> |
| 14 #include <utility> | 13 #include <utility> |
| 15 #include <vector> | 14 #include <vector> |
| 16 | 15 |
| 17 #include "base/bind.h" | 16 #include "base/bind.h" |
| 18 #include "base/guid.h" | 17 #include "base/guid.h" |
| 19 #include "base/location.h" | 18 #include "base/location.h" |
| 20 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 21 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 // written correctly, it may be null. | 750 // written correctly, it may be null. |
| 752 // TODO(horo): Change this line to DCHECK when crbug.com/485900 is fixed. | 751 // TODO(horo): Change this line to DCHECK when crbug.com/485900 is fixed. |
| 753 http_response_info_.reset( | 752 http_response_info_.reset( |
| 754 new net::HttpResponseInfo(*main_script_http_info)); | 753 new net::HttpResponseInfo(*main_script_http_info)); |
| 755 } | 754 } |
| 756 | 755 |
| 757 // Set up a request for reading the stream. | 756 // Set up a request for reading the stream. |
| 758 if (response.stream_url.is_valid()) { | 757 if (response.stream_url.is_valid()) { |
| 759 DCHECK(response.blob_uuid.empty()); | 758 DCHECK(response.blob_uuid.empty()); |
| 760 SetResponseBodyType(STREAM); | 759 SetResponseBodyType(STREAM); |
| 760 SetResponse(response); | |
| 761 streaming_version_ = version; | 761 streaming_version_ = version; |
| 762 streaming_version_->AddStreamingURLRequestJob(this); | 762 streaming_version_->AddStreamingURLRequestJob(this); |
| 763 response_url_ = response.url; | |
| 764 service_worker_response_type_ = response.response_type; | |
| 765 cors_exposed_header_names_ = response.cors_exposed_header_names; | |
| 766 response_time_ = response.response_time; | |
| 767 CreateResponseHeader( | |
| 768 response.status_code, response.status_text, response.headers); | |
| 769 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); | |
| 770 StreamContext* stream_context = | 763 StreamContext* stream_context = |
| 771 GetStreamContextForResourceContext(resource_context_); | 764 GetStreamContextForResourceContext(resource_context_); |
| 772 stream_ = | 765 stream_ = |
| 773 stream_context->registry()->GetStream(response.stream_url); | 766 stream_context->registry()->GetStream(response.stream_url); |
| 774 if (!stream_.get()) { | 767 if (!stream_.get()) { |
| 775 waiting_stream_url_ = response.stream_url; | 768 waiting_stream_url_ = response.stream_url; |
| 776 // Wait for StreamHostMsg_StartBuilding message from the ServiceWorker. | 769 // Wait for StreamHostMsg_StartBuilding message from the ServiceWorker. |
| 777 stream_context->registry()->SetRegisterObserver(waiting_stream_url_, | 770 stream_context->registry()->SetRegisterObserver(waiting_stream_url_, |
| 778 this); | 771 this); |
| 779 return; | 772 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 792 // The renderer gave us a bad blob UUID. | 785 // The renderer gave us a bad blob UUID. |
| 793 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_BLOB); | 786 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_ERROR_BAD_BLOB); |
| 794 DeliverErrorResponse(); | 787 DeliverErrorResponse(); |
| 795 return; | 788 return; |
| 796 } | 789 } |
| 797 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( | 790 blob_request_ = storage::BlobProtocolHandler::CreateBlobRequest( |
| 798 std::move(blob_data_handle), request()->context(), this); | 791 std::move(blob_data_handle), request()->context(), this); |
| 799 blob_request_->Start(); | 792 blob_request_->Start(); |
| 800 } | 793 } |
| 801 | 794 |
| 802 response_url_ = response.url; | 795 SetResponse(response); |
| 803 service_worker_response_type_ = response.response_type; | 796 |
| 804 response_time_ = response.response_time; | |
| 805 response_is_in_cache_storage_ = response.is_in_cache_storage; | |
| 806 response_cache_storage_cache_name_ = response.cache_storage_cache_name; | |
| 807 cors_exposed_header_names_ = response.cors_exposed_header_names; | |
| 808 CreateResponseHeader( | |
| 809 response.status_code, response.status_text, response.headers); | |
| 810 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); | |
| 811 if (!blob_request_) { | 797 if (!blob_request_) { |
| 812 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_HEADERS_ONLY_RESPONSE); | 798 RecordResult(ServiceWorkerMetrics::REQUEST_JOB_HEADERS_ONLY_RESPONSE); |
| 813 CommitResponseHeader(); | 799 CommitResponseHeader(); |
| 814 } | 800 } |
| 815 } | 801 } |
| 816 | 802 |
| 803 void ServiceWorkerURLRequestJob::SetResponse( | |
| 804 const ServiceWorkerResponse& response) { | |
| 805 response_url_ = response.url; | |
| 806 service_worker_response_type_ = response.response_type; | |
| 807 cors_exposed_header_names_ = response.cors_exposed_header_names; | |
| 808 response_time_ = response.response_time; | |
| 809 CreateResponseHeader(response.status_code, response.status_text, | |
| 810 response.headers); | |
| 811 load_timing_info_.receive_headers_end = base::TimeTicks::Now(); | |
| 812 | |
| 813 response_is_in_cache_storage_ = response.is_in_cache_storage; | |
| 814 response_cache_storage_cache_name_ = response.cache_storage_cache_name; | |
|
falken
2016/08/30 07:06:17
Previously these cache_storage members were only s
| |
| 815 } | |
| 816 | |
| 817 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 817 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
| 818 int status_code, | 818 int status_code, |
| 819 const std::string& status_text, | 819 const std::string& status_text, |
| 820 const ServiceWorkerHeaderMap& headers) { | 820 const ServiceWorkerHeaderMap& headers) { |
| 821 // TODO(kinuko): If the response has an identifier to on-disk cache entry, | 821 // TODO(kinuko): If the response has an identifier to on-disk cache entry, |
| 822 // pull response header from the disk. | 822 // pull response header from the disk. |
| 823 std::string status_line( | 823 std::string status_line( |
| 824 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); | 824 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); |
| 825 status_line.push_back('\0'); | 825 status_line.push_back('\0'); |
| 826 http_response_headers_ = new net::HttpResponseHeaders(status_line); | 826 http_response_headers_ = new net::HttpResponseHeaders(status_line); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), | 1039 CreateFetchRequest(), active_worker, resource_type_, request()->net_log(), |
| 1040 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, | 1040 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, |
| 1041 weak_factory_.GetWeakPtr(), active_worker), | 1041 weak_factory_.GetWeakPtr(), active_worker), |
| 1042 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 1042 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |
| 1043 weak_factory_.GetWeakPtr()))); | 1043 weak_factory_.GetWeakPtr()))); |
| 1044 worker_start_time_ = base::TimeTicks::Now(); | 1044 worker_start_time_ = base::TimeTicks::Now(); |
| 1045 fetch_dispatcher_->Run(); | 1045 fetch_dispatcher_->Run(); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 } // namespace content | 1048 } // namespace content |
| OLD | NEW |