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

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 5877003: Added clearing of downloads_ set on RemoveDownloadsBetween pathway. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/download/download_manager.h" 5 #include "chrome/browser/download/download_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // Tell observers to refresh their views. 712 // Tell observers to refresh their views.
713 NotifyModelChanged(); 713 NotifyModelChanged();
714 714
715 delete download; 715 delete download;
716 } 716 }
717 717
718 int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin, 718 int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin,
719 const base::Time remove_end) { 719 const base::Time remove_end) {
720 download_history_->RemoveEntriesBetween(remove_begin, remove_end); 720 download_history_->RemoveEntriesBetween(remove_begin, remove_end);
721 721
722 // All downloads visible to the user will be in the history,
723 // so scan that map.
722 DownloadMap::iterator it = history_downloads_.begin(); 724 DownloadMap::iterator it = history_downloads_.begin();
723 std::vector<DownloadItem*> pending_deletes; 725 std::vector<DownloadItem*> pending_deletes;
724 while (it != history_downloads_.end()) { 726 while (it != history_downloads_.end()) {
725 DownloadItem* download = it->second; 727 DownloadItem* download = it->second;
726 DownloadItem::DownloadState state = download->state(); 728 DownloadItem::DownloadState state = download->state();
727 if (download->start_time() >= remove_begin && 729 if (download->start_time() >= remove_begin &&
728 (remove_end.is_null() || download->start_time() < remove_end) && 730 (remove_end.is_null() || download->start_time() < remove_end) &&
729 (state == DownloadItem::COMPLETE || 731 (state == DownloadItem::COMPLETE ||
730 state == DownloadItem::CANCELLED)) { 732 state == DownloadItem::CANCELLED)) {
731 // Remove from the map and move to the next in the list. 733 // Remove from the map and move to the next in the list.
732 history_downloads_.erase(it++); 734 history_downloads_.erase(it++);
733 735
734 // Also remove it from any completed dangerous downloads. 736 // Also remove it from any completed dangerous downloads.
735 pending_deletes.push_back(download); 737 pending_deletes.push_back(download);
736 738
737 continue; 739 continue;
738 } 740 }
739 741
740 ++it; 742 ++it;
741 } 743 }
742 744
cbentzel 2010/12/15 21:34:20 Would this be clearer if you did if (pending_dele
745 // If we aren't deleting anything, we're done.
746 int num_deleted = static_cast<int>(pending_deletes.size());
747 if (num_deleted == 0)
748 return num_deleted;
749
750 // Remove the chosen downloads from the main owning container.
751 for (std::vector<DownloadItem*>::iterator it = pending_deletes.begin();
752 it != pending_deletes.end(); it++) {
753 downloads_.erase(*it);
754 }
755
743 // Tell observers to refresh their views. 756 // Tell observers to refresh their views.
744 int num_deleted = static_cast<int>(pending_deletes.size()); 757 NotifyModelChanged();
745 if (num_deleted > 0)
746 NotifyModelChanged();
747 758
748 // Delete the download items after updating the observers. 759 // Delete the download items themselves.
749 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); 760 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
750 pending_deletes.clear(); 761 pending_deletes.clear();
751 762
752 return num_deleted; 763 return num_deleted;
753 } 764 }
754 765
755 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { 766 int DownloadManager::RemoveDownloads(const base::Time remove_begin) {
756 return RemoveDownloadsBetween(remove_begin, base::Time()); 767 return RemoveDownloadsBetween(remove_begin, base::Time());
757 } 768 }
758 769
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 observed_download_manager_->RemoveObserver(this); 1044 observed_download_manager_->RemoveObserver(this);
1034 } 1045 }
1035 1046
1036 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1047 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1037 observing_download_manager_->NotifyModelChanged(); 1048 observing_download_manager_->NotifyModelChanged();
1038 } 1049 }
1039 1050
1040 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1051 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1041 observed_download_manager_ = NULL; 1052 observed_download_manager_ = NULL;
1042 } 1053 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698