| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 // Tell observers to refresh their views. | 1010 // Tell observers to refresh their views. |
| 1011 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); | 1011 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); |
| 1012 | 1012 |
| 1013 delete download; | 1013 delete download; |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin, | 1016 int DownloadManager::RemoveDownloadsBetween(const base::Time remove_begin, |
| 1017 const base::Time remove_end) { | 1017 const base::Time remove_end) { |
| 1018 RemoveDownloadsFromHistoryBetween(remove_begin, remove_end); | 1018 RemoveDownloadsFromHistoryBetween(remove_begin, remove_end); |
| 1019 | 1019 |
| 1020 int num_deleted = 0; | |
| 1021 DownloadMap::iterator it = downloads_.begin(); | 1020 DownloadMap::iterator it = downloads_.begin(); |
| 1021 std::vector<DownloadItem*> pending_deletes; |
| 1022 while (it != downloads_.end()) { | 1022 while (it != downloads_.end()) { |
| 1023 DownloadItem* download = it->second; | 1023 DownloadItem* download = it->second; |
| 1024 DownloadItem::DownloadState state = download->state(); | 1024 DownloadItem::DownloadState state = download->state(); |
| 1025 if (download->start_time() >= remove_begin && | 1025 if (download->start_time() >= remove_begin && |
| 1026 (remove_end.is_null() || download->start_time() < remove_end) && | 1026 (remove_end.is_null() || download->start_time() < remove_end) && |
| 1027 (state == DownloadItem::COMPLETE || | 1027 (state == DownloadItem::COMPLETE || |
| 1028 state == DownloadItem::CANCELLED)) { | 1028 state == DownloadItem::CANCELLED)) { |
| 1029 // Remove from the map and move to the next in the list. | 1029 // Remove from the map and move to the next in the list. |
| 1030 downloads_.erase(it++); | 1030 downloads_.erase(it++); |
| 1031 | 1031 |
| 1032 // Also remove it from any completed dangerous downloads. | 1032 // Also remove it from any completed dangerous downloads. |
| 1033 DownloadMap::iterator dit = dangerous_finished_.find(download->id()); | 1033 DownloadMap::iterator dit = dangerous_finished_.find(download->id()); |
| 1034 if (dit != dangerous_finished_.end()) | 1034 if (dit != dangerous_finished_.end()) |
| 1035 dangerous_finished_.erase(dit); | 1035 dangerous_finished_.erase(dit); |
| 1036 | 1036 |
| 1037 delete download; | 1037 pending_deletes.push_back(download); |
| 1038 | 1038 |
| 1039 ++num_deleted; | |
| 1040 continue; | 1039 continue; |
| 1041 } | 1040 } |
| 1042 | 1041 |
| 1043 ++it; | 1042 ++it; |
| 1044 } | 1043 } |
| 1045 | 1044 |
| 1046 // Tell observers to refresh their views. | 1045 // Tell observers to refresh their views. |
| 1046 int num_deleted = static_cast<int>(pending_deletes.size()); |
| 1047 if (num_deleted > 0) | 1047 if (num_deleted > 0) |
| 1048 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); | 1048 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged()); |
| 1049 | 1049 |
| 1050 // Delete the download items after updating the observers. |
| 1051 STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end()); |
| 1052 pending_deletes.clear(); |
| 1053 |
| 1050 return num_deleted; | 1054 return num_deleted; |
| 1051 } | 1055 } |
| 1052 | 1056 |
| 1053 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { | 1057 int DownloadManager::RemoveDownloads(const base::Time remove_begin) { |
| 1054 return RemoveDownloadsBetween(remove_begin, base::Time()); | 1058 return RemoveDownloadsBetween(remove_begin, base::Time()); |
| 1055 } | 1059 } |
| 1056 | 1060 |
| 1057 // Initiate a download of a specific URL. We send the request to the | 1061 // Initiate a download of a specific URL. We send the request to the |
| 1058 // ResourceDispatcherHost, and let it send us responses like a regular | 1062 // ResourceDispatcherHost, and let it send us responses like a regular |
| 1059 // download. | 1063 // download. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 searched_downloads.push_back(dit->second); | 1450 searched_downloads.push_back(dit->second); |
| 1447 } | 1451 } |
| 1448 | 1452 |
| 1449 requestor->SetDownloads(searched_downloads); | 1453 requestor->SetDownloads(searched_downloads); |
| 1450 } | 1454 } |
| 1451 | 1455 |
| 1452 // Clears the last download path, used to initialize "save as" dialogs. | 1456 // Clears the last download path, used to initialize "save as" dialogs. |
| 1453 void DownloadManager::ClearLastDownloadPath() { | 1457 void DownloadManager::ClearLastDownloadPath() { |
| 1454 last_download_path_ = FilePath(); | 1458 last_download_path_ = FilePath(); |
| 1455 } | 1459 } |
| OLD | NEW |