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

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

Issue 10799005: Replace the DownloadFileManager with direct ownership (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to LKGR. Created 8 years, 4 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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/i18n/file_util_icu.h" 12 #include "base/i18n/file_util_icu.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_piece.h" 16 #include "base/string_piece.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/sys_string_conversions.h" 18 #include "base/sys_string_conversions.h"
19 #include "base/threading/thread.h" 19 #include "base/threading/thread.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "content/browser/download/download_file_manager.h"
22 #include "content/browser/download/download_item_impl.h" 21 #include "content/browser/download/download_item_impl.h"
23 #include "content/browser/download/download_manager_impl.h" 22 #include "content/browser/download/download_manager_impl.h"
24 #include "content/browser/download/download_stats.h" 23 #include "content/browser/download/download_stats.h"
25 #include "content/browser/download/save_file.h" 24 #include "content/browser/download/save_file.h"
26 #include "content/browser/download/save_file_manager.h" 25 #include "content/browser/download/save_file_manager.h"
27 #include "content/browser/download/save_item.h" 26 #include "content/browser/download/save_item.h"
28 #include "content/browser/renderer_host/render_process_host_impl.h" 27 #include "content/browser/renderer_host/render_process_host_impl.h"
29 #include "content/browser/renderer_host/render_view_host_delegate.h" 28 #include "content/browser/renderer_host/render_view_host_delegate.h"
30 #include "content/browser/renderer_host/render_view_host_impl.h" 29 #include "content/browser/renderer_host/render_view_host_impl.h"
31 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" 30 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (size <= 0) { 331 if (size <= 0) {
333 Cancel(false); 332 Cancel(false);
334 return; 333 return;
335 } 334 }
336 wrote_to_completed_file_ = true; 335 wrote_to_completed_file_ = true;
337 download_->SetTotalBytes(size); 336 download_->SetTotalBytes(size);
338 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash); 337 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash);
339 // Must call OnAllDataSaved here in order for 338 // Must call OnAllDataSaved here in order for
340 // GDataDownloadObserver::ShouldUpload() to return true. 339 // GDataDownloadObserver::ShouldUpload() to return true.
341 // ShouldCompleteDownload() may depend on the gdata uploader to finish. 340 // ShouldCompleteDownload() may depend on the gdata uploader to finish.
342 download_->OnAllDataSaved(size, DownloadItem::kEmptyFileHash); 341 download_->UpdateProgress(size, CurrentSpeed(), "");
342 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash);
343 if (!download_manager_->GetDelegate() || 343 if (!download_manager_->GetDelegate() ||
344 download_manager_->GetDelegate()->ShouldCompleteDownload( 344 download_manager_->GetDelegate()->ShouldCompleteDownload(
345 download_, base::Bind(&SavePackage::Finish, this))) { 345 download_, base::Bind(&SavePackage::Finish, this))) {
346 Finish(); 346 Finish();
347 } 347 }
348 } 348 }
349 349
350 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further 350 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further
351 // restricted by NAME_MAX. The maximum allowed path looks like: 351 // restricted by NAME_MAX. The maximum allowed path looks like:
352 // '/path/to/save_dir' + '/' + NAME_MAX. 352 // '/path/to/save_dir' + '/' + NAME_MAX.
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 it != saved_failed_items_.end(); ++it) 735 it != saved_failed_items_.end(); ++it)
736 save_ids.push_back(it->second->save_id()); 736 save_ids.push_back(it->second->save_id());
737 737
738 BrowserThread::PostTask( 738 BrowserThread::PostTask(
739 BrowserThread::FILE, FROM_HERE, 739 BrowserThread::FILE, FROM_HERE,
740 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, 740 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap,
741 file_manager_, 741 file_manager_,
742 save_ids)); 742 save_ids));
743 743
744 if (download_) { 744 if (download_) {
745 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) 745 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) {
746 download_->OnAllDataSaved(all_save_items_count_, 746 download_->UpdateProgress(all_save_items_count_, CurrentSpeed(), "");
747 DownloadItem::kEmptyFileHash); 747 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash);
748 }
748 download_->MarkAsComplete(); 749 download_->MarkAsComplete();
749 FinalizeDownloadEntry(); 750 FinalizeDownloadEntry();
750 } 751 }
751 } 752 }
752 753
753 // Called for updating end state. 754 // Called for updating end state.
754 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { 755 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) {
755 // Because we might have canceled this saving job before, 756 // Because we might have canceled this saving job before,
756 // so we might not find corresponding SaveItem. Just ignore it. 757 // so we might not find corresponding SaveItem. Just ignore it.
757 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); 758 SaveItem* save_item = LookupItemInProcessBySaveId(save_id);
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 StopObservation(); 1363 StopObservation();
1363 } 1364 }
1364 1365
1365 void SavePackage::FinalizeDownloadEntry() { 1366 void SavePackage::FinalizeDownloadEntry() {
1366 DCHECK(download_); 1367 DCHECK(download_);
1367 DCHECK(download_manager_); 1368 DCHECK(download_manager_);
1368 1369
1369 download_manager_->SavePageDownloadFinished(download_); 1370 download_manager_->SavePageDownloadFinished(download_);
1370 StopObservation(); 1371 StopObservation();
1371 } 1372 }
OLDNEW
« no previous file with comments | « content/browser/download/mock_download_file.cc ('k') | content/browser/renderer_host/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698