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

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

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with trunk Created 9 years, 1 month 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.h" 5 #include "content/browser/download/download_manager.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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { 285 void DownloadManager::OnFileRemovalDetected(int64 db_handle) {
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
287 DownloadMap::iterator it = history_downloads_.find(db_handle); 287 DownloadMap::iterator it = history_downloads_.find(db_handle);
288 if (it != history_downloads_.end()) { 288 if (it != history_downloads_.end()) {
289 DownloadItem* download_item = it->second; 289 DownloadItem* download_item = it->second;
290 download_item->OnDownloadedFileRemoved(); 290 download_item->OnDownloadedFileRemoved();
291 } 291 }
292 } 292 }
293 293
294 void DownloadManager::RestartDownload( 294 void DownloadManager::RestartDownload(int32 download_id) {
295 int32 download_id) {
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
297 296
298 DownloadItem* download = GetActiveDownloadItem(download_id); 297 DownloadItem* download = GetActiveDownloadItem(download_id);
299 if (!download) 298 if (!download)
300 return; 299 return;
301 300
302 VLOG(20) << __FUNCTION__ << "()" 301 VLOG(20) << __FUNCTION__ << "()"
303 << " download = " << download->DebugString(true); 302 << " download = " << download->DebugString(true);
304 303
305 FilePath suggested_path = download->suggested_path(); 304 FilePath suggested_path = download->suggested_path();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 BrowserThread::FILE, FROM_HERE, 372 BrowserThread::FILE, FROM_HERE,
374 NewRunnableMethod( 373 NewRunnableMethod(
375 file_manager_, &DownloadFileManager::RenameInProgressDownloadFile, 374 file_manager_, &DownloadFileManager::RenameInProgressDownloadFile,
376 download->global_id(), download_path)); 375 download->global_id(), download_path));
377 376
378 download->Rename(download_path); 377 download->Rename(download_path);
379 378
380 delegate_->AddItemToPersistentStore(download); 379 delegate_->AddItemToPersistentStore(download);
381 } 380 }
382 381
383 void DownloadManager::UpdateDownload(int32 download_id, int64 size) { 382 void DownloadManager::UpdateDownload(int32 download_id, int64 size,
383 const std::string& partial_hash) {
384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
385 DownloadMap::iterator it = active_downloads_.find(download_id); 385 DownloadMap::iterator it = active_downloads_.find(download_id);
386 if (it != active_downloads_.end()) { 386 if (it != active_downloads_.end()) {
387 DownloadItem* download = it->second; 387 DownloadItem* download = it->second;
388 if (download->IsInProgress()) { 388 if (download->IsInProgress()) {
389 download->Update(size); 389 download->Update(size, partial_hash);
390 UpdateDownloadProgress(); // Reflect size updates. 390 UpdateDownloadProgress(); // Reflect size updates.
391 delegate_->UpdateItemInPersistentStore(download); 391 delegate_->UpdateItemInPersistentStore(download);
392 } 392 }
393 } 393 }
394 } 394 }
395 395
396 void DownloadManager::OnResponseCompleted(int32 download_id, 396 void DownloadManager::OnResponseCompleted(int32 download_id,
397 int64 size, 397 int64 size,
398 const std::string& hash) { 398 const std::string& hash) {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
400 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id 400 VLOG(20) << __FUNCTION__ << "()" << " download_id = " << download_id
401 << " size = " << size; 401 << " size = " << size;
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
403 403
404 // If it's not in active_downloads_, that means it was cancelled; just 404 // If it's not in active_downloads_, that means it was cancelled; just
405 // ignore the notification. 405 // ignore the notification.
406 if (active_downloads_.count(download_id) == 0) 406 if (active_downloads_.count(download_id) == 0)
407 return; 407 return;
408 408
409 DownloadItem* download = active_downloads_[download_id]; 409 DownloadItem* download = active_downloads_[download_id];
410 download->OnAllDataSaved(size); 410 download->OnAllDataSaved(size, hash);
411 411
412 delegate_->OnResponseCompleted(download, hash); 412 delegate_->OnResponseCompleted(download, hash);
413 413
414 MaybeCompleteDownload(download); 414 MaybeCompleteDownload(download);
415 } 415 }
416 416
417 void DownloadManager::AssertQueueStateConsistent(DownloadItem* download) { 417 void DownloadManager::AssertQueueStateConsistent(DownloadItem* download) {
418 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 418 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
419 if (download->state() == DownloadItem::REMOVING) { 419 if (download->state() == DownloadItem::REMOVING) {
420 CHECK(!ContainsKey(downloads_, download)); 420 CHECK(!ContainsKey(downloads_, download));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 RemoveFromActiveList(download); 565 RemoveFromActiveList(download);
566 // This function is called from the DownloadItem, so DI state 566 // This function is called from the DownloadItem, so DI state
567 // should already have been updated. 567 // should already have been updated.
568 AssertQueueStateConsistent(download); 568 AssertQueueStateConsistent(download);
569 569
570 download->OffThreadCancel(file_manager_); 570 download->OffThreadCancel(file_manager_);
571 } 571 }
572 572
573 void DownloadManager::OnDownloadInterrupted(int32 download_id, 573 void DownloadManager::OnDownloadInterrupted(int32 download_id,
574 int64 size, 574 int64 size,
575 const std::string partial_hash,
575 InterruptReason reason) { 576 InterruptReason reason) {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
577 578
578 DownloadItem* download = GetActiveDownload(download_id); 579 DownloadItem* download = GetActiveDownload(download_id);
579 if (!download) 580 if (!download)
580 return; 581 return;
581 582
582 VLOG(20) << __FUNCTION__ << "()" 583 VLOG(20) << __FUNCTION__ << "()"
583 << " reason " << InterruptReasonDebugString(reason) 584 << " reason " << InterruptReasonDebugString(reason)
584 << " at offset " << download->received_bytes() 585 << " at offset " << download->received_bytes()
585 << " size = " << size 586 << " size = " << size
586 << " download = " << download->DebugString(true); 587 << " download = " << download->DebugString(true);
587 588
588 RemoveFromActiveList(download); 589 RemoveFromActiveList(download);
589 download->Interrupted(size, reason); 590 download->Interrupted(size, partial_hash, reason);
590 download->OffThreadCancel(file_manager_); 591 download->OffThreadCancel(file_manager_);
591 } 592 }
592 593
593 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { 594 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) {
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
595 DownloadMap::iterator it = active_downloads_.find(download_id); 596 DownloadMap::iterator it = active_downloads_.find(download_id);
596 if (it == active_downloads_.end()) 597 if (it == active_downloads_.end())
597 return NULL; 598 return NULL;
598 599
599 DownloadItem* download = it->second; 600 DownloadItem* download = it->second;
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { 1086 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1086 delegate_->UpdateItemInPersistentStore(download); 1087 delegate_->UpdateItemInPersistentStore(download);
1087 int num_unopened = 0; 1088 int num_unopened = 0;
1088 for (DownloadMap::iterator it = history_downloads_.begin(); 1089 for (DownloadMap::iterator it = history_downloads_.begin();
1089 it != history_downloads_.end(); ++it) { 1090 it != history_downloads_.end(); ++it) {
1090 if (it->second->IsComplete() && !it->second->opened()) 1091 if (it->second->IsComplete() && !it->second->opened())
1091 ++num_unopened; 1092 ++num_unopened;
1092 } 1093 }
1093 download_stats::RecordOpensOutstanding(num_unopened); 1094 download_stats::RecordOpensOutstanding(num_unopened);
1094 } 1095 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698