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 <map> | 10 #include <map> |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 response_is_in_cache_storage_ = response.is_in_cache_storage; | 672 response_is_in_cache_storage_ = response.is_in_cache_storage; |
| 673 response_cache_storage_cache_name_ = response.cache_storage_cache_name; | 673 response_cache_storage_cache_name_ = response.cache_storage_cache_name; |
| 674 } | 674 } |
| 675 | 675 |
| 676 void ServiceWorkerURLRequestJob::CreateResponseHeader( | 676 void ServiceWorkerURLRequestJob::CreateResponseHeader( |
| 677 int status_code, | 677 int status_code, |
| 678 const std::string& status_text, | 678 const std::string& status_text, |
| 679 const ServiceWorkerHeaderMap& headers) { | 679 const ServiceWorkerHeaderMap& headers) { |
| 680 // TODO(kinuko): If the response has an identifier to on-disk cache entry, | 680 // TODO(kinuko): If the response has an identifier to on-disk cache entry, |
| 681 // pull response header from the disk. | 681 // pull response header from the disk. |
| 682 std::string status_line( | 682 std::string buf(base::StringPrintf("HTTP/1.1 %d %s\r\n", status_code, |
| 683 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); | 683 status_text.c_str())); |
| 684 status_line.push_back('\0'); | 684 for (auto it = headers.begin(); it != headers.end(); ++it) { |
|
xunjieli
2017/02/14 17:09:58
nit:
for (const auto& item : headers) {
falken
2017/02/15 00:39:39
Done.
| |
| 685 http_response_headers_ = new net::HttpResponseHeaders(status_line); | 685 buf.append(it->first); |
| 686 for (ServiceWorkerHeaderMap::const_iterator it = headers.begin(); | 686 buf.append(": "); |
| 687 it != headers.end(); | 687 buf.append(it->second); |
| 688 ++it) { | 688 buf.append("\r\n"); |
| 689 std::string header; | |
| 690 header.reserve(it->first.size() + 2 + it->second.size()); | |
| 691 header.append(it->first); | |
| 692 header.append(": "); | |
| 693 header.append(it->second); | |
| 694 http_response_headers_->AddHeader(header); | |
| 695 } | 689 } |
| 690 buf.append("\r\n"); | |
| 691 http_response_headers_ = new net::HttpResponseHeaders( | |
| 692 net::HttpUtil::AssembleRawHeaders(buf.c_str(), buf.size())); | |
| 696 } | 693 } |
| 697 | 694 |
| 698 void ServiceWorkerURLRequestJob::CommitResponseHeader() { | 695 void ServiceWorkerURLRequestJob::CommitResponseHeader() { |
| 699 if (!http_response_info_) | 696 if (!http_response_info_) |
| 700 http_response_info_.reset(new net::HttpResponseInfo()); | 697 http_response_info_.reset(new net::HttpResponseInfo()); |
| 701 http_response_info_->headers.swap(http_response_headers_); | 698 http_response_info_->headers.swap(http_response_headers_); |
| 702 http_response_info_->vary_data = net::HttpVaryData(); | 699 http_response_info_->vary_data = net::HttpVaryData(); |
| 703 http_response_info_->metadata = | 700 http_response_info_->metadata = |
| 704 blob_reader_ ? blob_reader_->response_metadata() : nullptr; | 701 blob_reader_ ? blob_reader_->response_metadata() : nullptr; |
| 705 NotifyHeadersComplete(); | 702 NotifyHeadersComplete(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 DCHECK(!reported_navigation_preload_metrics_); | 904 DCHECK(!reported_navigation_preload_metrics_); |
| 908 reported_navigation_preload_metrics_ = true; | 905 reported_navigation_preload_metrics_ = true; |
| 909 | 906 |
| 910 ServiceWorkerMetrics::RecordNavigationPreloadResponse( | 907 ServiceWorkerMetrics::RecordNavigationPreloadResponse( |
| 911 worker_ready_time_ - worker_start_time_, | 908 worker_ready_time_ - worker_start_time_, |
| 912 navigation_preload_response_time_ - worker_start_time_, | 909 navigation_preload_response_time_ - worker_start_time_, |
| 913 initial_worker_status_, worker_start_situation_); | 910 initial_worker_status_, worker_start_situation_); |
| 914 } | 911 } |
| 915 | 912 |
| 916 } // namespace content | 913 } // namespace content |
| OLD | NEW |