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

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

Issue 10912173: Replace the DownloadFileManager with direct ownership of DownloadFileImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR. Created 8 years, 3 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_path.h" 10 #include "base/file_path.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Cancel(false); 333 Cancel(false);
334 return; 334 return;
335 } 335 }
336 wrote_to_completed_file_ = true; 336 wrote_to_completed_file_ = true;
337 337
338 // Hack to avoid touching download_ after user cancel. 338 // Hack to avoid touching download_ after user cancel.
339 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 339 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
340 // with SavePackage flow. 340 // with SavePackage flow.
341 if (download_->IsInProgress()) { 341 if (download_->IsInProgress()) {
342 download_->SetTotalBytes(size); 342 download_->SetTotalBytes(size);
343 download_->UpdateProgress(size, 0, "");
343 // Must call OnAllDataSaved here in order for 344 // Must call OnAllDataSaved here in order for
344 // GDataDownloadObserver::ShouldUpload() to return true. 345 // GDataDownloadObserver::ShouldUpload() to return true.
345 // ShouldCompleteDownload() may depend on the gdata uploader to finish. 346 // ShouldCompleteDownload() may depend on the gdata uploader to finish.
346 download_->OnAllDataSaved(size, DownloadItem::kEmptyFileHash); 347 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash);
347 } 348 }
348 349
349 if (!download_manager_->GetDelegate() || 350 if (!download_manager_->GetDelegate() ||
350 download_manager_->GetDelegate()->ShouldCompleteDownload( 351 download_manager_->GetDelegate()->ShouldCompleteDownload(
351 download_, base::Bind(&SavePackage::Finish, this))) { 352 download_, base::Bind(&SavePackage::Finish, this))) {
352 Finish(); 353 Finish();
353 } 354 }
354 } 355 }
355 356
356 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further 357 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin(); 741 for (SaveUrlItemMap::iterator it = saved_failed_items_.begin();
741 it != saved_failed_items_.end(); ++it) 742 it != saved_failed_items_.end(); ++it)
742 save_ids.push_back(it->second->save_id()); 743 save_ids.push_back(it->second->save_id());
743 744
744 BrowserThread::PostTask( 745 BrowserThread::PostTask(
745 BrowserThread::FILE, FROM_HERE, 746 BrowserThread::FILE, FROM_HERE,
746 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, 747 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap,
747 file_manager_, 748 file_manager_,
748 save_ids)); 749 save_ids));
749 750
750 // Hack to avoid touching download_ after user cancel. 751 if (download_) {
751 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem 752 // Hack to avoid touching download_ after user cancel.
752 // with SavePackage flow. 753 // TODO(rdsmith/benjhayden): Integrate canceling on DownloadItem
753 if (download_ && download_->IsInProgress()) { 754 // with SavePackage flow.
754 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) { 755 if (download_->IsInProgress()) {
755 download_->OnAllDataSaved(all_save_items_count_, 756 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) {
756 DownloadItem::kEmptyFileHash); 757 download_->UpdateProgress(all_save_items_count_, CurrentSpeed(), "");
758 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash);
759 }
760 download_->MarkAsComplete();
757 } 761 }
758 download_->MarkAsComplete(); 762 FinalizeDownloadEntry();
759 } 763 }
760 FinalizeDownloadEntry();
761 } 764 }
762 765
763 // Called for updating end state. 766 // Called for updating end state.
764 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { 767 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) {
765 // Because we might have canceled this saving job before, 768 // Because we might have canceled this saving job before,
766 // so we might not find corresponding SaveItem. Just ignore it. 769 // so we might not find corresponding SaveItem. Just ignore it.
767 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); 770 SaveItem* save_item = LookupItemInProcessBySaveId(save_id);
768 if (!save_item) 771 if (!save_item)
769 return; 772 return;
770 773
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 // central SavePackage related location that observers can 1395 // central SavePackage related location that observers can
1393 // get to if they want to wait for notifications for a 1396 // get to if they want to wait for notifications for a
1394 // particular BrowserContext. Alternatively, we could make 1397 // particular BrowserContext. Alternatively, we could make
1395 // it come from the WebContents, which would be more specific 1398 // it come from the WebContents, which would be more specific
1396 // but less useful to (current) customers. 1399 // but less useful to (current) customers.
1397 content::Source<content::DownloadManager>(download_manager_), 1400 content::Source<content::DownloadManager>(download_manager_),
1398 content::Details<content::DownloadItem>(download_)); 1401 content::Details<content::DownloadItem>(download_));
1399 download_manager_->SavePageDownloadFinished(download_); 1402 download_manager_->SavePageDownloadFinished(download_);
1400 StopObservation(); 1403 StopObservation();
1401 } 1404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698