| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/download_resource_handler.h" | 5 #include "chrome/browser/renderer_host/download_resource_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 *buf = read_buffer_.get(); | 178 *buf = read_buffer_.get(); |
| 179 return true; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Pass the buffer to the download file writer. | 182 // Pass the buffer to the download file writer. |
| 183 bool DownloadResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { | 183 bool DownloadResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { |
| 184 if (!*bytes_read) | 184 if (!*bytes_read) |
| 185 return true; | 185 return true; |
| 186 DCHECK(read_buffer_); | 186 DCHECK(read_buffer_); |
| 187 AutoLock auto_lock(buffer_->lock); | 187 base::AutoLock auto_lock(buffer_->lock); |
| 188 bool need_update = buffer_->contents.empty(); | 188 bool need_update = buffer_->contents.empty(); |
| 189 | 189 |
| 190 // We are passing ownership of this buffer to the download file manager. | 190 // We are passing ownership of this buffer to the download file manager. |
| 191 net::IOBuffer* buffer = NULL; | 191 net::IOBuffer* buffer = NULL; |
| 192 read_buffer_.swap(&buffer); | 192 read_buffer_.swap(&buffer); |
| 193 buffer_->contents.push_back(std::make_pair(buffer, *bytes_read)); | 193 buffer_->contents.push_back(std::make_pair(buffer, *bytes_read)); |
| 194 if (need_update) { | 194 if (need_update) { |
| 195 BrowserThread::PostTask( | 195 BrowserThread::PostTask( |
| 196 BrowserThread::FILE, FROM_HERE, | 196 BrowserThread::FILE, FROM_HERE, |
| 197 NewRunnableMethod(download_file_manager_, | 197 NewRunnableMethod(download_file_manager_, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 const std::string& content_disposition) { | 256 const std::string& content_disposition) { |
| 257 content_disposition_ = content_disposition; | 257 content_disposition_ = content_disposition; |
| 258 } | 258 } |
| 259 | 259 |
| 260 void DownloadResourceHandler::CheckWriteProgress() { | 260 void DownloadResourceHandler::CheckWriteProgress() { |
| 261 if (!buffer_) | 261 if (!buffer_) |
| 262 return; // The download completed while we were waiting to run. | 262 return; // The download completed while we were waiting to run. |
| 263 | 263 |
| 264 size_t contents_size; | 264 size_t contents_size; |
| 265 { | 265 { |
| 266 AutoLock lock(buffer_->lock); | 266 base::AutoLock lock(buffer_->lock); |
| 267 contents_size = buffer_->contents.size(); | 267 contents_size = buffer_->contents.size(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool should_pause = contents_size > kLoadsToWrite; | 270 bool should_pause = contents_size > kLoadsToWrite; |
| 271 | 271 |
| 272 // We'll come back later and see if it's okay to unpause the request. | 272 // We'll come back later and see if it's okay to unpause the request. |
| 273 if (should_pause) | 273 if (should_pause) |
| 274 StartPauseTimer(); | 274 StartPauseTimer(); |
| 275 | 275 |
| 276 if (is_paused_ != should_pause) { | 276 if (is_paused_ != should_pause) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 307 render_view_id_, | 307 render_view_id_, |
| 308 save_info_.file_path.value().c_str()); | 308 save_info_.file_path.value().c_str()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void DownloadResourceHandler::UpdateDownloadUrlCheckStats( | 311 void DownloadResourceHandler::UpdateDownloadUrlCheckStats( |
| 312 SBStatsType stat_type) { | 312 SBStatsType stat_type) { |
| 313 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadUrlChecks", | 313 UMA_HISTOGRAM_ENUMERATION("SB2.DownloadUrlChecks", |
| 314 stat_type, | 314 stat_type, |
| 315 DOWNLOAD_URL_CHECKS_MAX); | 315 DOWNLOAD_URL_CHECKS_MAX); |
| 316 } | 316 } |
| OLD | NEW |