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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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 | Annotate | Revision Log
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, ""); 368 download_->UpdateProgress(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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 return false; 442 return false;
443 } 443 }
444 444
445 // Generate name for saving resource. 445 // Generate name for saving resource.
446 bool SavePackage::GenerateFileName(const std::string& disposition, 446 bool SavePackage::GenerateFileName(const std::string& disposition,
447 const GURL& url, 447 const GURL& url,
448 bool need_html_ext, 448 bool need_html_ext,
449 base::FilePath::StringType* generated_name) { 449 base::FilePath::StringType* generated_name) {
450 // TODO(jungshik): Figure out the referrer charset when having one 450 // TODO(jungshik): Figure out the referrer charset when having one
451 // makes sense and pass it to GenerateFileName. 451 // makes sense and pass it to GenerateFileName.
452 base::FilePath file_path = net::GenerateFileName(url, disposition, "", "", "", 452 base::FilePath file_path = net::GenerateFileName(url,
453 disposition,
454 std::string(),
455 std::string(),
456 std::string(),
453 kDefaultSaveName); 457 kDefaultSaveName);
454 458
455 DCHECK(!file_path.empty()); 459 DCHECK(!file_path.empty());
456 base::FilePath::StringType pure_file_name = 460 base::FilePath::StringType pure_file_name =
457 file_path.RemoveExtension().BaseName().value(); 461 file_path.RemoveExtension().BaseName().value();
458 base::FilePath::StringType file_name_ext = file_path.Extension(); 462 base::FilePath::StringType file_name_ext = file_path.Extension();
459 463
460 // If it is HTML resource, use ".htm{l,}" as its extension. 464 // If it is HTML resource, use ".htm{l,}" as its extension.
461 if (need_html_ext) { 465 if (need_html_ext) {
462 file_name_ext = FILE_PATH_LITERAL("."); 466 file_name_ext = FILE_PATH_LITERAL(".");
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, 785 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap,
782 file_manager_, 786 file_manager_,
783 save_ids)); 787 save_ids));
784 788
785 if (download_) { 789 if (download_) {
786 // Hack to avoid touching download_ after user cancel. 790 // Hack to avoid touching download_ after user cancel.
787 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 791 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
788 // with SavePackage flow. 792 // with SavePackage flow.
789 if (download_->IsInProgress()) { 793 if (download_->IsInProgress()) {
790 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) { 794 if (save_type_ != SAVE_PAGE_TYPE_AS_MHTML) {
791 download_->UpdateProgress(all_save_items_count_, CurrentSpeed(), ""); 795 download_->UpdateProgress(
796 all_save_items_count_, CurrentSpeed(), std::string());
792 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); 797 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash);
793 } 798 }
794 download_->MarkAsComplete(); 799 download_->MarkAsComplete();
795 } 800 }
796 FinalizeDownloadEntry(); 801 FinalizeDownloadEntry();
797 } 802 }
798 } 803 }
799 804
800 // Called for updating end state. 805 // Called for updating end state.
801 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { 806 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) {
802 // Because we might have canceled this saving job before, 807 // Because we might have canceled this saving job before,
803 // so we might not find corresponding SaveItem. Just ignore it. 808 // so we might not find corresponding SaveItem. Just ignore it.
804 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); 809 SaveItem* save_item = LookupItemInProcessBySaveId(save_id);
805 if (!save_item) 810 if (!save_item)
806 return; 811 return;
807 812
808 // Let SaveItem set end state. 813 // Let SaveItem set end state.
809 save_item->Finish(size, is_success); 814 save_item->Finish(size, is_success);
810 // Remove the associated save id and SavePackage. 815 // Remove the associated save id and SavePackage.
811 file_manager_->RemoveSaveFile(save_id, save_item->url(), this); 816 file_manager_->RemoveSaveFile(save_id, save_item->url(), this);
812 817
813 PutInProgressItemToSavedMap(save_item); 818 PutInProgressItemToSavedMap(save_item);
814 819
815 // Inform the DownloadItem to update UI. 820 // Inform the DownloadItem to update UI.
816 // We use the received bytes as number of saved files. 821 // We use the received bytes as number of saved files.
817 // Hack to avoid touching download_ after user cancel. 822 // Hack to avoid touching download_ after user cancel.
818 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 823 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
819 // with SavePackage flow. 824 // with SavePackage flow.
820 if (download_ && download_->IsInProgress()) 825 if (download_ && download_->IsInProgress())
821 download_->UpdateProgress(completed_count(), CurrentSpeed(), ""); 826 download_->UpdateProgress(completed_count(), CurrentSpeed(), std::string());
822 827
823 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM && 828 if (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM &&
824 save_item->url() == page_url_ && !save_item->received_bytes()) { 829 save_item->url() == page_url_ && !save_item->received_bytes()) {
825 // If size of main HTML page is 0, treat it as disk error. 830 // If size of main HTML page is 0, treat it as disk error.
826 Cancel(false); 831 Cancel(false);
827 return; 832 return;
828 } 833 }
829 834
830 if (canceled()) { 835 if (canceled()) {
831 DCHECK(finished_); 836 DCHECK(finished_);
(...skipping 24 matching lines...) Expand all
856 save_item->Finish(0, false); 861 save_item->Finish(0, false);
857 862
858 PutInProgressItemToSavedMap(save_item); 863 PutInProgressItemToSavedMap(save_item);
859 864
860 // Inform the DownloadItem to update UI. 865 // Inform the DownloadItem to update UI.
861 // We use the received bytes as number of saved files. 866 // We use the received bytes as number of saved files.
862 // Hack to avoid touching download_ after user cancel. 867 // Hack to avoid touching download_ after user cancel.
863 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 868 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
864 // with SavePackage flow. 869 // with SavePackage flow.
865 if (download_ && download_->IsInProgress()) 870 if (download_ && download_->IsInProgress())
866 download_->UpdateProgress(completed_count(), CurrentSpeed(), ""); 871 download_->UpdateProgress(completed_count(), CurrentSpeed(), std::string());
867 872
868 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) || 873 if ((save_type_ == SAVE_PAGE_TYPE_AS_ONLY_HTML) ||
869 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) || 874 (save_type_ == SAVE_PAGE_TYPE_AS_MHTML) ||
870 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) { 875 (save_item->save_source() == SaveFileCreateInfo::SAVE_FILE_FROM_DOM)) {
871 // We got error when saving page. Treat it as disk error. 876 // We got error when saving page. Treat it as disk error.
872 Cancel(true); 877 Cancel(true);
873 } 878 }
874 879
875 if (canceled()) { 880 if (canceled()) {
876 DCHECK(finished_); 881 DCHECK(finished_);
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 1432
1428 void SavePackage::FinalizeDownloadEntry() { 1433 void SavePackage::FinalizeDownloadEntry() {
1429 DCHECK(download_); 1434 DCHECK(download_);
1430 DCHECK(download_manager_); 1435 DCHECK(download_manager_);
1431 1436
1432 download_manager_->OnSavePackageSuccessfullyFinished(download_); 1437 download_manager_->OnSavePackageSuccessfullyFinished(download_);
1433 StopObservation(); 1438 StopObservation();
1434 } 1439 }
1435 1440
1436 } // namespace content 1441 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/save_file.cc ('k') | content/browser/download/save_package_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698