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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 download->Cancel(false); | 310 download->Cancel(false); |
311 if (delegate_) | 311 if (delegate_) |
312 delegate_->UpdateItemInPersistentStore(download); | 312 delegate_->UpdateItemInPersistentStore(download); |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 // At this point, all dangerous downloads have had their files removed | 316 // At this point, all dangerous downloads have had their files removed |
317 // and all in progress downloads have been cancelled. We can now delete | 317 // and all in progress downloads have been cancelled. We can now delete |
318 // anything left. | 318 // anything left. |
319 | 319 |
320 // Copy downloads_ to separate container so as not to set off checks | |
321 // in DownloadItem destruction. | |
322 DownloadMap downloads_to_delete; | |
323 downloads_to_delete.swap(downloads_); | |
324 | |
325 active_downloads_.clear(); | 320 active_downloads_.clear(); |
326 STLDeleteValues(&downloads_to_delete); | 321 STLDeleteValues(&downloads_); |
Randy Smith (Not in Mondays)
2012/07/14 19:25:53
Shouldn't we also do a downloads_.clear() here? W
benjhayden
2012/07/23 15:43:09
Done.
| |
327 | 322 |
328 // We'll have nothing more to report to the observers after this point. | 323 // We'll have nothing more to report to the observers after this point. |
329 observers_.Clear(); | 324 observers_.Clear(); |
330 | 325 |
331 file_manager_ = NULL; | 326 file_manager_ = NULL; |
332 if (delegate_) | 327 if (delegate_) |
333 delegate_->Shutdown(); | 328 delegate_->Shutdown(); |
334 } | 329 } |
335 | 330 |
336 void DownloadManagerImpl::GetTemporaryDownloads( | 331 void DownloadManagerImpl::GetTemporaryDownloads( |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 // ignore the notification. | 624 // ignore the notification. |
630 if (active_downloads_.count(download_id) == 0) | 625 if (active_downloads_.count(download_id) == 0) |
631 return; | 626 return; |
632 | 627 |
633 DownloadItem* download = active_downloads_[download_id]; | 628 DownloadItem* download = active_downloads_[download_id]; |
634 download->OnAllDataSaved(size, hash); | 629 download->OnAllDataSaved(size, hash); |
635 MaybeCompleteDownload(download); | 630 MaybeCompleteDownload(download); |
636 } | 631 } |
637 | 632 |
638 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const { | 633 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const { |
639 if (download->GetState() == DownloadItem::REMOVING) { | |
640 DCHECK(!ContainsKey(downloads_, download->GetId())); | |
641 DCHECK(!ContainsKey(active_downloads_, download->GetId())); | |
642 return; | |
643 } | |
644 | |
645 // Should be in downloads_ if we're not REMOVING. | |
646 CHECK(ContainsKey(downloads_, download->GetId())); | 634 CHECK(ContainsKey(downloads_, download->GetId())); |
647 | 635 |
648 int64 state = download->GetState(); | 636 int64 state = download->GetState(); |
649 base::debug::Alias(&state); | 637 base::debug::Alias(&state); |
650 if (ContainsKey(active_downloads_, download->GetId())) { | 638 if (ContainsKey(active_downloads_, download->GetId())) { |
651 if (download->IsPersisted()) | 639 if (download->IsPersisted()) |
652 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 640 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
653 if (DownloadItem::IN_PROGRESS != download->GetState()) | 641 if (DownloadItem::IN_PROGRESS != download->GetState()) |
654 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle()); | 642 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle()); |
655 } | 643 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 | 800 |
813 bool DownloadManagerImpl::GenerateFileHash() { | 801 bool DownloadManagerImpl::GenerateFileHash() { |
814 return delegate_ && delegate_->GenerateFileHash(); | 802 return delegate_ && delegate_->GenerateFileHash(); |
815 } | 803 } |
816 | 804 |
817 int DownloadManagerImpl::RemoveDownloadItems( | 805 int DownloadManagerImpl::RemoveDownloadItems( |
818 const DownloadVector& pending_deletes) { | 806 const DownloadVector& pending_deletes) { |
819 if (pending_deletes.empty()) | 807 if (pending_deletes.empty()) |
820 return 0; | 808 return 0; |
821 | 809 |
822 // Delete from internal maps. | |
823 for (DownloadVector::const_iterator it = pending_deletes.begin(); | 810 for (DownloadVector::const_iterator it = pending_deletes.begin(); |
824 it != pending_deletes.end(); | 811 it != pending_deletes.end(); |
825 ++it) { | 812 ++it) { |
826 DownloadItem* download = *it; | 813 DownloadItem* download = *it; |
827 DCHECK(download); | 814 DCHECK(download); |
828 downloads_.erase(download->GetId()); | 815 int32 download_id = download->GetId(); |
816 delete download; | |
817 downloads_.erase(download_id); | |
829 } | 818 } |
830 | |
831 // Tell observers to refresh their views. | |
832 NotifyModelChanged(); | 819 NotifyModelChanged(); |
833 | 820 return static_cast<int>(pending_deletes.size()); |
834 // Delete the download items themselves. | |
835 const int num_deleted = static_cast<int>(pending_deletes.size()); | |
836 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); | |
837 return num_deleted; | |
838 } | 821 } |
839 | 822 |
840 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) { | 823 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) { |
841 if (!download || | 824 if (!download || |
842 downloads_.find(download->GetId()) == downloads_.end()) | 825 downloads_.find(download->GetId()) == downloads_.end()) |
843 return; | 826 return; |
844 | 827 |
845 // TODO(benjhayden,rdsmith): Remove this. | 828 // TODO(benjhayden,rdsmith): Remove this. |
846 if (!download->IsPersisted()) | 829 if (!download->IsPersisted()) |
847 return; | 830 return; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1186 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1169 void DownloadManagerImpl::DownloadRenamedToFinalName( |
1187 DownloadItem* download) { | 1170 DownloadItem* download) { |
1188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1189 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1172 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
1190 // receive the DownloadRenamedToFinalName() call. | 1173 // receive the DownloadRenamedToFinalName() call. |
1191 if (delegate_) { | 1174 if (delegate_) { |
1192 delegate_->UpdatePathForItemInPersistentStore( | 1175 delegate_->UpdatePathForItemInPersistentStore( |
1193 download, download->GetFullPath()); | 1176 download, download->GetFullPath()); |
1194 } | 1177 } |
1195 } | 1178 } |
OLD | NEW |