OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return; | 267 return; |
268 | 268 |
269 // Create a client to verify download URL with safebrowsing. | 269 // Create a client to verify download URL with safebrowsing. |
270 // It deletes itself after the callback. | 270 // It deletes itself after the callback. |
271 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 271 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
272 download_id, download->url_chain(), download->referrer_url()); | 272 download_id, download->url_chain(), download->referrer_url()); |
273 sb_client->CheckDownloadUrl( | 273 sb_client->CheckDownloadUrl( |
274 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 274 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
275 } | 275 } |
276 | 276 |
| 277 void DownloadManager::CheckForHistoryFilesRemoval() { |
| 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 279 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 280 it != history_downloads_.end(); ++it) { |
| 281 CheckForFileRemoval(it->second); |
| 282 } |
| 283 } |
| 284 |
| 285 void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) { |
| 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 287 if (download_item->IsComplete() && |
| 288 !download_item->file_externally_removed()) { |
| 289 BrowserThread::PostTask( |
| 290 BrowserThread::FILE, FROM_HERE, |
| 291 NewRunnableMethod(this, |
| 292 &DownloadManager::CheckForFileRemovalOnFileThread, |
| 293 download_item->db_handle(), |
| 294 download_item->GetTargetFilePath())); |
| 295 } |
| 296 } |
| 297 |
| 298 void DownloadManager::CheckForFileRemovalOnFileThread( |
| 299 int64 db_handle, const FilePath& path) { |
| 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 301 if (!file_util::PathExists(path)) { |
| 302 BrowserThread::PostTask( |
| 303 BrowserThread::UI, FROM_HERE, |
| 304 NewRunnableMethod(this, |
| 305 &DownloadManager::OnFileRemovalDetected, |
| 306 db_handle)); |
| 307 } |
| 308 } |
| 309 |
| 310 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 312 DownloadMap::iterator it = history_downloads_.find(db_handle); |
| 313 if (it != history_downloads_.end()) { |
| 314 DownloadItem* download_item = it->second; |
| 315 download_item->OnDownloadedFileRemoved(); |
| 316 } |
| 317 } |
| 318 |
277 void DownloadManager::CheckDownloadUrlDone(int32 download_id, | 319 void DownloadManager::CheckDownloadUrlDone(int32 download_id, |
278 bool is_dangerous_url) { | 320 bool is_dangerous_url) { |
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
280 | 322 |
281 DownloadItem* download = GetActiveDownloadItem(download_id); | 323 DownloadItem* download = GetActiveDownloadItem(download_id); |
282 if (!download) | 324 if (!download) |
283 return; | 325 return; |
284 | 326 |
285 if (is_dangerous_url) | 327 if (is_dangerous_url) |
286 download->MarkUrlDangerous(); | 328 download->MarkUrlDangerous(); |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 std::vector<DownloadHistoryInfo>* entries) { | 1120 std::vector<DownloadHistoryInfo>* entries) { |
1079 for (size_t i = 0; i < entries->size(); ++i) { | 1121 for (size_t i = 0; i < entries->size(); ++i) { |
1080 DownloadItem* download = new DownloadItem(this, entries->at(i)); | 1122 DownloadItem* download = new DownloadItem(this, entries->at(i)); |
1081 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); | 1123 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); |
1082 downloads_.insert(download); | 1124 downloads_.insert(download); |
1083 history_downloads_[download->db_handle()] = download; | 1125 history_downloads_[download->db_handle()] = download; |
1084 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 1126 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
1085 << " download = " << download->DebugString(true); | 1127 << " download = " << download->DebugString(true); |
1086 } | 1128 } |
1087 NotifyModelChanged(); | 1129 NotifyModelChanged(); |
| 1130 CheckForHistoryFilesRemoval(); |
1088 } | 1131 } |
1089 | 1132 |
1090 // Once the new DownloadItem's creation info has been committed to the history | 1133 // Once the new DownloadItem's creation info has been committed to the history |
1091 // service, we associate the DownloadItem with the db handle, update our | 1134 // service, we associate the DownloadItem with the db handle, update our |
1092 // 'history_downloads_' map and inform observers. | 1135 // 'history_downloads_' map and inform observers. |
1093 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id, | 1136 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id, |
1094 int64 db_handle) { | 1137 int64 db_handle) { |
1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1096 DownloadItem* download = GetActiveDownloadItem(download_id); | 1139 DownloadItem* download = GetActiveDownloadItem(download_id); |
1097 if (!download) | 1140 if (!download) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 observed_download_manager_->RemoveObserver(this); | 1304 observed_download_manager_->RemoveObserver(this); |
1262 } | 1305 } |
1263 | 1306 |
1264 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1307 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1265 observing_download_manager_->NotifyModelChanged(); | 1308 observing_download_manager_->NotifyModelChanged(); |
1266 } | 1309 } |
1267 | 1310 |
1268 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1311 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1269 observed_download_manager_ = NULL; | 1312 observed_download_manager_ = NULL; |
1270 } | 1313 } |
OLD | NEW |