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 251 matching lines...) Loading... |
262 return; | 262 return; |
263 | 263 |
264 // Create a client to verify download URL with safebrowsing. | 264 // Create a client to verify download URL with safebrowsing. |
265 // It deletes itself after the callback. | 265 // It deletes itself after the callback. |
266 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 266 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
267 download_id, download->url_chain(), download->referrer_url()); | 267 download_id, download->url_chain(), download->referrer_url()); |
268 sb_client->CheckDownloadUrl( | 268 sb_client->CheckDownloadUrl( |
269 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 269 NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
270 } | 270 } |
271 | 271 |
| 272 void DownloadManager::CheckForHistoryFilesRemoval() { |
| 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 274 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 275 it != history_downloads_.end(); ++it) { |
| 276 CheckForFileRemoval(it->second); |
| 277 } |
| 278 } |
| 279 |
| 280 void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) { |
| 281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 282 if (download_item->IsComplete() && |
| 283 !download_item->file_externally_removed()) { |
| 284 BrowserThread::PostTask( |
| 285 BrowserThread::FILE, FROM_HERE, |
| 286 NewRunnableMethod(this, |
| 287 &DownloadManager::CheckForFileRemovalOnFileThread, |
| 288 download_item->db_handle(), |
| 289 download_item->GetTargetFilePath())); |
| 290 } |
| 291 } |
| 292 |
| 293 void DownloadManager::CheckForFileRemovalOnFileThread( |
| 294 int64 db_handle, const FilePath& path) { |
| 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 296 if (!file_util::PathExists(path)) { |
| 297 BrowserThread::PostTask( |
| 298 BrowserThread::UI, FROM_HERE, |
| 299 NewRunnableMethod(this, |
| 300 &DownloadManager::OnFileRemovalDetected, |
| 301 db_handle)); |
| 302 } |
| 303 } |
| 304 |
| 305 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { |
| 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 307 DownloadMap::iterator it = history_downloads_.find(db_handle); |
| 308 if (it != history_downloads_.end()) { |
| 309 DownloadItem* download_item = it->second; |
| 310 download_item->OnDownloadedFileRemoved(); |
| 311 } |
| 312 } |
| 313 |
272 void DownloadManager::CheckDownloadUrlDone(int32 download_id, | 314 void DownloadManager::CheckDownloadUrlDone(int32 download_id, |
273 bool is_dangerous_url) { | 315 bool is_dangerous_url) { |
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
275 | 317 |
276 DownloadItem* download = GetActiveDownloadItem(download_id); | 318 DownloadItem* download = GetActiveDownloadItem(download_id); |
277 if (!download) | 319 if (!download) |
278 return; | 320 return; |
279 | 321 |
280 if (is_dangerous_url) | 322 if (is_dangerous_url) |
281 download->MarkUrlDangerous(); | 323 download->MarkUrlDangerous(); |
(...skipping 812 matching lines...) Loading... |
1094 std::vector<DownloadHistoryInfo>* entries) { | 1136 std::vector<DownloadHistoryInfo>* entries) { |
1095 for (size_t i = 0; i < entries->size(); ++i) { | 1137 for (size_t i = 0; i < entries->size(); ++i) { |
1096 DownloadItem* download = new DownloadItem(this, entries->at(i)); | 1138 DownloadItem* download = new DownloadItem(this, entries->at(i)); |
1097 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); | 1139 DCHECK(!ContainsKey(history_downloads_, download->db_handle())); |
1098 downloads_.insert(download); | 1140 downloads_.insert(download); |
1099 history_downloads_[download->db_handle()] = download; | 1141 history_downloads_[download->db_handle()] = download; |
1100 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 1142 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
1101 << " download = " << download->DebugString(true); | 1143 << " download = " << download->DebugString(true); |
1102 } | 1144 } |
1103 NotifyModelChanged(); | 1145 NotifyModelChanged(); |
| 1146 CheckForHistoryFilesRemoval(); |
1104 } | 1147 } |
1105 | 1148 |
1106 // Once the new DownloadItem's creation info has been committed to the history | 1149 // Once the new DownloadItem's creation info has been committed to the history |
1107 // service, we associate the DownloadItem with the db handle, update our | 1150 // service, we associate the DownloadItem with the db handle, update our |
1108 // 'history_downloads_' map and inform observers. | 1151 // 'history_downloads_' map and inform observers. |
1109 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id, | 1152 void DownloadManager::OnCreateDownloadEntryComplete(int32 download_id, |
1110 int64 db_handle) { | 1153 int64 db_handle) { |
1111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1112 DownloadItem* download = GetActiveDownloadItem(download_id); | 1155 DownloadItem* download = GetActiveDownloadItem(download_id); |
1113 if (!download) | 1156 if (!download) |
(...skipping 163 matching lines...) Loading... |
1277 observed_download_manager_->RemoveObserver(this); | 1320 observed_download_manager_->RemoveObserver(this); |
1278 } | 1321 } |
1279 | 1322 |
1280 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1323 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1281 observing_download_manager_->NotifyModelChanged(); | 1324 observing_download_manager_->NotifyModelChanged(); |
1282 } | 1325 } |
1283 | 1326 |
1284 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1327 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1285 observed_download_manager_ = NULL; | 1328 observed_download_manager_ = NULL; |
1286 } | 1329 } |
OLD | NEW |