OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "content/browser/download/save_file_manager.h" | 7 #include "content/browser/download/save_file_manager.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // We do forward an update to the UI thread here, since we do not use timer to | 234 // We do forward an update to the UI thread here, since we do not use timer to |
235 // update the UI. If the user has canceled the saving action (in the UI | 235 // update the UI. If the user has canceled the saving action (in the UI |
236 // thread). We may receive a few more updates before the IO thread gets the | 236 // thread). We may receive a few more updates before the IO thread gets the |
237 // cancel message. We just delete the data since the SaveFile has been deleted. | 237 // cancel message. We just delete the data since the SaveFile has been deleted. |
238 void SaveFileManager::UpdateSaveProgress(int save_id, | 238 void SaveFileManager::UpdateSaveProgress(int save_id, |
239 net::IOBuffer* data, | 239 net::IOBuffer* data, |
240 int data_len) { | 240 int data_len) { |
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
242 SaveFile* save_file = LookupSaveFile(save_id); | 242 SaveFile* save_file = LookupSaveFile(save_id); |
243 if (save_file) { | 243 if (save_file) { |
244 net::Error write_success = | 244 content::DownloadInterruptReason reason = |
245 save_file->AppendDataToFile(data->data(), data_len); | 245 save_file->AppendDataToFile(data->data(), data_len); |
246 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
247 BrowserThread::UI, FROM_HERE, | 247 BrowserThread::UI, FROM_HERE, |
248 base::Bind(&SaveFileManager::OnUpdateSaveProgress, | 248 base::Bind(&SaveFileManager::OnUpdateSaveProgress, |
249 this, | 249 this, |
250 save_file->save_id(), | 250 save_file->save_id(), |
251 save_file->BytesSoFar(), | 251 save_file->BytesSoFar(), |
252 write_success == net::OK)); | 252 reason == content::DOWNLOAD_INTERRUPT_REASON_NONE)); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 // The IO thread will call this when saving is completed or it got error when | 256 // The IO thread will call this when saving is completed or it got error when |
257 // fetching data. In the former case, we forward the message to OnSaveFinished | 257 // fetching data. In the former case, we forward the message to OnSaveFinished |
258 // in UI thread. In the latter case, the save ID will be -1, which means the | 258 // in UI thread. In the latter case, the save ID will be -1, which means the |
259 // saving action did not even start, so we need to call OnErrorFinished in UI | 259 // saving action did not even start, so we need to call OnErrorFinished in UI |
260 // thread, which will use the save URL to find corresponding request record and | 260 // thread, which will use the save URL to find corresponding request record and |
261 // delete it. | 261 // delete it. |
262 void SaveFileManager::SaveFinished(int save_id, | 262 void SaveFileManager::SaveFinished(int save_id, |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 SaveFileMap::iterator it = save_file_map_.find(*i); | 517 SaveFileMap::iterator it = save_file_map_.find(*i); |
518 if (it != save_file_map_.end()) { | 518 if (it != save_file_map_.end()) { |
519 SaveFile* save_file = it->second; | 519 SaveFile* save_file = it->second; |
520 DCHECK(!save_file->InProgress()); | 520 DCHECK(!save_file->InProgress()); |
521 file_util::Delete(save_file->FullPath(), false); | 521 file_util::Delete(save_file->FullPath(), false); |
522 delete save_file; | 522 delete save_file; |
523 save_file_map_.erase(it); | 523 save_file_map_.erase(it); |
524 } | 524 } |
525 } | 525 } |
526 } | 526 } |
OLD | NEW |