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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
259 | 259 |
260 // Create a client to verify download URL with safebrowsing. | 260 // Create a client to verify download URL with safebrowsing. |
261 // It deletes itself after the callback. | 261 // It deletes itself after the callback. |
262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( | 262 scoped_refptr<DownloadSBClient> sb_client = new DownloadSBClient( |
263 info->download_id, info->url_chain, info->referrer_url); | 263 info->download_id, info->url_chain, info->referrer_url); |
264 sb_client->CheckDownloadUrl( | 264 sb_client->CheckDownloadUrl( |
265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); | 265 info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
266 } | 266 } |
267 | 267 |
| 268 void DownloadManager::CheckForFilesRemoval() { |
| 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 270 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 271 it != history_downloads_.end(); ++it) { |
| 272 DownloadItem* download_item = it->second; |
| 273 if (download_item->IsComplete() && |
| 274 !download_item->file_externally_removed()) { |
| 275 BrowserThread::PostTask( |
| 276 BrowserThread::FILE, FROM_HERE, |
| 277 NewRunnableMethod(this, |
| 278 &DownloadManager::CheckForFileRemovalOnFileThread, |
| 279 it->first, download_item->GetTargetFilePath())); |
| 280 } |
| 281 } |
| 282 } |
| 283 |
| 284 void DownloadManager::CheckForFileRemovalOnFileThread( |
| 285 int64 db_handle, const FilePath& path) { |
| 286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 287 if (!file_util::PathExists(path)) { |
| 288 BrowserThread::PostTask( |
| 289 BrowserThread::UI, FROM_HERE, |
| 290 NewRunnableMethod(this, |
| 291 &DownloadManager::OnFileRemovalDetected, |
| 292 db_handle)); |
| 293 } |
| 294 } |
| 295 |
| 296 void DownloadManager::OnFileRemovalDetected(int64 db_handle) { |
| 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 298 DownloadMap::iterator it = history_downloads_.find(db_handle); |
| 299 if (it != history_downloads_.end()) { |
| 300 DownloadItem* download_item = it->second; |
| 301 download_item->OnDownloadedFileRemoved(); |
| 302 } |
| 303 } |
| 304 |
268 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, | 305 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, |
269 bool is_dangerous_url) { | 306 bool is_dangerous_url) { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
271 DCHECK(info); | 308 DCHECK(info); |
272 | 309 |
273 info->is_dangerous_url = is_dangerous_url; | 310 info->is_dangerous_url = is_dangerous_url; |
274 | 311 |
275 // Check whether this download is for an extension install or not. | 312 // Check whether this download is for an extension install or not. |
276 // Allow extensions to be explicitly saved. | 313 // Allow extensions to be explicitly saved. |
277 if (!info->prompt_user_for_save_location) { | 314 if (!info->prompt_user_for_save_location) { |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 observed_download_manager_->RemoveObserver(this); | 1212 observed_download_manager_->RemoveObserver(this); |
1176 } | 1213 } |
1177 | 1214 |
1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1215 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1179 observing_download_manager_->NotifyModelChanged(); | 1216 observing_download_manager_->NotifyModelChanged(); |
1180 } | 1217 } |
1181 | 1218 |
1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1219 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1183 observed_download_manager_ = NULL; | 1220 observed_download_manager_ = NULL; |
1184 } | 1221 } |
OLD | NEW |