| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/automation/url_request_slow_download_job.h" | 5 #include "chrome/browser/automation/url_request_slow_download_job.h" | 
| 6 | 6 | 
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" | 
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" | 
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" | 
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" | 
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 131   } | 131   } | 
| 132 } | 132 } | 
| 133 | 133 | 
| 134 // Public virtual version. | 134 // Public virtual version. | 
| 135 void URLRequestSlowDownloadJob::GetResponseInfo(net::HttpResponseInfo* info) { | 135 void URLRequestSlowDownloadJob::GetResponseInfo(net::HttpResponseInfo* info) { | 
| 136   // Forward to private const version. | 136   // Forward to private const version. | 
| 137   GetResponseInfoConst(info); | 137   GetResponseInfoConst(info); | 
| 138 } | 138 } | 
| 139 | 139 | 
| 140 // Private const version. | 140 // Private const version. | 
| 141 void URLRequestSlowDownloadJob::GetResponseInfoConst(net::HttpResponseInfo* info
     ) const { | 141 void URLRequestSlowDownloadJob::GetResponseInfoConst( | 
|  | 142     net::HttpResponseInfo* info) const { | 
| 142   // Send back mock headers. | 143   // Send back mock headers. | 
| 143   std::string raw_headers; | 144   std::string raw_headers; | 
| 144   if (LowerCaseEqualsASCII(kFinishDownloadUrl, | 145   if (LowerCaseEqualsASCII(kFinishDownloadUrl, | 
| 145                            request_->url().spec().c_str())) { | 146                            request_->url().spec().c_str())) { | 
| 146     raw_headers.append( | 147     raw_headers.append( | 
| 147       "HTTP/1.1 200 OK\n" | 148       "HTTP/1.1 200 OK\n" | 
| 148       "Content-type: text/plain\n"); | 149       "Content-type: text/plain\n"); | 
| 149   } else { | 150   } else { | 
| 150     raw_headers.append( | 151     raw_headers.append( | 
| 151       "HTTP/1.1 200 OK\n" | 152       "HTTP/1.1 200 OK\n" | 
| 152       "Content-type: application/octet-stream\n" | 153       "Content-type: application/octet-stream\n" | 
| 153       "Cache-Control: max-age=0\n"); | 154       "Cache-Control: max-age=0\n"); | 
| 154 | 155 | 
| 155     if (LowerCaseEqualsASCII(kKnownSizeUrl, request_->url().spec().c_str())) { | 156     if (LowerCaseEqualsASCII(kKnownSizeUrl, request_->url().spec().c_str())) { | 
| 156       raw_headers.append(StringPrintf("Content-Length: %d\n", | 157       raw_headers.append(StringPrintf("Content-Length: %d\n", | 
| 157           kFirstDownloadSize + kSecondDownloadSize)); | 158           kFirstDownloadSize + kSecondDownloadSize)); | 
| 158     } | 159     } | 
| 159   } | 160   } | 
| 160 | 161 | 
| 161   // ParseRawHeaders expects \0 to end each header line. | 162   // ParseRawHeaders expects \0 to end each header line. | 
| 162   ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 163   ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); | 
| 163   info->headers = new net::HttpResponseHeaders(raw_headers); | 164   info->headers = new net::HttpResponseHeaders(raw_headers); | 
| 164 } | 165 } | 
| 165 | 166 | 
| 166 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { | 167 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { | 
| 167   net::HttpResponseInfo info; | 168   net::HttpResponseInfo info; | 
| 168   GetResponseInfoConst(&info); | 169   GetResponseInfoConst(&info); | 
| 169   return info.headers && info.headers->GetMimeType(mime_type); | 170   return info.headers && info.headers->GetMimeType(mime_type); | 
| 170 } | 171 } | 
| OLD | NEW | 
|---|