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/download/download_file_manager.h" | 5 #include "chrome/browser/download/download_file_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 // We don't forward an update to the UI thread here, since we want to throttle | 185 // We don't forward an update to the UI thread here, since we want to throttle |
186 // the UI update rate via a periodic timer. If the user has cancelled the | 186 // the UI update rate via a periodic timer. If the user has cancelled the |
187 // download (in the UI thread), we may receive a few more updates before the IO | 187 // download (in the UI thread), we may receive a few more updates before the IO |
188 // thread gets the cancel message: we just delete the data since the | 188 // thread gets the cancel message: we just delete the data since the |
189 // DownloadFile has been deleted. | 189 // DownloadFile has been deleted. |
190 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { | 190 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
192 std::vector<DownloadBuffer::Contents> contents; | 192 std::vector<DownloadBuffer::Contents> contents; |
193 { | 193 { |
194 AutoLock auto_lock(buffer->lock); | 194 base::AutoLock auto_lock(buffer->lock); |
195 contents.swap(buffer->contents); | 195 contents.swap(buffer->contents); |
196 } | 196 } |
197 | 197 |
198 DownloadFile* download = GetDownloadFile(id); | 198 DownloadFile* download = GetDownloadFile(id); |
199 for (size_t i = 0; i < contents.size(); ++i) { | 199 for (size_t i = 0; i < contents.size(); ++i) { |
200 net::IOBuffer* data = contents[i].first; | 200 net::IOBuffer* data = contents[i].first; |
201 const int data_len = contents[i].second; | 201 const int data_len = contents[i].second; |
202 if (download) | 202 if (download) |
203 download->AppendDataToFile(data->data(), data_len); | 203 download->AppendDataToFile(data->data(), data_len); |
204 data->Release(); | 204 data->Release(); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 if (!download_manager) { | 369 if (!download_manager) { |
370 download->CancelDownloadRequest(resource_dispatcher_host_); | 370 download->CancelDownloadRequest(resource_dispatcher_host_); |
371 return; | 371 return; |
372 } | 372 } |
373 | 373 |
374 BrowserThread::PostTask( | 374 BrowserThread::PostTask( |
375 BrowserThread::UI, FROM_HERE, | 375 BrowserThread::UI, FROM_HERE, |
376 NewRunnableMethod(download_manager, | 376 NewRunnableMethod(download_manager, |
377 &DownloadManager::DownloadCancelled, id)); | 377 &DownloadManager::DownloadCancelled, id)); |
378 } | 378 } |
OLD | NEW |