| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/net/url_request_slow_download_job.h" | 5 #include "chrome/browser/net/url_request_slow_download_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stringprintf.h" |
| 9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 12 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 14 #include "net/url_request/url_request_filter.h" | 15 #include "net/url_request/url_request_filter.h" |
| 15 | 16 |
| 16 const int kFirstDownloadSize = 1024 * 35; | 17 const int kFirstDownloadSize = 1024 * 35; |
| 17 const int kSecondDownloadSize = 1024 * 10; | 18 const int kSecondDownloadSize = 1024 * 10; |
| 18 | 19 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 raw_headers.append( | 159 raw_headers.append( |
| 159 "HTTP/1.1 200 OK\n" | 160 "HTTP/1.1 200 OK\n" |
| 160 "Content-type: text/plain\n"); | 161 "Content-type: text/plain\n"); |
| 161 } else { | 162 } else { |
| 162 raw_headers.append( | 163 raw_headers.append( |
| 163 "HTTP/1.1 200 OK\n" | 164 "HTTP/1.1 200 OK\n" |
| 164 "Content-type: application/octet-stream\n" | 165 "Content-type: application/octet-stream\n" |
| 165 "Cache-Control: max-age=0\n"); | 166 "Cache-Control: max-age=0\n"); |
| 166 | 167 |
| 167 if (LowerCaseEqualsASCII(kKnownSizeUrl, request_->url().spec().c_str())) { | 168 if (LowerCaseEqualsASCII(kKnownSizeUrl, request_->url().spec().c_str())) { |
| 168 raw_headers.append(StringPrintf("Content-Length: %d\n", | 169 raw_headers.append(base::StringPrintf( |
| 170 "Content-Length: %d\n", |
| 169 kFirstDownloadSize + kSecondDownloadSize)); | 171 kFirstDownloadSize + kSecondDownloadSize)); |
| 170 } | 172 } |
| 171 } | 173 } |
| 172 | 174 |
| 173 // ParseRawHeaders expects \0 to end each header line. | 175 // ParseRawHeaders expects \0 to end each header line. |
| 174 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 176 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); |
| 175 info->headers = new net::HttpResponseHeaders(raw_headers); | 177 info->headers = new net::HttpResponseHeaders(raw_headers); |
| 176 } | 178 } |
| 177 | 179 |
| 178 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { | 180 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { |
| 179 net::HttpResponseInfo info; | 181 net::HttpResponseInfo info; |
| 180 GetResponseInfoConst(&info); | 182 GetResponseInfoConst(&info); |
| 181 return info.headers && info.headers->GetMimeType(mime_type); | 183 return info.headers && info.headers->GetMimeType(mime_type); |
| 182 } | 184 } |
| OLD | NEW |