| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 it != saved_failed_items_.end(); ++it) | 672 it != saved_failed_items_.end(); ++it) |
| 673 save_ids.push_back(it->second->save_id()); | 673 save_ids.push_back(it->second->save_id()); |
| 674 | 674 |
| 675 BrowserThread::PostTask( | 675 BrowserThread::PostTask( |
| 676 BrowserThread::FILE, FROM_HERE, | 676 BrowserThread::FILE, FROM_HERE, |
| 677 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, | 677 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, |
| 678 file_manager_, | 678 file_manager_, |
| 679 save_ids)); | 679 save_ids)); |
| 680 | 680 |
| 681 if (download_) { | 681 if (download_) { |
| 682 download_->OnAllDataSaved(all_save_items_count_); | 682 download_->OnAllDataSaved(all_save_items_count_, ""); |
| 683 download_->MarkAsComplete(); | 683 download_->MarkAsComplete(); |
| 684 FinalizeDownloadEntry(); | 684 FinalizeDownloadEntry(); |
| 685 } | 685 } |
| 686 } | 686 } |
| 687 | 687 |
| 688 // Called for updating end state. | 688 // Called for updating end state. |
| 689 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { | 689 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { |
| 690 // Because we might have canceled this saving job before, | 690 // Because we might have canceled this saving job before, |
| 691 // so we might not find corresponding SaveItem. Just ignore it. | 691 // so we might not find corresponding SaveItem. Just ignore it. |
| 692 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); | 692 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); |
| 693 if (!save_item) | 693 if (!save_item) |
| 694 return; | 694 return; |
| 695 | 695 |
| 696 // Let SaveItem set end state. | 696 // Let SaveItem set end state. |
| 697 save_item->Finish(size, is_success); | 697 save_item->Finish(size, is_success); |
| 698 // Remove the associated save id and SavePackage. | 698 // Remove the associated save id and SavePackage. |
| 699 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); | 699 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); |
| 700 | 700 |
| 701 PutInProgressItemToSavedMap(save_item); | 701 PutInProgressItemToSavedMap(save_item); |
| 702 | 702 |
| 703 // Inform the DownloadItem to update UI. | 703 // Inform the DownloadItem to update UI. |
| 704 // We use the received bytes as number of saved files. | 704 // We use the received bytes as number of saved files. |
| 705 if (download_) | 705 if (download_) |
| 706 download_->Update(completed_count()); | 706 download_->Update(completed_count(), ""); |
| 707 | 707 |
| 708 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && | 708 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && |
| 709 save_item->url() == page_url_ && !save_item->received_bytes()) { | 709 save_item->url() == page_url_ && !save_item->received_bytes()) { |
| 710 // If size of main HTML page is 0, treat it as disk error. | 710 // If size of main HTML page is 0, treat it as disk error. |
| 711 Cancel(false); | 711 Cancel(false); |
| 712 return; | 712 return; |
| 713 } | 713 } |
| 714 | 714 |
| 715 if (canceled()) { | 715 if (canceled()) { |
| 716 DCHECK(finished_); | 716 DCHECK(finished_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 738 } | 738 } |
| 739 SaveItem* save_item = it->second; | 739 SaveItem* save_item = it->second; |
| 740 | 740 |
| 741 save_item->Finish(0, false); | 741 save_item->Finish(0, false); |
| 742 | 742 |
| 743 PutInProgressItemToSavedMap(save_item); | 743 PutInProgressItemToSavedMap(save_item); |
| 744 | 744 |
| 745 // Inform the DownloadItem to update UI. | 745 // Inform the DownloadItem to update UI. |
| 746 // We use the received bytes as number of saved files. | 746 // We use the received bytes as number of saved files. |
| 747 if (download_) | 747 if (download_) |
| 748 download_->Update(completed_count()); | 748 download_->Update(completed_count(), ""); |
| 749 | 749 |
| 750 if (save_type_ == SAVE_AS_ONLY_HTML || | 750 if (save_type_ == SAVE_AS_ONLY_HTML || |
| 751 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { | 751 save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM) { |
| 752 // We got error when saving page. Treat it as disk error. | 752 // We got error when saving page. Treat it as disk error. |
| 753 Cancel(true); | 753 Cancel(true); |
| 754 } | 754 } |
| 755 | 755 |
| 756 if (canceled()) { | 756 if (canceled()) { |
| 757 DCHECK(finished_); | 757 DCHECK(finished_); |
| 758 return; | 758 return; |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 StopObservation(); | 1277 StopObservation(); |
| 1278 } | 1278 } |
| 1279 | 1279 |
| 1280 void SavePackage::FinalizeDownloadEntry() { | 1280 void SavePackage::FinalizeDownloadEntry() { |
| 1281 DCHECK(download_); | 1281 DCHECK(download_); |
| 1282 DCHECK(download_manager_); | 1282 DCHECK(download_manager_); |
| 1283 | 1283 |
| 1284 download_manager_->SavePageDownloadFinished(download_); | 1284 download_manager_->SavePageDownloadFinished(download_); |
| 1285 StopObservation(); | 1285 StopObservation(); |
| 1286 } | 1286 } |
| OLD | NEW |