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

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

Issue 2690333003: service worker: Optimize response header creation. (Closed)
Patch Set: fix auto Created 3 years, 10 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 | content/browser/service_worker/service_worker_url_request_job_unittest.cc » ('j') | no next file with comments »
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 <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
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
683 base::StringPrintf("HTTP/1.1 %d %s", status_code, status_text.c_str())); 683 // Build a string instead of using HttpResponseHeaders::AddHeader on
684 status_line.push_back('\0'); 684 // each header, since AddHeader has O(n^2) performance.
685 http_response_headers_ = new net::HttpResponseHeaders(status_line); 685 std::string buf(base::StringPrintf("HTTP/1.1 %d %s\r\n", status_code,
686 for (ServiceWorkerHeaderMap::const_iterator it = headers.begin(); 686 status_text.c_str()));
687 it != headers.end(); 687 for (const auto& item : headers) {
688 ++it) { 688 buf.append(item.first);
689 std::string header; 689 buf.append(": ");
690 header.reserve(it->first.size() + 2 + it->second.size()); 690 buf.append(item.second);
691 header.append(it->first); 691 buf.append("\r\n");
692 header.append(": ");
693 header.append(it->second);
694 http_response_headers_->AddHeader(header);
695 } 692 }
693 buf.append("\r\n");
694 http_response_headers_ = new net::HttpResponseHeaders(
695 net::HttpUtil::AssembleRawHeaders(buf.c_str(), buf.size()));
696 } 696 }
697 697
698 void ServiceWorkerURLRequestJob::CommitResponseHeader() { 698 void ServiceWorkerURLRequestJob::CommitResponseHeader() {
699 if (!http_response_info_) 699 if (!http_response_info_)
700 http_response_info_.reset(new net::HttpResponseInfo()); 700 http_response_info_.reset(new net::HttpResponseInfo());
701 http_response_info_->headers.swap(http_response_headers_); 701 http_response_info_->headers.swap(http_response_headers_);
702 http_response_info_->vary_data = net::HttpVaryData(); 702 http_response_info_->vary_data = net::HttpVaryData();
703 http_response_info_->metadata = 703 http_response_info_->metadata =
704 blob_reader_ ? blob_reader_->response_metadata() : nullptr; 704 blob_reader_ ? blob_reader_->response_metadata() : nullptr;
705 NotifyHeadersComplete(); 705 NotifyHeadersComplete();
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 DCHECK(!reported_navigation_preload_metrics_); 907 DCHECK(!reported_navigation_preload_metrics_);
908 reported_navigation_preload_metrics_ = true; 908 reported_navigation_preload_metrics_ = true;
909 909
910 ServiceWorkerMetrics::RecordNavigationPreloadResponse( 910 ServiceWorkerMetrics::RecordNavigationPreloadResponse(
911 worker_ready_time_ - worker_start_time_, 911 worker_ready_time_ - worker_start_time_,
912 navigation_preload_response_time_ - worker_start_time_, 912 navigation_preload_response_time_ - worker_start_time_,
913 initial_worker_status_, worker_start_situation_); 913 initial_worker_status_, worker_start_situation_);
914 } 914 }
915 915
916 } // namespace content 916 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698