| 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/renderer_host/buffered_resource_handler.h" | 5 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/mime_sniffer.h" | 9 #include "net/base/mime_sniffer.h" |
| 10 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" | 10 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 in_complete); | 257 in_complete); |
| 258 if (bytes_read_) { | 258 if (bytes_read_) { |
| 259 // a Read has already occurred and we need to copy the data into the | 259 // a Read has already occurred and we need to copy the data into the |
| 260 // EventHandler. | 260 // EventHandler. |
| 261 net::IOBuffer* buf = NULL; | 261 net::IOBuffer* buf = NULL; |
| 262 int buf_len = 0; | 262 int buf_len = 0; |
| 263 download_handler->OnWillRead(request_id, &buf, &buf_len, bytes_read_); | 263 download_handler->OnWillRead(request_id, &buf, &buf_len, bytes_read_); |
| 264 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0)); | 264 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0)); |
| 265 memcpy(buf->data(), read_buffer_->data(), bytes_read_); | 265 memcpy(buf->data(), read_buffer_->data(), bytes_read_); |
| 266 } | 266 } |
| 267 // Update the renderer with the response headers which will cause it to | 267 |
| 268 // cancel the request. | 268 // Send the renderer a response that indicates that the request will be |
| 269 // TODO(paulg): Send the renderer a response that indicates that the request | 269 // handled by an external source (the browser's DownloadManager). |
| 270 // will be handled by an external source (the browser). | |
| 271 real_handler_->OnResponseStarted(info->request_id, response_); | 270 real_handler_->OnResponseStarted(info->request_id, response_); |
| 271 URLRequestStatus status(URLRequestStatus::HANDLED_EXTERNALLY, 0); |
| 272 real_handler_->OnResponseCompleted(info->request_id, status); |
| 273 |
| 274 // Ditch the old async handler that talks to the renderer for the new |
| 275 // download handler that talks to the DownloadManager. |
| 272 real_handler_ = download_handler; | 276 real_handler_ = download_handler; |
| 273 } | 277 } |
| 274 return real_handler_->OnResponseStarted(request_id, response_); | 278 return real_handler_->OnResponseStarted(request_id, response_); |
| 275 } | 279 } |
| 276 | 280 |
| 277 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { | 281 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { |
| 278 const int kRequiredLength = 256; | 282 const int kRequiredLength = 256; |
| 279 | 283 |
| 280 return bytes_read >= kRequiredLength; | 284 return bytes_read >= kRequiredLength; |
| 281 } | 285 } |
| OLD | NEW |