Chromium Code Reviews| 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/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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 | 632 |
| 633 // Confirm we're in the proper set of states to be here; | 633 // Confirm we're in the proper set of states to be here; |
| 634 // in in_progress_, have all data, have a history handle, (validated or safe). | 634 // in in_progress_, have all data, have a history handle, (validated or safe). |
| 635 DCHECK_NE(DownloadItem::DANGEROUS, download->GetSafetyState()); | 635 DCHECK_NE(DownloadItem::DANGEROUS, download->GetSafetyState()); |
| 636 DCHECK_EQ(1u, in_progress_.count(download->GetId())); | 636 DCHECK_EQ(1u, in_progress_.count(download->GetId())); |
| 637 DCHECK(download->AllDataSaved()); | 637 DCHECK(download->AllDataSaved()); |
| 638 DCHECK(download->IsPersisted()); | 638 DCHECK(download->IsPersisted()); |
| 639 DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle())); | 639 DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle())); |
| 640 | 640 |
| 641 // Give the delegate a chance to override. | 641 // Give the delegate a chance to override. |
| 642 if (!delegate_->ShouldCompleteDownload(download)) | 642 // It's ok to keep re-setting the delegate's |maybe_complete_download| cb as |
| 643 // long as there isn't another call-point trying to set it to a different cb. | |
| 644 // TODO(benjhayden): Change the callback to point directly to the item instead | |
| 645 // of |this| when DownloadItem supports weak-ptrs. | |
| 646 if (!delegate_->ShouldCompleteDownload(download, base::Bind( | |
| 647 &DownloadManagerImpl::MaybeCompleteDownloadById, | |
|
Randy Smith (Not in Mondays)
2012/05/01 18:21:49
Hmmm. I see why you're doing this. Another alter
benjhayden
2012/05/01 19:00:30
The new routine with its lookup seems safer.
| |
| 648 this, download->GetId()))) | |
| 643 return; | 649 return; |
| 644 | 650 |
| 645 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " | 651 VLOG(20) << __FUNCTION__ << "()" << " executing: download = " |
| 646 << download->DebugString(false); | 652 << download->DebugString(false); |
| 647 | 653 |
| 648 // Remove the id from in_progress | 654 // Remove the id from in_progress |
| 649 in_progress_.erase(download->GetId()); | 655 in_progress_.erase(download->GetId()); |
| 650 | 656 |
| 651 delegate_->UpdateItemInPersistentStore(download); | 657 delegate_->UpdateItemInPersistentStore(download); |
| 652 | 658 |
| 653 // Finish the download. | 659 // Finish the download. |
| 654 download->OnDownloadCompleting(file_manager_); | 660 download->OnDownloadCompleting(file_manager_); |
| 655 } | 661 } |
| 656 | 662 |
| 663 void DownloadManagerImpl::MaybeCompleteDownloadById(int download_id) { | |
| 664 DownloadItem* download_item = GetActiveDownload(download_id); | |
| 665 if (download_item != NULL) | |
| 666 MaybeCompleteDownload(download_item); | |
| 667 } | |
| 668 | |
| 657 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) { | 669 void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) { |
| 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 659 DCHECK(download); | 671 DCHECK(download); |
| 660 delegate_->UpdateItemInPersistentStore(download); | 672 delegate_->UpdateItemInPersistentStore(download); |
| 661 active_downloads_.erase(download->GetId()); | 673 active_downloads_.erase(download->GetId()); |
| 662 AssertStateConsistent(download); | 674 AssertStateConsistent(download); |
| 663 } | 675 } |
| 664 | 676 |
| 665 void DownloadManagerImpl::OnDownloadRenamedToFinalName( | 677 void DownloadManagerImpl::OnDownloadRenamedToFinalName( |
| 666 int download_id, | 678 int download_id, |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1208 if (it->second->IsComplete() && !it->second->GetOpened()) | 1220 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1209 ++num_unopened; | 1221 ++num_unopened; |
| 1210 } | 1222 } |
| 1211 download_stats::RecordOpensOutstanding(num_unopened); | 1223 download_stats::RecordOpensOutstanding(num_unopened); |
| 1212 } | 1224 } |
| 1213 | 1225 |
| 1214 void DownloadManagerImpl::SetFileManagerForTesting( | 1226 void DownloadManagerImpl::SetFileManagerForTesting( |
| 1215 DownloadFileManager* file_manager) { | 1227 DownloadFileManager* file_manager) { |
| 1216 file_manager_ = file_manager; | 1228 file_manager_ = file_manager; |
| 1217 } | 1229 } |
| OLD | NEW |