| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 void DownloadManagerImpl::Shutdown() { | 327 void DownloadManagerImpl::Shutdown() { |
| 328 VLOG(20) << __FUNCTION__ << "()" | 328 VLOG(20) << __FUNCTION__ << "()" |
| 329 << " shutdown_needed_ = " << shutdown_needed_; | 329 << " shutdown_needed_ = " << shutdown_needed_; |
| 330 if (!shutdown_needed_) | 330 if (!shutdown_needed_) |
| 331 return; | 331 return; |
| 332 shutdown_needed_ = false; | 332 shutdown_needed_ = false; |
| 333 | 333 |
| 334 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this)); | 334 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this)); |
| 335 // TODO(benjhayden): Consider clearing observers_. | 335 // TODO(benjhayden): Consider clearing observers_. |
| 336 | 336 |
| 337 // Go through all downloads in downloads_. Dangerous ones we need to | 337 // If there are in-progress downloads, cancel them. This also goes for |
| 338 // remove on disk, and in progress ones we need to cancel. | 338 // dangerous downloads which will remain in history if they aren't explicitly |
| 339 for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end();) { | 339 // accepted or discarded. Canceling will remove the intermediate download |
| 340 // file. |
| 341 for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end(); |
| 342 ++it) { |
| 340 DownloadItemImpl* download = it->second; | 343 DownloadItemImpl* download = it->second; |
| 341 | 344 if (download->GetState() == DownloadItem::IN_PROGRESS) |
| 342 // Save iterator from potential erases in this set done by called code. | |
| 343 // Iterators after an erasure point are still valid for lists and | |
| 344 // associative containers such as sets. | |
| 345 it++; | |
| 346 | |
| 347 if (download->IsDangerous() && download->IsPartialDownload()) { | |
| 348 // The user hasn't accepted it, so we need to remove it | |
| 349 // from the disk. This may or may not result in it being | |
| 350 // removed from the DownloadManager queues and deleted | |
| 351 // (specifically, DownloadManager::DownloadRemoved only | |
| 352 // removes and deletes it if it's known to the history service) | |
| 353 // so the only thing we know after calling this function is that | |
| 354 // the download was deleted if-and-only-if it was removed | |
| 355 // from all queues. | |
| 356 download->Delete(DownloadItem::DELETE_DUE_TO_BROWSER_SHUTDOWN); | |
| 357 } else if (download->IsPartialDownload()) { | |
| 358 download->Cancel(false); | 345 download->Cancel(false); |
| 359 } | |
| 360 } | 346 } |
| 361 | |
| 362 // At this point, all dangerous downloads have had their files removed | |
| 363 // and all in progress downloads have been cancelled. We can now delete | |
| 364 // anything left. | |
| 365 | |
| 366 STLDeleteValues(&downloads_); | 347 STLDeleteValues(&downloads_); |
| 367 downloads_.clear(); | 348 downloads_.clear(); |
| 368 | 349 |
| 369 // We'll have nothing more to report to the observers after this point. | 350 // We'll have nothing more to report to the observers after this point. |
| 370 observers_.Clear(); | 351 observers_.Clear(); |
| 371 | 352 |
| 372 if (delegate_) | 353 if (delegate_) |
| 373 delegate_->Shutdown(); | 354 delegate_->Shutdown(); |
| 374 delegate_ = NULL; | 355 delegate_ = NULL; |
| 375 } | 356 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 if (delegate_) | 646 if (delegate_) |
| 666 delegate_->OpenDownload(download); | 647 delegate_->OpenDownload(download); |
| 667 } | 648 } |
| 668 | 649 |
| 669 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 650 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 670 if (delegate_) | 651 if (delegate_) |
| 671 delegate_->ShowDownloadInShell(download); | 652 delegate_->ShowDownloadInShell(download); |
| 672 } | 653 } |
| 673 | 654 |
| 674 } // namespace content | 655 } // namespace content |
| OLD | NEW |