Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/download/save_package.cc

Issue 14646036: Get rid of DownloadItemImpl::UpdateProgress() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added "Patch from" to commit message Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->IsInProgress()) {
367 download_->SetTotalBytes(size); 367 download_->SetTotalBytes(size);
368 download_->UpdateProgress(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();
377 return; 377 return;
378 } 378 }
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->IsInProgress()) {
794 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { 794 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) {
795 download_->UpdateProgress( 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 }
804 804
805 // Called for updating end state. 805 // Called for updating end state.
806 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { 806 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) {
807 // Because we might have canceled this saving job before, 807 // Because we might have canceled this saving job before,
808 // so we might not find corresponding SaveItem. Just ignore it. 808 // so we might not find corresponding SaveItem. Just ignore it.
809 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); 809 SaveItem* save_item = LookupItemInProcessBySaveId(save_id);
810 if (!save_item) 810 if (!save_item)
811 return; 811 return;
812 812
813 // Let SaveItem set end state. 813 // Let SaveItem set end state.
814 save_item->Finish(size, is_success); 814 save_item->Finish(size, is_success);
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_->IsInProgress()) {
826 download_->UpdateProgress(completed_count(), CurrentSpeed(), std::string()); 826 download_->DestinationUpdate(
827 completed_count(), CurrentSpeed(), std::string());
828 }
827 829
828 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && 830 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM &&
829 save_item->url() == page_url_ && !save_item->received_bytes()) { 831 save_item->url() == page_url_ && !save_item->received_bytes()) {
830 // 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.
831 Cancel(false); 833 Cancel(false);
832 return; 834 return;
833 } 835 }
834 836
835 if (canceled()) { 837 if (canceled()) {
836 DCHECK(finished_); 838 DCHECK(finished_);
(...skipping 23 matching lines...) Expand all
860 862
861 save_item->Finish(0, false); 863 save_item->Finish(0, false);
862 864
863 PutInProgressItemToSavedMap(save_item); 865 PutInProgressItemToSavedMap(save_item);
864 866
865 // Inform the DownloadItem to update UI. 867 // Inform the DownloadItem to update UI.
866 // We use the received bytes as number of saved files. 868 // We use the received bytes as number of saved files.
867 // Hack to avoid touching download_ after user cancel. 869 // Hack to avoid touching download_ after user cancel.
868 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 870 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
869 // with SavePackage flow. 871 // with SavePackage flow.
870 if (download_ && download_->IsInProgress()) 872 if (download_ && download_->IsInProgress()) {
871 download_->UpdateProgress(completed_count(), CurrentSpeed(), std::string()); 873 download_->DestinationUpdate(
874 completed_count(), CurrentSpeed(), std::string());
875 }
872 876
873 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) || 877 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) ||
874 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) || 878 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) ||
875 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) { 879 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) {
876 // We got error when saving page. Treat it as disk error. 880 // We got error when saving page. Treat it as disk error.
877 Cancel(true); 881 Cancel(true);
878 } 882 }
879 883
880 if (canceled()) { 884 if (canceled()) {
881 DCHECK(finished_); 885 DCHECK(finished_);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 1436
1433 void SavePackage::FinalizeDownloadEntry() { 1437 void SavePackage::FinalizeDownloadEntry() {
1434 DCHECK(download_); 1438 DCHECK(download_);
1435 DCHECK(download_manager_); 1439 DCHECK(download_manager_);
1436 1440
1437 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1441 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1438 StopObservation(); 1442 StopObservation();
1439 } 1443 }
1440 1444
1441 } // namespace content 1445 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698