Chromium Code Reviews| 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() { | |
|
Paweł Hajdan Jr.
2011/05/10 11:37:51
nit: Could you add a DCHECK(BrowserThread::Cureent
| |
| 269 PathVector existing_paths; | |
| 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() && download_item->file_exists()) { | |
| 274 existing_paths.push_back(std::pair<int64, FilePath>( | |
| 275 it->first, download_item->GetTargetFilePath())); | |
| 276 } | |
| 277 } | |
| 278 | |
| 279 BrowserThread::PostTask( | |
| 280 BrowserThread::FILE, FROM_HERE, | |
| 281 NewRunnableMethod(this, | |
| 282 &DownloadManager::CheckForFilesRemovalOnFileThread, | |
| 283 existing_paths)); | |
| 284 } | |
| 285 | |
| 286 void DownloadManager::CheckForFilesRemovalOnFileThread( | |
| 287 const PathVector& existing_paths) { | |
| 288 PathVector removed_paths; | |
| 289 for (PathVector::const_iterator it = existing_paths.begin(); | |
| 290 it != existing_paths.end(); ++it) { | |
| 291 if (!file_util::PathExists(it->second)) { | |
| 292 removed_paths.push_back(std::pair<int64, FilePath>( | |
| 293 it->first, it->second)); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 BrowserThread::PostTask( | |
| 298 BrowserThread::UI, FROM_HERE, | |
| 299 NewRunnableMethod(this, | |
| 300 &DownloadManager::OnFilesRemovalDetected, | |
| 301 removed_paths)); | |
| 302 } | |
| 303 | |
| 304 void DownloadManager::OnFilesRemovalDetected(const PathVector& removed_paths) { | |
| 305 for (PathVector::const_iterator it = removed_paths.begin(); | |
| 306 it != removed_paths.end(); ++it) { | |
| 307 DownloadMap::iterator map_it = history_downloads_.find(it->first); | |
| 308 // Since all download items are registered to DownloadDOMHandler's | |
|
Paweł Hajdan Jr.
2011/05/10 11:37:51
nit: I'd rather remove this comment. It might beco
| |
| 309 // observer, we can update the display of chrome://downloads page | |
| 310 // by calling UpdateObservers() | |
| 311 if (map_it != history_downloads_.end()) { | |
| 312 DownloadItem* download_item = map_it->second; | |
| 313 download_item->set_file_exists(false); | |
| 314 download_item->UpdateObservers(); | |
| 315 } | |
| 316 } | |
| 317 } | |
| 318 | |
| 268 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, | 319 void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, |
| 269 bool is_dangerous_url) { | 320 bool is_dangerous_url) { |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 271 DCHECK(info); | 322 DCHECK(info); |
| 272 | 323 |
| 273 info->is_dangerous_url = is_dangerous_url; | 324 info->is_dangerous_url = is_dangerous_url; |
| 274 | 325 |
| 275 // Check whether this download is for an extension install or not. | 326 // Check whether this download is for an extension install or not. |
| 276 // Allow extensions to be explicitly saved. | 327 // Allow extensions to be explicitly saved. |
| 277 if (!info->prompt_user_for_save_location) { | 328 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); | 1226 observed_download_manager_->RemoveObserver(this); |
| 1176 } | 1227 } |
| 1177 | 1228 |
| 1178 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1229 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
| 1179 observing_download_manager_->NotifyModelChanged(); | 1230 observing_download_manager_->NotifyModelChanged(); |
| 1180 } | 1231 } |
| 1181 | 1232 |
| 1182 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1233 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
| 1183 observed_download_manager_ = NULL; | 1234 observed_download_manager_ = NULL; |
| 1184 } | 1235 } |
| OLD | NEW |