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_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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 if (size <= 0) { | 330 if (size <= 0) { |
332 Cancel(false); | 331 Cancel(false); |
333 return; | 332 return; |
334 } | 333 } |
335 wrote_to_completed_file_ = true; | 334 wrote_to_completed_file_ = true; |
336 download_->SetTotalBytes(size); | 335 download_->SetTotalBytes(size); |
337 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash); | 336 download_->UpdateProgress(size, size, DownloadItem::kEmptyFileHash); |
338 // Must call OnAllDataSaved here in order for | 337 // Must call OnAllDataSaved here in order for |
339 // GDataDownloadObserver::ShouldUpload() to return true. | 338 // GDataDownloadObserver::ShouldUpload() to return true. |
340 // ShouldCompleteDownload() may depend on the gdata uploader to finish. | 339 // ShouldCompleteDownload() may depend on the gdata uploader to finish. |
341 download_->OnAllDataSaved(size, DownloadItem::kEmptyFileHash); | 340 download_->UpdateProgress(size, CurrentSpeed(), ""); |
| 341 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); |
342 if (!download_manager_->GetDelegate() || | 342 if (!download_manager_->GetDelegate() || |
343 download_manager_->GetDelegate()->ShouldCompleteDownload( | 343 download_manager_->GetDelegate()->ShouldCompleteDownload( |
344 download_, base::Bind(&SavePackage::Finish, this))) { | 344 download_, base::Bind(&SavePackage::Finish, this))) { |
345 Finish(); | 345 Finish(); |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further | 349 // On POSIX, the length of |pure_file_name| + |file_name_ext| is further |
350 // restricted by NAME_MAX. The maximum allowed path looks like: | 350 // restricted by NAME_MAX. The maximum allowed path looks like: |
351 // '/path/to/save_dir' + '/' + NAME_MAX. | 351 // '/path/to/save_dir' + '/' + NAME_MAX. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 it != saved_failed_items_.end(); ++it) | 734 it != saved_failed_items_.end(); ++it) |
735 save_ids.push_back(it->second->save_id()); | 735 save_ids.push_back(it->second->save_id()); |
736 | 736 |
737 BrowserThread::PostTask( | 737 BrowserThread::PostTask( |
738 BrowserThread::FILE, FROM_HERE, | 738 BrowserThread::FILE, FROM_HERE, |
739 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, | 739 base::Bind(&SaveFileManager::RemoveSavedFileFromFileMap, |
740 file_manager_, | 740 file_manager_, |
741 save_ids)); | 741 save_ids)); |
742 | 742 |
743 if (download_) { | 743 if (download_) { |
744 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) | 744 if (save_type_ != content::SAVE_PAGE_TYPE_AS_MHTML) { |
745 download_->OnAllDataSaved(all_save_items_count_, | 745 download_->UpdateProgress(all_save_items_count_, CurrentSpeed(), ""); |
746 DownloadItem::kEmptyFileHash); | 746 download_->OnAllDataSaved(DownloadItem::kEmptyFileHash); |
| 747 } |
747 download_->MarkAsComplete(); | 748 download_->MarkAsComplete(); |
748 FinalizeDownloadEntry(); | 749 FinalizeDownloadEntry(); |
749 } | 750 } |
750 } | 751 } |
751 | 752 |
752 // Called for updating end state. | 753 // Called for updating end state. |
753 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { | 754 void SavePackage::SaveFinished(int32 save_id, int64 size, bool is_success) { |
754 // Because we might have canceled this saving job before, | 755 // Because we might have canceled this saving job before, |
755 // so we might not find corresponding SaveItem. Just ignore it. | 756 // so we might not find corresponding SaveItem. Just ignore it. |
756 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); | 757 SaveItem* save_item = LookupItemInProcessBySaveId(save_id); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 StopObservation(); | 1362 StopObservation(); |
1362 } | 1363 } |
1363 | 1364 |
1364 void SavePackage::FinalizeDownloadEntry() { | 1365 void SavePackage::FinalizeDownloadEntry() { |
1365 DCHECK(download_); | 1366 DCHECK(download_); |
1366 DCHECK(download_manager_); | 1367 DCHECK(download_manager_); |
1367 | 1368 |
1368 download_manager_->SavePageDownloadFinished(download_); | 1369 download_manager_->SavePageDownloadFinished(download_); |
1369 StopObservation(); | 1370 StopObservation(); |
1370 } | 1371 } |
OLD | NEW |