OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/appcache/appcache_job.h" | 5 #include "content/browser/appcache/appcache_job.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/appcache/appcache_request.h" | 8 #include "content/browser/appcache/appcache_request.h" |
| 9 #include "content/browser/appcache/appcache_response.h" |
9 #include "content/browser/appcache/appcache_url_loader_job.h" | 10 #include "content/browser/appcache/appcache_url_loader_job.h" |
10 #include "content/browser/appcache/appcache_url_request_job.h" | 11 #include "content/browser/appcache/appcache_url_request_job.h" |
11 | |
12 #include "content/public/common/content_switches.h" | 12 #include "content/public/common/content_switches.h" |
| 13 #include "net/http/http_request_headers.h" |
| 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/http/http_util.h" |
13 | 16 |
14 namespace content { | 17 namespace content { |
15 | 18 |
16 std::unique_ptr<AppCacheJob> AppCacheJob::Create( | 19 std::unique_ptr<AppCacheJob> AppCacheJob::Create( |
17 bool is_main_resource, | 20 bool is_main_resource, |
18 AppCacheHost* host, | 21 AppCacheHost* host, |
19 AppCacheStorage* storage, | 22 AppCacheStorage* storage, |
20 AppCacheRequest* request, | 23 AppCacheRequest* request, |
21 net::NetworkDelegate* network_delegate, | 24 net::NetworkDelegate* network_delegate, |
22 const OnPrepareToRestartCallback& restart_callback) { | 25 const OnPrepareToRestartCallback& restart_callback) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 70 |
68 AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() { | 71 AppCacheURLLoaderJob* AppCacheJob::AsURLLoaderJob() { |
69 return nullptr; | 72 return nullptr; |
70 } | 73 } |
71 | 74 |
72 AppCacheJob::AppCacheJob() | 75 AppCacheJob::AppCacheJob() |
73 : cache_entry_not_found_(false), | 76 : cache_entry_not_found_(false), |
74 delivery_type_(AWAITING_DELIVERY_ORDERS), | 77 delivery_type_(AWAITING_DELIVERY_ORDERS), |
75 weak_factory_(this) {} | 78 weak_factory_(this) {} |
76 | 79 |
| 80 void AppCacheJob::InitializeRangeRequestInfo( |
| 81 const net::HttpRequestHeaders& headers) { |
| 82 std::string value; |
| 83 std::vector<net::HttpByteRange> ranges; |
| 84 if (!headers.GetHeader(net::HttpRequestHeaders::kRange, &value) || |
| 85 !net::HttpUtil::ParseRangeHeader(value, &ranges)) { |
| 86 return; |
| 87 } |
| 88 |
| 89 // If multiple ranges are requested, we play dumb and |
| 90 // return the entire response with 200 OK. |
| 91 if (ranges.size() == 1U) |
| 92 range_requested_ = ranges[0]; |
| 93 } |
| 94 |
| 95 void AppCacheJob::SetupRangeResponse() { |
| 96 DCHECK(is_range_request() && reader_.get() && IsDeliveringAppCacheResponse()); |
| 97 int resource_size = static_cast<int>(info_->response_data_size()); |
| 98 if (resource_size < 0 || !range_requested_.ComputeBounds(resource_size)) { |
| 99 range_requested_ = net::HttpByteRange(); |
| 100 return; |
| 101 } |
| 102 |
| 103 DCHECK(range_requested_.IsValid()); |
| 104 int offset = static_cast<int>(range_requested_.first_byte_position()); |
| 105 int length = static_cast<int>(range_requested_.last_byte_position() - |
| 106 range_requested_.first_byte_position() + 1); |
| 107 |
| 108 // Tell the reader about the range to read. |
| 109 reader_->SetReadRange(offset, length); |
| 110 |
| 111 // Make a copy of the full response headers and fix them up |
| 112 // for the range we'll be returning. |
| 113 range_response_info_.reset( |
| 114 new net::HttpResponseInfo(*info_->http_response_info())); |
| 115 net::HttpResponseHeaders* headers = range_response_info_->headers.get(); |
| 116 headers->UpdateWithNewRange(range_requested_, resource_size, |
| 117 true /* replace status line */); |
| 118 } |
| 119 |
77 } // namespace content | 120 } // namespace content |
OLD | NEW |