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

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

Issue 10837125: Revert 149794 - DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1228/src/
Patch Set: Created 8 years, 4 months 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) 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 download->Cancel(false); 314 download->Cancel(false);
315 if (delegate_) 315 if (delegate_)
316 delegate_->UpdateItemInPersistentStore(download); 316 delegate_->UpdateItemInPersistentStore(download);
317 } 317 }
318 } 318 }
319 319
320 // At this point, all dangerous downloads have had their files removed 320 // At this point, all dangerous downloads have had their files removed
321 // and all in progress downloads have been cancelled. We can now delete 321 // and all in progress downloads have been cancelled. We can now delete
322 // anything left. 322 // anything left.
323 323
324 // Copy downloads_ to separate container so as not to set off checks
325 // in DownloadItem destruction.
326 DownloadMap downloads_to_delete;
327 downloads_to_delete.swap(downloads_);
328
324 active_downloads_.clear(); 329 active_downloads_.clear();
325 STLDeleteValues(&downloads_); 330 STLDeleteValues(&downloads_to_delete);
326 downloads_.clear();
327 331
328 // We'll have nothing more to report to the observers after this point. 332 // We'll have nothing more to report to the observers after this point.
329 observers_.Clear(); 333 observers_.Clear();
330 334
331 file_manager_ = NULL; 335 file_manager_ = NULL;
332 if (delegate_) 336 if (delegate_)
333 delegate_->Shutdown(); 337 delegate_->Shutdown();
334 delegate_ = NULL; 338 delegate_ = NULL;
335 } 339 }
336 340
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (active_downloads_.count(download_id) == 0) 610 if (active_downloads_.count(download_id) == 0)
607 return; 611 return;
608 612
609 DownloadItemImpl* download = active_downloads_[download_id]; 613 DownloadItemImpl* download = active_downloads_[download_id];
610 download->OnAllDataSaved(size, hash); 614 download->OnAllDataSaved(size, hash);
611 MaybeCompleteDownload(download); 615 MaybeCompleteDownload(download);
612 } 616 }
613 617
614 void DownloadManagerImpl::AssertStateConsistent( 618 void DownloadManagerImpl::AssertStateConsistent(
615 DownloadItemImpl* download) const { 619 DownloadItemImpl* download) const {
620 if (download->GetState() == DownloadItem::REMOVING) {
621 DCHECK(!ContainsKey(downloads_, download->GetId()));
622 DCHECK(!ContainsKey(active_downloads_, download->GetId()));
623 return;
624 }
625
626 // Should be in downloads_ if we're not REMOVING.
616 CHECK(ContainsKey(downloads_, download->GetId())); 627 CHECK(ContainsKey(downloads_, download->GetId()));
617 628
618 int64 state = download->GetState(); 629 int64 state = download->GetState();
619 base::debug::Alias(&state); 630 base::debug::Alias(&state);
620 if (ContainsKey(active_downloads_, download->GetId())) { 631 if (ContainsKey(active_downloads_, download->GetId())) {
621 if (download->IsPersisted()) 632 if (download->IsPersisted())
622 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); 633 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState());
623 if (DownloadItem::IN_PROGRESS != download->GetState()) 634 if (DownloadItem::IN_PROGRESS != download->GetState())
624 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle()); 635 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle());
625 } 636 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return delegate_ && delegate_->GenerateFileHash(); 775 return delegate_ && delegate_->GenerateFileHash();
765 } 776 }
766 777
767 int DownloadManagerImpl::RemoveDownloadItems( 778 int DownloadManagerImpl::RemoveDownloadItems(
768 const DownloadItemImplVector& pending_deletes) { 779 const DownloadItemImplVector& pending_deletes) {
769 if (pending_deletes.empty()) 780 if (pending_deletes.empty())
770 return 0; 781 return 0;
771 782
772 // Delete from internal maps. 783 // Delete from internal maps.
773 for (DownloadItemImplVector::const_iterator it = pending_deletes.begin(); 784 for (DownloadItemImplVector::const_iterator it = pending_deletes.begin();
774 it != pending_deletes.end(); 785 it != pending_deletes.end();
775 ++it) { 786 ++it) {
776 DownloadItemImpl* download = *it; 787 DownloadItemImpl* download = *it;
777 DCHECK(download); 788 DCHECK(download);
778 int32 download_id = download->GetId(); 789 downloads_.erase(download->GetId());
779 delete download;
780 downloads_.erase(download_id);
781 } 790 }
791
792 // Tell observers to refresh their views.
782 NotifyModelChanged(); 793 NotifyModelChanged();
783 return static_cast<int>(pending_deletes.size()); 794
795 // Delete the download items themselves.
796 const int num_deleted = static_cast<int>(pending_deletes.size());
797 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
798 return num_deleted;
784 } 799 }
785 800
786 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { 801 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
787 if (!download || 802 if (!download ||
788 downloads_.find(download->GetId()) == downloads_.end()) 803 downloads_.find(download->GetId()) == downloads_.end())
789 return; 804 return;
790 805
791 // TODO(benjhayden,rdsmith): Remove this. 806 // TODO(benjhayden,rdsmith): Remove this.
792 if (!download->IsPersisted()) 807 if (!download->IsPersisted())
793 return; 808 return;
794 809
795 // Make history update. 810 // Make history update.
796 if (delegate_) 811 if (delegate_)
797 delegate_->RemoveItemFromPersistentStore(download); 812 delegate_->RemoveItemFromPersistentStore(download);
798 813
799 // Remove from our tables and delete. 814 // Remove from our tables and delete.
800 int downloads_count = 815 int downloads_count =
801 RemoveDownloadItems(DownloadItemImplVector(1, download)); 816 RemoveDownloadItems(DownloadItemImplVector(1, download));
802 DCHECK_EQ(1, downloads_count); 817 DCHECK_EQ(1, downloads_count);
803 } 818 }
804 819
805 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, 820 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
806 base::Time remove_end) { 821 base::Time remove_end) {
807 if (delegate_) 822 if (delegate_)
808 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end); 823 delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end);
809 824
825 // All downloads visible to the user will be in the history,
826 // so scan that map.
810 DownloadItemImplVector pending_deletes; 827 DownloadItemImplVector pending_deletes;
811 for (DownloadMap::const_iterator it = downloads_.begin(); 828 for (DownloadMap::const_iterator it = downloads_.begin();
812 it != downloads_.end(); 829 it != downloads_.end();
813 ++it) { 830 ++it) {
814 DownloadItemImpl* download = it->second; 831 DownloadItemImpl* download = it->second;
815 if (download->IsPersisted() && 832 if (download->IsPersisted() &&
816 download->GetStartTime() >= remove_begin && 833 download->GetStartTime() >= remove_begin &&
817 (remove_end.is_null() || download->GetStartTime() < remove_end) && 834 (remove_end.is_null() || download->GetStartTime() < remove_end) &&
818 (download->IsComplete() || download->IsCancelled())) { 835 (download->IsComplete() || download->IsCancelled())) {
819 AssertStateConsistent(download); 836 AssertStateConsistent(download);
820 download->NotifyRemoved();
821 pending_deletes.push_back(download); 837 pending_deletes.push_back(download);
822 } 838 }
823 } 839 }
824 return RemoveDownloadItems(pending_deletes); 840 return RemoveDownloadItems(pending_deletes);
825 } 841 }
826 842
827 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { 843 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) {
828 return RemoveDownloadsBetween(remove_begin, base::Time()); 844 return RemoveDownloadsBetween(remove_begin, base::Time());
829 } 845 }
830 846
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 void DownloadManagerImpl::DownloadRenamedToFinalName( 1115 void DownloadManagerImpl::DownloadRenamedToFinalName(
1100 DownloadItemImpl* download) { 1116 DownloadItemImpl* download) {
1101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1102 // If the rename failed, we receive an OnDownloadInterrupted() call before we 1118 // If the rename failed, we receive an OnDownloadInterrupted() call before we
1103 // receive the DownloadRenamedToFinalName() call. 1119 // receive the DownloadRenamedToFinalName() call.
1104 if (delegate_) { 1120 if (delegate_) {
1105 delegate_->UpdatePathForItemInPersistentStore( 1121 delegate_->UpdatePathForItemInPersistentStore(
1106 download, download->GetFullPath()); 1122 download, download->GetFullPath());
1107 } 1123 }
1108 } 1124 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | content/browser/download/drag_download_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698