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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 void SavePackage::OnMHTMLGenerated(const base::FilePath& path, int64 size) { | 356 void SavePackage::OnMHTMLGenerated(const base::FilePath& path, int64 size) { |
357 if (size <= 0) { | 357 if (size <= 0) { |
358 Cancel(false); | 358 Cancel(false); |
359 return; | 359 return; |
360 } | 360 } |
361 wrote_to_completed_file_ = true; | 361 wrote_to_completed_file_ = true; |
362 | 362 |
363 // Hack to avoid touching download_ after user cancel. | 363 // Hack to avoid touching download_ after user cancel. |
364 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 364 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
365 // with SavePackage flow. | 365 // with SavePackage flow. |
366 if (download_->IsInProgress()) { | 366 if (download_->GetState() == DownloadItem::IN_PROGRESS) { |
367 download_->SetTotalBytes(size); | 367 download_->SetTotalBytes(size); |
368 download_->DestinationUpdate(size, 0, std::string()); | 368 download_->DestinationUpdate(size, 0, std::string()); |
369 // Must call OnAllDataSaved here in order for | 369 // Must call OnAllDataSaved here in order for |
370 // GDataDownloadObserver::ShouldUpload() to return true. | 370 // GDataDownloadObserver::ShouldUpload() to return true. |
371 // ShouldCompleteDownload() may depend on the gdata uploader to finish. | 371 // ShouldCompleteDownload() may depend on the gdata uploader to finish. |
372 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); | 372 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); |
373 } | 373 } |
374 | 374 |
375 if (!download_manager_->GetDelegate()) { | 375 if (!download_manager_->GetDelegate()) { |
376 Finish(); | 376 Finish(); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 BrowserThread::PostTask( | 783 BrowserThread::PostTask( |
784 BrowserThread::FILE, FROM_HERE, | 784 BrowserThread::FILE, FROM_HERE, |
785 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, | 785 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, |
786 file_manager_, | 786 file_manager_, |
787 save_ids)); | 787 save_ids)); |
788 | 788 |
789 if (download_) { | 789 if (download_) { |
790 // Hack to avoid touching download_ after user cancel. | 790 // Hack to avoid touching download_ after user cancel. |
791 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 791 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
792 // with SavePackage flow. | 792 // with SavePackage flow. |
793 if (download_->IsInProgress()) { | 793 if (download_->GetState() == DownloadItem::IN_PROGRESS) { |
794 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { | 794 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { |
795 download_->DestinationUpdate( | 795 download_->DestinationUpdate( |
796 all_save_items_count_, CurrentSpeed(), std::string()); | 796 all_save_items_count_, CurrentSpeed(), std::string()); |
797 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); | 797 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); |
798 } | 798 } |
799 download_->MarkAsComplete(); | 799 download_->MarkAsComplete(); |
800 } | 800 } |
801 FinalizeDownloadEntry(); | 801 FinalizeDownloadEntry(); |
802 } | 802 } |
803 } | 803 } |
(...skipping 11 matching lines...) Expand all Loading... |
815 // Remove the associated save id and SavePackage. | 815 // Remove the associated save id and SavePackage. |
816 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); | 816 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); |
817 | 817 |
818 PutInProgressItemToSavedMap(save_item); | 818 PutInProgressItemToSavedMap(save_item); |
819 | 819 |
820 // Inform the DownloadItem to update UI. | 820 // Inform the DownloadItem to update UI. |
821 // We use the received bytes as number of saved files. | 821 // We use the received bytes as number of saved files. |
822 // Hack to avoid touching download_ after user cancel. | 822 // Hack to avoid touching download_ after user cancel. |
823 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 823 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
824 // with SavePackage flow. | 824 // with SavePackage flow. |
825 if (download_ && download_->IsInProgress()) { | 825 if (download_ && (download_->GetState() == DownloadItem::IN_PROGRESS)) { |
826 download_->DestinationUpdate( | 826 download_->DestinationUpdate( |
827 completed_count(), CurrentSpeed(), std::string()); | 827 completed_count(), CurrentSpeed(), std::string()); |
828 } | 828 } |
829 | 829 |
830 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && | 830 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && |
831 save_item->url() == page_url_ && !save_item->received_bytes()) { | 831 save_item->url() == page_url_ && !save_item->received_bytes()) { |
832 // If size of main HTML page is 0, treat it as disk error. | 832 // If size of main HTML page is 0, treat it as disk error. |
833 Cancel(false); | 833 Cancel(false); |
834 return; | 834 return; |
835 } | 835 } |
(...skipping 26 matching lines...) Expand all Loading... |
862 | 862 |
863 save_item->Finish(0, false); | 863 save_item->Finish(0, false); |
864 | 864 |
865 PutInProgressItemToSavedMap(save_item); | 865 PutInProgressItemToSavedMap(save_item); |
866 | 866 |
867 // Inform the DownloadItem to update UI. | 867 // Inform the DownloadItem to update UI. |
868 // We use the received bytes as number of saved files. | 868 // We use the received bytes as number of saved files. |
869 // Hack to avoid touching download_ after user cancel. | 869 // Hack to avoid touching download_ after user cancel. |
870 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 870 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
871 // with SavePackage flow. | 871 // with SavePackage flow. |
872 if (download_ && download_->IsInProgress()) { | 872 if (download_ && (download_->GetState() == DownloadItem::IN_PROGRESS)) { |
873 download_->DestinationUpdate( | 873 download_->DestinationUpdate( |
874 completed_count(), CurrentSpeed(), std::string()); | 874 completed_count(), CurrentSpeed(), std::string()); |
875 } | 875 } |
876 | 876 |
877 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) || | 877 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) || |
878 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) || | 878 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) || |
879 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) { | 879 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) { |
880 // We got error when saving page. Treat it as disk error. | 880 // We got error when saving page. Treat it as disk error. |
881 Cancel(true); | 881 Cancel(true); |
882 } | 882 } |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 if (resources_list.size() != referrers_list.size()) | 1157 if (resources_list.size() != referrers_list.size()) |
1158 return; | 1158 return; |
1159 | 1159 |
1160 all_save_items_count_ = static_cast<int>(resources_list.size()) + | 1160 all_save_items_count_ = static_cast<int>(resources_list.size()) + |
1161 static_cast<int>(frames_list.size()); | 1161 static_cast<int>(frames_list.size()); |
1162 | 1162 |
1163 // We use total bytes as the total number of files we want to save. | 1163 // We use total bytes as the total number of files we want to save. |
1164 // Hack to avoid touching download_ after user cancel. | 1164 // Hack to avoid touching download_ after user cancel. |
1165 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem | 1165 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem |
1166 // with SavePackage flow. | 1166 // with SavePackage flow. |
1167 if (download_ && download_->IsInProgress()) | 1167 if (download_ && (download_->GetState() == DownloadItem::IN_PROGRESS)) |
1168 download_->SetTotalBytes(all_save_items_count_); | 1168 download_->SetTotalBytes(all_save_items_count_); |
1169 | 1169 |
1170 if (all_save_items_count_) { | 1170 if (all_save_items_count_) { |
1171 // Put all sub-resources to wait list. | 1171 // Put all sub-resources to wait list. |
1172 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { | 1172 for (int i = 0; i < static_cast<int>(resources_list.size()); ++i) { |
1173 const GURL& u = resources_list[i]; | 1173 const GURL& u = resources_list[i]; |
1174 DCHECK(u.is_valid()); | 1174 DCHECK(u.is_valid()); |
1175 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? | 1175 SaveFileCreateInfo::SaveFileSource save_source = u.SchemeIsFile() ? |
1176 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : | 1176 SaveFileCreateInfo::SAVE_FILE_FROM_FILE : |
1177 SaveFileCreateInfo::SAVE_FILE_FROM_NET; | 1177 SaveFileCreateInfo::SAVE_FILE_FROM_NET; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 | 1436 |
1437 void SavePackage::FinalizeDownloadEntry() { | 1437 void SavePackage::FinalizeDownloadEntry() { |
1438 DCHECK(download_); | 1438 DCHECK(download_); |
1439 DCHECK(download_manager_); | 1439 DCHECK(download_manager_); |
1440 | 1440 |
1441 download_manager_->OnSavePackageSuccessfullyFinished(download_); | 1441 download_manager_->OnSavePackageSuccessfullyFinished(download_); |
1442 StopObservation(); | 1442 StopObservation(); |
1443 } | 1443 } |
1444 | 1444 |
1445 } // namespace content | 1445 } // namespace content |
OLD | NEW |