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