| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 void DownloadManagerImpl::OnFileRemovalDetected(int64 db_handle) { | 278 void DownloadManagerImpl::OnFileRemovalDetected(int64 db_handle) { |
| 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 280 DownloadMap::iterator it = history_downloads_.find(db_handle); | 280 DownloadMap::iterator it = history_downloads_.find(db_handle); |
| 281 if (it != history_downloads_.end()) { | 281 if (it != history_downloads_.end()) { |
| 282 DownloadItem* download_item = it->second; | 282 DownloadItem* download_item = it->second; |
| 283 download_item->OnDownloadedFileRemoved(); | 283 download_item->OnDownloadedFileRemoved(); |
| 284 } | 284 } |
| 285 } | 285 } |
| 286 | 286 |
| 287 void DownloadManagerImpl::RestartDownload( | 287 void DownloadManagerImpl::RestartDownload(int32 download_id) { |
| 288 int32 download_id) { | |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 | 289 |
| 291 DownloadItem* download = GetActiveDownloadItem(download_id); | 290 DownloadItem* download = GetActiveDownloadItem(download_id); |
| 292 if (!download) | 291 if (!download) |
| 293 return; | 292 return; |
| 294 | 293 |
| 295 VLOG(20) << __FUNCTION__ << "()" | 294 VLOG(20) << __FUNCTION__ << "()" |
| 296 << " download = " << download->DebugString(true); | 295 << " download = " << download->DebugString(true); |
| 297 | 296 |
| 298 FilePath suggested_path = download->suggested_path(); | 297 FilePath suggested_path = download->suggested_path(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 BrowserThread::PostTask( | 370 BrowserThread::PostTask( |
| 372 BrowserThread::FILE, FROM_HERE, | 371 BrowserThread::FILE, FROM_HERE, |
| 373 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, | 372 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, |
| 374 file_manager_, download->global_id(), download_path)); | 373 file_manager_, download->global_id(), download_path)); |
| 375 | 374 |
| 376 download->Rename(download_path); | 375 download->Rename(download_path); |
| 377 | 376 |
| 378 delegate_->AddItemToPersistentStore(download); | 377 delegate_->AddItemToPersistentStore(download); |
| 379 } | 378 } |
| 380 | 379 |
| 381 void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 size) { | 380 void DownloadManagerImpl::UpdateDownload(int32 download_id, |
| 381 int64 size, |
| 382 std::string hash_state) { |
| 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 383 DownloadMap::iterator it = active_downloads_.find(download_id); | 384 DownloadMap::iterator it = active_downloads_.find(download_id); |
| 384 if (it != active_downloads_.end()) { | 385 if (it != active_downloads_.end()) { |
| 385 DownloadItem* download = it->second; | 386 DownloadItem* download = it->second; |
| 386 if (download->IsInProgress()) { | 387 if (download->IsInProgress()) { |
| 387 download->Update(size); | 388 download->Update(size, hash_state); |
| 388 UpdateDownloadProgress(); // Reflect size updates. | 389 UpdateDownloadProgress(); // Reflect size updates. |
| 389 delegate_->UpdateItemInPersistentStore(download); | 390 delegate_->UpdateItemInPersistentStore(download); |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 } | 393 } |
| 393 | 394 |
| 394 void DownloadManagerImpl::OnResponseCompleted(int32 download_id, | 395 void DownloadManagerImpl::OnResponseCompleted(int32 download_id, |
| 395 int64 size, | 396 int64 size, |
| 396 const std::string& hash) { | 397 const std::string& hash) { |
| 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 // This function is called from the DownloadItem, so DI state | 569 // This function is called from the DownloadItem, so DI state |
| 569 // should already have been updated. | 570 // should already have been updated. |
| 570 AssertQueueStateConsistent(download); | 571 AssertQueueStateConsistent(download); |
| 571 | 572 |
| 572 if (file_manager_) | 573 if (file_manager_) |
| 573 download->OffThreadCancel(file_manager_); | 574 download->OffThreadCancel(file_manager_); |
| 574 } | 575 } |
| 575 | 576 |
| 576 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, | 577 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, |
| 577 int64 size, | 578 int64 size, |
| 579 std::string hash_state, |
| 578 InterruptReason reason) { | 580 InterruptReason reason) { |
| 579 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 580 | 582 |
| 581 DownloadItem* download = GetActiveDownload(download_id); | 583 DownloadItem* download = GetActiveDownload(download_id); |
| 582 if (!download) | 584 if (!download) |
| 583 return; | 585 return; |
| 584 | 586 |
| 585 VLOG(20) << __FUNCTION__ << "()" | 587 VLOG(20) << __FUNCTION__ << "()" |
| 586 << " reason " << InterruptReasonDebugString(reason) | 588 << " reason " << InterruptReasonDebugString(reason) |
| 587 << " at offset " << download->received_bytes() | 589 << " at offset " << download->received_bytes() |
| 588 << " size = " << size | 590 << " size = " << size |
| 589 << " download = " << download->DebugString(true); | 591 << " download = " << download->DebugString(true); |
| 590 | 592 |
| 591 RemoveFromActiveList(download); | 593 RemoveFromActiveList(download); |
| 592 download->Interrupted(size, reason); | 594 download->Interrupted(size, hash_state, reason); |
| 593 download->OffThreadCancel(file_manager_); | 595 download->OffThreadCancel(file_manager_); |
| 594 } | 596 } |
| 595 | 597 |
| 596 DownloadItem* DownloadManagerImpl::GetActiveDownload(int32 download_id) { | 598 DownloadItem* DownloadManagerImpl::GetActiveDownload(int32 download_id) { |
| 597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 598 DownloadMap::iterator it = active_downloads_.find(download_id); | 600 DownloadMap::iterator it = active_downloads_.find(download_id); |
| 599 if (it == active_downloads_.end()) | 601 if (it == active_downloads_.end()) |
| 600 return NULL; | 602 return NULL; |
| 601 | 603 |
| 602 DownloadItem* download = it->second; | 604 DownloadItem* download = it->second; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 } | 718 } |
| 717 | 719 |
| 718 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, | 720 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, |
| 719 const GURL& referrer, | 721 const GURL& referrer, |
| 720 const std::string& referrer_charset, | 722 const std::string& referrer_charset, |
| 721 const DownloadSaveInfo& save_info, | 723 const DownloadSaveInfo& save_info, |
| 722 TabContents* tab_contents) { | 724 TabContents* tab_contents) { |
| 723 DCHECK(tab_contents); | 725 DCHECK(tab_contents); |
| 724 ResourceDispatcherHost* resource_dispatcher_host = | 726 ResourceDispatcherHost* resource_dispatcher_host = |
| 725 content::GetContentClient()->browser()->GetResourceDispatcherHost(); | 727 content::GetContentClient()->browser()->GetResourceDispatcherHost(); |
| 728 |
| 726 // We send a pointer to content::ResourceContext, instead of the usual | 729 // We send a pointer to content::ResourceContext, instead of the usual |
| 727 // reference, so that a copy of the object isn't made. | 730 // reference, so that a copy of the object isn't made. |
| 728 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. | 731 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. |
| 729 BrowserThread::PostTask( | 732 BrowserThread::PostTask( |
| 730 BrowserThread::IO, FROM_HERE, | 733 BrowserThread::IO, FROM_HERE, |
| 731 base::Bind(&BeginDownload, | 734 base::Bind(&BeginDownload, |
| 732 URLParams(url, referrer), save_info, resource_dispatcher_host, | 735 URLParams(url, referrer), save_info, resource_dispatcher_host, |
| 733 RenderParams(tab_contents->GetRenderProcessHost()->GetID(), | 736 RenderParams(tab_contents->GetRenderProcessHost()->GetID(), |
| 734 tab_contents->render_view_host()->routing_id()), | 737 tab_contents->render_view_host()->routing_id()), |
| 735 &tab_contents->browser_context()->GetResourceContext())); | 738 &tab_contents->browser_context()->GetResourceContext())); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 it != history_downloads_.end(); ++it) { | 1100 it != history_downloads_.end(); ++it) { |
| 1098 if (it->second->IsComplete() && !it->second->opened()) | 1101 if (it->second->IsComplete() && !it->second->opened()) |
| 1099 ++num_unopened; | 1102 ++num_unopened; |
| 1100 } | 1103 } |
| 1101 download_stats::RecordOpensOutstanding(num_unopened); | 1104 download_stats::RecordOpensOutstanding(num_unopened); |
| 1102 } | 1105 } |
| 1103 | 1106 |
| 1104 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1107 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
| 1105 file_manager_ = file_manager; | 1108 file_manager_ = file_manager; |
| 1106 } | 1109 } |
| OLD | NEW |