Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 722953002: downloads: add the ability to undo download removal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheck Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 shutdown_needed_(true), 238 shutdown_needed_(true),
239 browser_context_(browser_context), 239 browser_context_(browser_context),
240 delegate_(NULL), 240 delegate_(NULL),
241 net_log_(net_log), 241 net_log_(net_log),
242 weak_factory_(this) { 242 weak_factory_(this) {
243 DCHECK(browser_context); 243 DCHECK(browser_context);
244 } 244 }
245 245
246 DownloadManagerImpl::~DownloadManagerImpl() { 246 DownloadManagerImpl::~DownloadManagerImpl() {
247 DCHECK(!shutdown_needed_); 247 DCHECK(!shutdown_needed_);
248 DCHECK(removed_downloads_.empty());
Dan Beam 2014/11/19 23:16:26 I could change this to: STLDeleteValues(&remove
248 } 249 }
249 250
250 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem( 251 DownloadItemImpl* DownloadManagerImpl::CreateActiveItem(
251 uint32 id, const DownloadCreateInfo& info) { 252 uint32 id, const DownloadCreateInfo& info) {
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
253 DCHECK(!ContainsKey(downloads_, id)); 254 DCHECK(!ContainsKey(downloads_, id));
254 net::BoundNetLog bound_net_log = 255 net::BoundNetLog bound_net_log =
255 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD); 256 net::BoundNetLog::Make(net_log_, net::NetLog::SOURCE_DOWNLOAD);
256 DownloadItemImpl* download = 257 DownloadItemImpl* download =
257 item_factory_->CreateActiveItem(this, id, info, bound_net_log); 258 item_factory_->CreateActiveItem(this, id, info, bound_net_log);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // dangerous downloads which will remain in history if they aren't explicitly 339 // dangerous downloads which will remain in history if they aren't explicitly
339 // accepted or discarded. Canceling will remove the intermediate download 340 // accepted or discarded. Canceling will remove the intermediate download
340 // file. 341 // file.
341 for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end(); 342 for (DownloadMap::iterator it = downloads_.begin(); it != downloads_.end();
342 ++it) { 343 ++it) {
343 DownloadItemImpl* download = it->second; 344 DownloadItemImpl* download = it->second;
344 if (download->GetState() == DownloadItem::IN_PROGRESS) 345 if (download->GetState() == DownloadItem::IN_PROGRESS)
345 download->Cancel(false); 346 download->Cancel(false);
346 } 347 }
347 STLDeleteValues(&downloads_); 348 STLDeleteValues(&downloads_);
348 downloads_.clear();
Dan Beam 2014/11/19 23:16:26 STLDeleteValues() does this already
349 349
350 // 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.
351 observers_.Clear(); 351 observers_.Clear();
352 352
353 if (delegate_) 353 if (delegate_)
354 delegate_->Shutdown(); 354 delegate_->Shutdown();
355 delegate_ = NULL; 355 delegate_ = NULL;
356 } 356 }
357 357
358 void DownloadManagerImpl::StartDownload( 358 void DownloadManagerImpl::StartDownload(
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return file_factory_.get(); 556 return file_factory_.get();
557 } 557 }
558 558
559 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) { 559 void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
560 if (!download) 560 if (!download)
561 return; 561 return;
562 562
563 uint32 download_id = download->GetId(); 563 uint32 download_id = download->GetId();
564 if (downloads_.erase(download_id) == 0) 564 if (downloads_.erase(download_id) == 0)
565 return; 565 return;
566 delete download; 566
567 removed_downloads_[download_id] = download;
567 } 568 }
568 569
569 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin, 570 int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
570 base::Time remove_end) { 571 base::Time remove_end) {
571 int count = 0; 572 int count = 0;
572 DownloadMap::const_iterator it = downloads_.begin(); 573 DownloadMap::const_iterator it = downloads_.begin();
573 while (it != downloads_.end()) { 574 while (it != downloads_.end()) {
574 DownloadItemImpl* download = it->second; 575 DownloadItemImpl* download = it->second;
575 576
576 // Increment done here to protect against invalidation below. 577 // Increment done here to protect against invalidation below.
(...skipping 14 matching lines...) Expand all
591 return RemoveDownloadsBetween(remove_begin, base::Time()); 592 return RemoveDownloadsBetween(remove_begin, base::Time());
592 } 593 }
593 594
594 int DownloadManagerImpl::RemoveAllDownloads() { 595 int DownloadManagerImpl::RemoveAllDownloads() {
595 // The null times make the date range unbounded. 596 // The null times make the date range unbounded.
596 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time()); 597 int num_deleted = RemoveDownloadsBetween(base::Time(), base::Time());
597 RecordClearAllSize(num_deleted); 598 RecordClearAllSize(num_deleted);
598 return num_deleted; 599 return num_deleted;
599 } 600 }
600 601
602 void DownloadManagerImpl::ReviveDownload(uint32 id) {
603 auto it = removed_downloads_.find(id);
604 if (it == removed_downloads_.end())
605 return;
606
607 DownloadItemImpl* item = removed_downloads_[id];
608 removed_downloads_.erase(it);
609
610 downloads_[id] = item;
611
612 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRevived(this, item));
613 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item));
benjhayden 2014/11/21 00:50:01 Is every listener really ok with having a single i
Dan Beam 2014/11/21 05:32:21 According to my interpretation of the documentatio
614 }
615
616 void DownloadManagerImpl::FinalizeRemoval(uint32 id) {
617 auto it = removed_downloads_.find(id);
618 if (it == removed_downloads_.end())
619 return;
620
621 delete it->second;
622 removed_downloads_.erase(it);
623 }
624
601 void DownloadManagerImpl::DownloadUrl( 625 void DownloadManagerImpl::DownloadUrl(
602 scoped_ptr<DownloadUrlParameters> params) { 626 scoped_ptr<DownloadUrlParameters> params) {
603 if (params->post_id() >= 0) { 627 if (params->post_id() >= 0) {
604 // Check this here so that the traceback is more useful. 628 // Check this here so that the traceback is more useful.
605 DCHECK(params->prefer_cache()); 629 DCHECK(params->prefer_cache());
606 DCHECK_EQ("POST", params->method()); 630 DCHECK_EQ("POST", params->method());
607 } 631 }
608 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( 632 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
609 &BeginDownload, base::Passed(&params), 633 &BeginDownload, base::Passed(&params),
610 content::DownloadItem::kInvalidId)); 634 content::DownloadItem::kInvalidId));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 if (delegate_) 741 if (delegate_)
718 delegate_->OpenDownload(download); 742 delegate_->OpenDownload(download);
719 } 743 }
720 744
721 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { 745 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) {
722 if (delegate_) 746 if (delegate_)
723 delegate_->ShowDownloadInShell(download); 747 delegate_->ShowDownloadInShell(download);
724 } 748 }
725 749
726 } // namespace content 750 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698