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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 5 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 } 292 }
293 293
294 // At this point, all dangerous downloads have had their files removed 294 // At this point, all dangerous downloads have had their files removed
295 // and all in progress downloads have been cancelled. We can now delete 295 // and all in progress downloads have been cancelled. We can now delete
296 // anything left. 296 // anything left.
297 297
298 // Copy downloads_ to separate container so as not to set off checks 298 // Copy downloads_ to separate container so as not to set off checks
299 // in DownloadItem destruction. 299 // in DownloadItem destruction.
300 DownloadMap downloads_to_delete; 300 DownloadMap downloads_to_delete;
301 downloads_to_delete.swap(downloads_);
302 301
303 active_downloads_.clear(); 302 active_downloads_.clear();
304 STLDeleteValues(&downloads_to_delete); 303 STLDeleteValues(&downloads_to_delete);
304 downloads_to_delete.swap(downloads_);
Randy Smith (Not in Mondays) 2012/07/11 17:55:37 Is there a reason for moving this line? (I don't
benjhayden 2012/07/13 20:03:17 ~DownloadItemImpl() calls AssertStateConsistent()
305 305
306 // We'll have nothing more to report to the observers after this point. 306 // We'll have nothing more to report to the observers after this point.
307 observers_.Clear(); 307 observers_.Clear();
308 308
309 DCHECK(save_page_downloads_.empty()); 309 DCHECK(save_page_downloads_.empty());
310 310
311 file_manager_ = NULL; 311 file_manager_ = NULL;
312 if (delegate_) 312 if (delegate_)
313 delegate_->Shutdown(); 313 delegate_->Shutdown();
314 } 314 }
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // ignore the notification. 608 // ignore the notification.
609 if (active_downloads_.count(download_id) == 0) 609 if (active_downloads_.count(download_id) == 0)
610 return; 610 return;
611 611
612 DownloadItem* download = active_downloads_[download_id]; 612 DownloadItem* download = active_downloads_[download_id];
613 download->OnAllDataSaved(size, hash); 613 download->OnAllDataSaved(size, hash);
614 MaybeCompleteDownload(download); 614 MaybeCompleteDownload(download);
615 } 615 }
616 616
617 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const { 617 void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const {
618 if (download->GetState() == DownloadItem::REMOVING) {
619 DCHECK(!ContainsKey(downloads_, download->GetId()));
620 DCHECK(!ContainsKey(active_downloads_, download->GetId()));
621 return;
622 }
623
624 // Should be in downloads_ if we're not REMOVING.
625 CHECK(ContainsKey(downloads_, download->GetId())); 618 CHECK(ContainsKey(downloads_, download->GetId()));
626 619
627 int64 state = download->GetState(); 620 int64 state = download->GetState();
628 base::debug::Alias(&state); 621 base::debug::Alias(&state);
629 if (ContainsKey(active_downloads_, download->GetId())) { 622 if (ContainsKey(active_downloads_, download->GetId())) {
630 if (download->IsPersisted()) 623 if (download->IsPersisted())
631 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState()); 624 CHECK_EQ(DownloadItem::IN_PROGRESS, download->GetState());
632 if (DownloadItem::IN_PROGRESS != download->GetState()) 625 if (DownloadItem::IN_PROGRESS != download->GetState())
633 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle()); 626 CHECK_EQ(DownloadItem::kUninitializedHandle, download->GetDbHandle());
634 } 627 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 784
792 bool DownloadManagerImpl::GenerateFileHash() { 785 bool DownloadManagerImpl::GenerateFileHash() {
793 return delegate_ && delegate_->GenerateFileHash(); 786 return delegate_ && delegate_->GenerateFileHash();
794 } 787 }
795 788
796 int DownloadManagerImpl::RemoveDownloadItems( 789 int DownloadManagerImpl::RemoveDownloadItems(
797 const DownloadVector& pending_deletes) { 790 const DownloadVector& pending_deletes) {
798 if (pending_deletes.empty()) 791 if (pending_deletes.empty())
799 return 0; 792 return 0;
800 793
794 std::vector<int32> deleting_ids;
795
801 // Delete from internal maps. 796 // Delete from internal maps.
802 for (DownloadVector::const_iterator it = pending_deletes.begin(); 797 for (DownloadVector::const_iterator it = pending_deletes.begin();
803 it != pending_deletes.end(); 798 it != pending_deletes.end();
804 ++it) { 799 ++it) {
805 DownloadItem* download = *it; 800 DownloadItem* download = *it;
806 DCHECK(download); 801 DCHECK(download);
807 save_page_downloads_.erase(download->GetId()); 802 deleting_ids.push_back(download->GetId());
808 downloads_.erase(download->GetId());
809 } 803 }
810 804
811 // Tell observers to refresh their views. 805 // Tell observers to refresh their views.
812 NotifyModelChanged(); 806 NotifyModelChanged();
813 807
814 // Delete the download items themselves. 808 // Delete the download items themselves.
815 const int num_deleted = static_cast<int>(pending_deletes.size()); 809 const int num_deleted = static_cast<int>(pending_deletes.size());
816 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); 810 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
811
812 for (std::vector<int32>::const_iterator it = deleting_ids.begin();
813 it != deleting_ids.end();
814 ++it) {
815 save_page_downloads_.erase(*it);
816 downloads_.erase(*it);
817 }
818
Randy Smith (Not in Mondays) 2012/07/11 17:55:37 Why the shift? This seems more complicated. Simp
benjhayden 2012/07/13 20:03:17 Done.
817 return num_deleted; 819 return num_deleted;
818 } 820 }
819 821
820 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) { 822 void DownloadManagerImpl::DownloadRemoved(DownloadItem* download) {
821 if (!download || 823 if (!download ||
822 downloads_.find(download->GetId()) == downloads_.end()) 824 downloads_.find(download->GetId()) == downloads_.end())
823 return; 825 return;
824 826
825 // TODO(benjhayden,rdsmith): Remove this. 827 // TODO(benjhayden,rdsmith): Remove this.
826 if (!download->IsPersisted()) 828 if (!download->IsPersisted())
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 void DownloadManagerImpl::DownloadRenamedToFinalName( 1187 void DownloadManagerImpl::DownloadRenamedToFinalName(
1186 DownloadItem* download) { 1188 DownloadItem* download) {
1187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1188 // If the rename failed, we receive an OnDownloadInterrupted() call before we 1190 // If the rename failed, we receive an OnDownloadInterrupted() call before we
1189 // receive the DownloadRenamedToFinalName() call. 1191 // receive the DownloadRenamedToFinalName() call.
1190 if (delegate_) { 1192 if (delegate_) {
1191 delegate_->UpdatePathForItemInPersistentStore( 1193 delegate_->UpdatePathForItemInPersistentStore(
1192 download, download->GetFullPath()); 1194 download, download->GetFullPath());
1193 } 1195 }
1194 } 1196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698