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 "content/browser/download/save_package.h" | 5 #include "content/browser/download/save_package.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 if (size <= 0) { | 366 if (size <= 0) { |
367 Cancel(false); | 367 Cancel(false); |
368 return; | 368 return; |
369 } | 369 } |
370 wrote_to_completed_file_ = true; | 370 wrote_to_completed_file_ = true; |
371 | 371 |
372 // Hack to avoid touching download_ after user cancel. | 372 // Hack to avoid touching download_ after user cancel. |
373 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 373 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
374 // with SavePackage flow. | 374 // with SavePackage flow. |
375 if (download_->GetState() == DownloadItem::IN_PROGRESS) { | 375 if (download_->GetState() == DownloadItem::IN_PROGRESS) { |
376 download_->SetTotalBytes(size); | |
377 download_->DestinationUpdate(size, 0, std::string()); | |
378 // Must call OnAllDataSaved here in order for | 376 // Must call OnAllDataSaved here in order for |
379 // GDataDownloadObserver::ShouldUpload() to return true. | 377 // GDataDownloadObserver::ShouldUpload() to return true. |
380 // ShouldCompleteDownload() may depend on the gdata uploader to finish. | 378 // ShouldCompleteDownload() may depend on the gdata uploader to finish. |
381 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); | 379 download_->OnAllDataSaved(size, scoped_ptr<crypto::SecureHash>()); |
382 } | 380 } |
383 | 381 |
384 if (!download_manager_->GetDelegate()) { | 382 if (!download_manager_->GetDelegate()) { |
385 Finish(); | 383 Finish(); |
386 return; | 384 return; |
387 } | 385 } |
388 | 386 |
389 if (download_manager_->GetDelegate()->ShouldCompleteDownload( | 387 if (download_manager_->GetDelegate()->ShouldCompleteDownload( |
390 download_, base::Bind(&SavePackage::Finish, this))) { | 388 download_, base::Bind(&SavePackage::Finish, this))) { |
391 Finish(); | 389 Finish(); |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 BrowserThread::FILE, FROM_HERE, | 774 BrowserThread::FILE, FROM_HERE, |
777 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_, | 775 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, file_manager_, |
778 list_of_failed_save_item_ids)); | 776 list_of_failed_save_item_ids)); |
779 | 777 |
780 if (download_) { | 778 if (download_) { |
781 // Hack to avoid touching download_ after user cancel. | 779 // Hack to avoid touching download_ after user cancel. |
782 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 780 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
783 // with SavePackage flow. | 781 // with SavePackage flow. |
784 if (download_->GetState() == DownloadItem::IN_PROGRESS) { | 782 if (download_->GetState() == DownloadItem::IN_PROGRESS) { |
785 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { | 783 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { |
786 download_->DestinationUpdate( | 784 download_->DestinationUpdate(all_save_items_count_, CurrentSpeed()); |
787 all_save_items_count_, CurrentSpeed(), std::string()); | 785 download_->OnAllDataSaved(all_save_items_count_, |
788 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); | 786 scoped_ptr<crypto::SecureHash>()); |
789 } | 787 } |
790 download_->MarkAsComplete(); | 788 download_->MarkAsComplete(); |
791 } | 789 } |
792 FinalizeDownloadEntry(); | 790 FinalizeDownloadEntry(); |
793 } | 791 } |
794 } | 792 } |
795 | 793 |
796 // Called for updating end state. | 794 // Called for updating end state. |
797 void SavePackage::SaveFinished(SaveItemId save_item_id, | 795 void SavePackage::SaveFinished(SaveItemId save_item_id, |
798 int64_t size, | 796 int64_t size, |
(...skipping 10 matching lines...) Expand all Loading... |
809 file_manager_->RemoveSaveFile(save_item->id(), this); | 807 file_manager_->RemoveSaveFile(save_item->id(), this); |
810 | 808 |
811 PutInProgressItemToSavedMap(save_item); | 809 PutInProgressItemToSavedMap(save_item); |
812 | 810 |
813 // Inform the DownloadItem to update UI. | 811 // Inform the DownloadItem to update UI. |
814 // We use the received bytes as number of saved files. | 812 // We use the received bytes as number of saved files. |
815 // Hack to avoid touching download_ after user cancel. | 813 // Hack to avoid touching download_ after user cancel. |
816 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 814 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
817 // with SavePackage flow. | 815 // with SavePackage flow. |
818 if (download_ && (download_->GetState() == DownloadItem::IN_PROGRESS)) { | 816 if (download_ && (download_->GetState() == DownloadItem::IN_PROGRESS)) { |
819 download_->DestinationUpdate( | 817 download_->DestinationUpdate(completed_count(), CurrentSpeed()); |
820 completed_count(), CurrentSpeed(), std::string()); | |
821 } | 818 } |
822 | 819 |
823 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && | 820 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && |
824 save_item->url() == page_url_ && !save_item->received_bytes()) { | 821 save_item->url() == page_url_ && !save_item->received_bytes()) { |
825 // If size of main HTML page is 0, treat it as disk error. | 822 // If size of main HTML page is 0, treat it as disk error. |
826 Cancel(false); | 823 Cancel(false); |
827 return; | 824 return; |
828 } | 825 } |
829 | 826 |
830 if (canceled()) { | 827 if (canceled()) { |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 | 1519 |
1523 void SavePackage::FinalizeDownloadEntry() { | 1520 void SavePackage::FinalizeDownloadEntry() { |
1524 DCHECK(download_); | 1521 DCHECK(download_); |
1525 DCHECK(download_manager_); | 1522 DCHECK(download_manager_); |
1526 | 1523 |
1527 download_manager_->OnSavePackageSuccessfullyFinished(download_); | 1524 download_manager_->OnSavePackageSuccessfullyFinished(download_); |
1528 StopObservation(); | 1525 StopObservation(); |
1529 } | 1526 } |
1530 | 1527 |
1531 } // namespace content | 1528 } // namespace content |
OLD | NEW |