| 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_item.h" | 5 #include "chrome/browser/download/download_item.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 | 323 |
| 324 // Notify our observers that we are complete (the call to OnAllDataSaved() | 324 // Notify our observers that we are complete (the call to OnAllDataSaved() |
| 325 // set the state to complete but did not notify). | 325 // set the state to complete but did not notify). |
| 326 UpdateObservers(); | 326 UpdateObservers(); |
| 327 | 327 |
| 328 // The download file is meant to be completed if both the filename is | 328 // The download file is meant to be completed if both the filename is |
| 329 // finalized and the file data is downloaded. The ordering of these two | 329 // finalized and the file data is downloaded. The ordering of these two |
| 330 // actions is indeterministic. Thus, if the filename is not finalized yet, | 330 // actions is indeterministic. Thus, if the filename is not finalized yet, |
| 331 // delay the notification. | 331 // delay the notification. |
| 332 if (name_finalized()) | 332 if (name_finalized()) { |
| 333 NotifyObserversDownloadFileCompleted(); | 333 NotifyObserversDownloadFileCompleted(); |
| 334 download_manager_->RemoveFromActiveList(id()); |
| 335 } |
| 334 } | 336 } |
| 335 | 337 |
| 336 void DownloadItem::Remove(bool delete_on_disk) { | 338 void DownloadItem::Remove(bool delete_on_disk) { |
| 337 Cancel(true); | 339 Cancel(true); |
| 338 state_ = REMOVING; | 340 state_ = REMOVING; |
| 339 if (delete_on_disk) { | 341 if (delete_on_disk) { |
| 340 BrowserThread::PostTask( | 342 BrowserThread::PostTask( |
| 341 BrowserThread::FILE, FROM_HERE, | 343 BrowserThread::FILE, FROM_HERE, |
| 342 NewRunnableFunction(&DeleteDownloadedFile, full_path_)); | 344 NewRunnableFunction(&DeleteDownloadedFile, full_path_)); |
| 343 } | 345 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 UpdateObservers(); | 390 UpdateObservers(); |
| 389 } | 391 } |
| 390 | 392 |
| 391 void DownloadItem::OnNameFinalized() { | 393 void DownloadItem::OnNameFinalized() { |
| 392 name_finalized_ = true; | 394 name_finalized_ = true; |
| 393 | 395 |
| 394 // The download file is meant to be completed if both the filename is | 396 // The download file is meant to be completed if both the filename is |
| 395 // finalized and the file data is downloaded. The ordering of these two | 397 // finalized and the file data is downloaded. The ordering of these two |
| 396 // actions is indeterministic. Thus, if we are still in downloading the | 398 // actions is indeterministic. Thus, if we are still in downloading the |
| 397 // file, delay the notification. | 399 // file, delay the notification. |
| 398 if (state() == DownloadItem::COMPLETE) | 400 if (state() == DownloadItem::COMPLETE) { |
| 399 NotifyObserversDownloadFileCompleted(); | 401 NotifyObserversDownloadFileCompleted(); |
| 402 download_manager_->RemoveFromActiveList(id()); |
| 403 } |
| 400 } | 404 } |
| 401 | 405 |
| 402 void DownloadItem::OnSafeDownloadFinished(DownloadFileManager* file_manager) { | 406 void DownloadItem::OnSafeDownloadFinished(DownloadFileManager* file_manager) { |
| 403 DCHECK_EQ(SAFE, safety_state()); | 407 DCHECK_EQ(SAFE, safety_state()); |
| 404 DCHECK(file_manager); | 408 DCHECK(file_manager); |
| 405 if (NeedsRename()) { | 409 if (NeedsRename()) { |
| 406 BrowserThread::PostTask( | 410 BrowserThread::PostTask( |
| 407 BrowserThread::FILE, FROM_HERE, | 411 BrowserThread::FILE, FROM_HERE, |
| 408 NewRunnableMethod( | 412 NewRunnableMethod( |
| 409 file_manager, &DownloadFileManager::OnFinalDownloadName, | 413 file_manager, &DownloadFileManager::OnFinalDownloadName, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 target_name_.value().c_str(), | 547 target_name_.value().c_str(), |
| 544 full_path().value().c_str()); | 548 full_path().value().c_str()); |
| 545 } else { | 549 } else { |
| 546 description += base::StringPrintf(" url = \"%s\"", url().spec().c_str()); | 550 description += base::StringPrintf(" url = \"%s\"", url().spec().c_str()); |
| 547 } | 551 } |
| 548 | 552 |
| 549 description += " }"; | 553 description += " }"; |
| 550 | 554 |
| 551 return description; | 555 return description; |
| 552 } | 556 } |
| OLD | NEW |