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

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

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment. Created 9 years 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) 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 void DownloadManagerImpl::OnFileRemovalDetected(int64 db_handle) { 286 void DownloadManagerImpl::OnFileRemovalDetected(int64 db_handle) {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
288 DownloadMap::iterator it = history_downloads_.find(db_handle); 288 DownloadMap::iterator it = history_downloads_.find(db_handle);
289 if (it != history_downloads_.end()) { 289 if (it != history_downloads_.end()) {
290 DownloadItem* download_item = it->second; 290 DownloadItem* download_item = it->second;
291 download_item->OnDownloadedFileRemoved(); 291 download_item->OnDownloadedFileRemoved();
292 } 292 }
293 } 293 }
294 294
295 void DownloadManagerImpl::RestartDownload( 295 void DownloadManagerImpl::RestartDownload(int32 download_id) {
296 int32 download_id) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
298 297
299 DownloadItem* download = GetActiveDownloadItem(download_id); 298 DownloadItem* download = GetActiveDownloadItem(download_id);
300 if (!download) 299 if (!download)
301 return; 300 return;
302 301
303 VLOG(20) << __FUNCTION__ << "()" 302 VLOG(20) << __FUNCTION__ << "()"
304 << " download = " << download->DebugString(true); 303 << " download = " << download->DebugString(true);
305 304
306 FilePath suggested_path = download->GetSuggestedPath(); 305 FilePath suggested_path = download->GetSuggestedPath();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 BrowserThread::FILE, FROM_HERE, 412 BrowserThread::FILE, FROM_HERE,
414 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, 413 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile,
415 file_manager_, download->GetGlobalId(), 414 file_manager_, download->GetGlobalId(),
416 download_path)); 415 download_path));
417 416
418 download->Rename(download_path); 417 download->Rename(download_path);
419 418
420 delegate_->AddItemToPersistentStore(download); 419 delegate_->AddItemToPersistentStore(download);
421 } 420 }
422 421
423 void DownloadManagerImpl::UpdateDownload(int32 download_id, int64 bytes_so_far, 422 void DownloadManagerImpl::UpdateDownload(int32 download_id,
424 int64 bytes_per_sec) { 423 int64 bytes_so_far,
424 int64 bytes_per_sec,
425 std::string hash_state) {
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
426 DownloadMap::iterator it = active_downloads_.find(download_id); 427 DownloadMap::iterator it = active_downloads_.find(download_id);
427 if (it != active_downloads_.end()) { 428 if (it != active_downloads_.end()) {
428 DownloadItem* download = it->second; 429 DownloadItem* download = it->second;
429 if (download->IsInProgress()) { 430 if (download->IsInProgress()) {
430 download->UpdateProgress(bytes_so_far, bytes_per_sec); 431 download->UpdateProgress(bytes_so_far, bytes_per_sec, hash_state);
431 UpdateDownloadProgress(); // Reflect size updates. 432 UpdateDownloadProgress(); // Reflect size updates.
432 delegate_->UpdateItemInPersistentStore(download); 433 delegate_->UpdateItemInPersistentStore(download);
433 } 434 }
434 } 435 }
435 } 436 }
436 437
437 void DownloadManagerImpl::OnResponseCompleted(int32 download_id, 438 void DownloadManagerImpl::OnResponseCompleted(int32 download_id,
438 int64 size, 439 int64 size,
439 const std::string& hash) { 440 const std::string& hash) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 // This function is called from the DownloadItem, so DI state 614 // This function is called from the DownloadItem, so DI state
614 // should already have been updated. 615 // should already have been updated.
615 AssertStateConsistent(download); 616 AssertStateConsistent(download);
616 617
617 if (file_manager_) 618 if (file_manager_)
618 download->OffThreadCancel(file_manager_); 619 download->OffThreadCancel(file_manager_);
619 } 620 }
620 621
621 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id, 622 void DownloadManagerImpl::OnDownloadInterrupted(int32 download_id,
622 int64 size, 623 int64 size,
624 std::string hash_state,
623 InterruptReason reason) { 625 InterruptReason reason) {
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
625 627
626 DownloadItem* download = GetActiveDownload(download_id); 628 DownloadItem* download = GetActiveDownload(download_id);
627 if (!download) 629 if (!download)
628 return; 630 return;
629 631
630 VLOG(20) << __FUNCTION__ << "()" 632 VLOG(20) << __FUNCTION__ << "()"
631 << " reason " << InterruptReasonDebugString(reason) 633 << " reason " << InterruptReasonDebugString(reason)
632 << " at offset " << download->GetReceivedBytes() 634 << " at offset " << download->GetReceivedBytes()
633 << " size = " << size 635 << " size = " << size
634 << " download = " << download->DebugString(true); 636 << " download = " << download->DebugString(true);
635 637
636 RemoveFromActiveList(download); 638 RemoveFromActiveList(download);
637 download->Interrupted(size, reason); 639 download->Interrupted(size, hash_state, reason);
638 download->OffThreadCancel(file_manager_); 640 download->OffThreadCancel(file_manager_);
639 } 641 }
640 642
641 DownloadItem* DownloadManagerImpl::GetActiveDownload(int32 download_id) { 643 DownloadItem* DownloadManagerImpl::GetActiveDownload(int32 download_id) {
642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
643 DownloadMap::iterator it = active_downloads_.find(download_id); 645 DownloadMap::iterator it = active_downloads_.find(download_id);
644 if (it == active_downloads_.end()) 646 if (it == active_downloads_.end())
645 return NULL; 647 return NULL;
646 648
647 DownloadItem* download = it->second; 649 DownloadItem* download = it->second;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 762 }
761 763
762 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url, 764 void DownloadManagerImpl::DownloadUrlToFile(const GURL& url,
763 const GURL& referrer, 765 const GURL& referrer,
764 const std::string& referrer_charset, 766 const std::string& referrer_charset,
765 const DownloadSaveInfo& save_info, 767 const DownloadSaveInfo& save_info,
766 TabContents* tab_contents) { 768 TabContents* tab_contents) {
767 DCHECK(tab_contents); 769 DCHECK(tab_contents);
768 ResourceDispatcherHost* resource_dispatcher_host = 770 ResourceDispatcherHost* resource_dispatcher_host =
769 content::GetContentClient()->browser()->GetResourceDispatcherHost(); 771 content::GetContentClient()->browser()->GetResourceDispatcherHost();
772
770 // We send a pointer to content::ResourceContext, instead of the usual 773 // We send a pointer to content::ResourceContext, instead of the usual
771 // reference, so that a copy of the object isn't made. 774 // reference, so that a copy of the object isn't made.
772 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. 775 // base::Bind can't handle 7 args, so we use URLParams and RenderParams.
773 BrowserThread::PostTask( 776 BrowserThread::PostTask(
774 BrowserThread::IO, FROM_HERE, 777 BrowserThread::IO, FROM_HERE,
775 base::Bind(&BeginDownload, 778 base::Bind(&BeginDownload,
776 URLParams(url, referrer), save_info, resource_dispatcher_host, 779 URLParams(url, referrer), save_info, resource_dispatcher_host,
777 RenderParams(tab_contents->GetRenderProcessHost()->GetID(), 780 RenderParams(tab_contents->GetRenderProcessHost()->GetID(),
778 tab_contents->render_view_host()->routing_id()), 781 tab_contents->render_view_host()->routing_id()),
779 &tab_contents->browser_context()->GetResourceContext())); 782 &tab_contents->browser_context()->GetResourceContext()));
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 it != history_downloads_.end(); ++it) { 1134 it != history_downloads_.end(); ++it) {
1132 if (it->second->IsComplete() && !it->second->GetOpened()) 1135 if (it->second->IsComplete() && !it->second->GetOpened())
1133 ++num_unopened; 1136 ++num_unopened;
1134 } 1137 }
1135 download_stats::RecordOpensOutstanding(num_unopened); 1138 download_stats::RecordOpensOutstanding(num_unopened);
1136 } 1139 }
1137 1140
1138 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { 1141 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) {
1139 file_manager_ = file_manager; 1142 file_manager_ = file_manager;
1140 } 1143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698