| 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.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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { | 275 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { |
| 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 DownloadMap::iterator it = history_downloads_.find(db_handle); | 277 DownloadMap::iterator it = history_downloads_.find(db_handle); |
| 278 if (it != history_downloads_.end()) { | 278 if (it != history_downloads_.end()) { |
| 279 DownloadItem* download_item = it->second; | 279 DownloadItem* download_item = it->second; |
| 280 download_item->OnDownloadedFileRemoved(); | 280 download_item->OnDownloadedFileRemoved(); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 void DownloadManager::RestartDownload( | 284 void DownloadManager::RestartDownload(int32 download_id) { |
| 285 int32 download_id) { | |
| 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 287 | 286 |
| 288 DownloadItem* download = GetActiveDownloadItem(download_id); | 287 DownloadItem* download = GetActiveDownloadItem(download_id); |
| 289 if (!download) | 288 if (!download) |
| 290 return; | 289 return; |
| 291 | 290 |
| 292 VLOG(20) << __FUNCTION__ << "()" | 291 VLOG(20) << __FUNCTION__ << "()" |
| 293 << " download = " << download->DebugString(true); | 292 << " download = " << download->DebugString(true); |
| 294 | 293 |
| 295 FilePath suggested_path = download->suggested_path(); | 294 FilePath suggested_path = download->suggested_path(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
| 361 BrowserThread::FILE, FROM_HERE, | 360 BrowserThread::FILE, FROM_HERE, |
| 362 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, | 361 base::Bind(&DownloadFileManager::RenameInProgressDownloadFile, |
| 363 file_manager_, download->global_id(), download_path)); | 362 file_manager_, download->global_id(), download_path)); |
| 364 | 363 |
| 365 download->Rename(download_path); | 364 download->Rename(download_path); |
| 366 | 365 |
| 367 delegate_->AddItemToPersistentStore(download); | 366 delegate_->AddItemToPersistentStore(download); |
| 368 } | 367 } |
| 369 | 368 |
| 370 void DownloadManager::UpdateDownload(int32 download_id, int64 size) { | 369 void DownloadManager::UpdateDownload(int32 download_id, int64 size, |
| 370 const std::string& partial_hash) { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 372 DownloadMap::iterator it = active_downloads_.find(download_id); | 372 DownloadMap::iterator it = active_downloads_.find(download_id); |
| 373 if (it != active_downloads_.end()) { | 373 if (it != active_downloads_.end()) { |
| 374 DownloadItem* download = it->second; | 374 DownloadItem* download = it->second; |
| 375 if (download->IsInProgress()) { | 375 if (download->IsInProgress()) { |
| 376 download->Update(size); | 376 download->Update(size, partial_hash); |
| 377 UpdateDownloadProgress(); // Reflect size updates. | 377 UpdateDownloadProgress(); // Reflect size updates. |
| 378 delegate_->UpdateItemInPersistentStore(download); | 378 delegate_->UpdateItemInPersistentStore(download); |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 void DownloadManager::OnResponseCompleted(int32 download_id, | 383 void DownloadManager::OnResponseCompleted(int32 download_id, |
| 384 int64 size, | 384 int64 size, |
| 385 const std::string& hash) { | 385 const std::string& hash) { |
| 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // This function is called from the DownloadItem, so DI state | 556 // This function is called from the DownloadItem, so DI state |
| 557 // should already have been updated. | 557 // should already have been updated. |
| 558 AssertQueueStateConsistent(download); | 558 AssertQueueStateConsistent(download); |
| 559 | 559 |
| 560 if (file_manager_) | 560 if (file_manager_) |
| 561 download->OffThreadCancel(file_manager_); | 561 download->OffThreadCancel(file_manager_); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void DownloadManager::OnDownloadInterrupted(int32 download_id, | 564 void DownloadManager::OnDownloadInterrupted(int32 download_id, |
| 565 int64 size, | 565 int64 size, |
| 566 const std::string partial_hash, |
| 566 InterruptReason reason) { | 567 InterruptReason reason) { |
| 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 568 | 569 |
| 569 DownloadItem* download = GetActiveDownload(download_id); | 570 DownloadItem* download = GetActiveDownload(download_id); |
| 570 if (!download) | 571 if (!download) |
| 571 return; | 572 return; |
| 572 | 573 |
| 573 VLOG(20) << __FUNCTION__ << "()" | 574 VLOG(20) << __FUNCTION__ << "()" |
| 574 << " reason " << InterruptReasonDebugString(reason) | 575 << " reason " << InterruptReasonDebugString(reason) |
| 575 << " at offset " << download->received_bytes() | 576 << " at offset " << download->received_bytes() |
| 576 << " size = " << size | 577 << " size = " << size |
| 577 << " download = " << download->DebugString(true); | 578 << " download = " << download->DebugString(true); |
| 578 | 579 |
| 579 RemoveFromActiveList(download); | 580 RemoveFromActiveList(download); |
| 580 download->Interrupted(size, reason); | 581 download->Interrupted(size, partial_hash, reason); |
| 581 download->OffThreadCancel(file_manager_); | 582 download->OffThreadCancel(file_manager_); |
| 582 } | 583 } |
| 583 | 584 |
| 584 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { | 585 DownloadItem* DownloadManager::GetActiveDownload(int32 download_id) { |
| 585 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 586 DownloadMap::iterator it = active_downloads_.find(download_id); | 587 DownloadMap::iterator it = active_downloads_.find(download_id); |
| 587 if (it == active_downloads_.end()) | 588 if (it == active_downloads_.end()) |
| 588 return NULL; | 589 return NULL; |
| 589 | 590 |
| 590 DownloadItem* download = it->second; | 591 DownloadItem* download = it->second; |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { | 1074 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { |
| 1074 delegate_->UpdateItemInPersistentStore(download); | 1075 delegate_->UpdateItemInPersistentStore(download); |
| 1075 int num_unopened = 0; | 1076 int num_unopened = 0; |
| 1076 for (DownloadMap::iterator it = history_downloads_.begin(); | 1077 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 1077 it != history_downloads_.end(); ++it) { | 1078 it != history_downloads_.end(); ++it) { |
| 1078 if (it->second->IsComplete() && !it->second->opened()) | 1079 if (it->second->IsComplete() && !it->second->opened()) |
| 1079 ++num_unopened; | 1080 ++num_unopened; |
| 1080 } | 1081 } |
| 1081 download_stats::RecordOpensOutstanding(num_unopened); | 1082 download_stats::RecordOpensOutstanding(num_unopened); |
| 1082 } | 1083 } |
| OLD | NEW |