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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 months 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 | Annotate | Revision Log
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_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 const char* DebugDownloadStateString(DownloadItem::DownloadState state) { 82 const char* DebugDownloadStateString(DownloadItem::DownloadState state) {
83 switch (state) { 83 switch (state) {
84 case DownloadItem::IN_PROGRESS: 84 case DownloadItem::IN_PROGRESS:
85 return "IN_PROGRESS"; 85 return "IN_PROGRESS";
86 case DownloadItem::COMPLETE: 86 case DownloadItem::COMPLETE:
87 return "COMPLETE"; 87 return "COMPLETE";
88 case DownloadItem::CANCELLED: 88 case DownloadItem::CANCELLED:
89 return "CANCELLED"; 89 return "CANCELLED";
90 case DownloadItem::REMOVING:
91 return "REMOVING";
92 case DownloadItem::INTERRUPTED: 90 case DownloadItem::INTERRUPTED:
93 return "INTERRUPTED"; 91 return "INTERRUPTED";
94 default: 92 default:
95 NOTREACHED() << "Unknown download state " << state; 93 NOTREACHED() << "Unknown download state " << state;
96 return "unknown"; 94 return "unknown";
97 }; 95 };
98 } 96 }
99 97
100 // Classes to null out request handle calls (for SavePage DownloadItems, which 98 // Classes to null out request handle calls (for SavePage DownloadItems, which
101 // may have, e.g., Cancel() called on them without it doing anything) 99 // may have, e.g., Cancel() called on them without it doing anything)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 delegate_delayed_complete_(false), 290 delegate_delayed_complete_(false),
293 bound_net_log_(bound_net_log), 291 bound_net_log_(bound_net_log),
294 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 292 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
295 delegate_->Attach(); 293 delegate_->Attach();
296 Init(true /* actively downloading */, 294 Init(true /* actively downloading */,
297 download_net_logs::SRC_SAVE_PAGE_AS); 295 download_net_logs::SRC_SAVE_PAGE_AS);
298 } 296 }
299 297
300 DownloadItemImpl::~DownloadItemImpl() { 298 DownloadItemImpl::~DownloadItemImpl() {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
302 300 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this));
303 TransitionTo(REMOVING);
304 STLDeleteContainerPairSecondPointers( 301 STLDeleteContainerPairSecondPointers(
305 external_data_map_.begin(), external_data_map_.end()); 302 external_data_map_.begin(), external_data_map_.end());
306 delegate_->AssertStateConsistent(this); 303 delegate_->AssertStateConsistent(this);
307 delegate_->Detach(); 304 delegate_->Detach();
308 } 305 }
309 306
310 void DownloadItemImpl::AddObserver(Observer* observer) { 307 void DownloadItemImpl::AddObserver(Observer* observer) {
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
312 309
313 observers_.AddObserver(observer); 310 observers_.AddObserver(observer);
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 // We have now been deleted. 645 // We have now been deleted.
649 } 646 }
650 647
651 void DownloadItemImpl::Remove() { 648 void DownloadItemImpl::Remove() {
652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
653 650
654 delegate_->AssertStateConsistent(this); 651 delegate_->AssertStateConsistent(this);
655 Cancel(true); 652 Cancel(true);
656 delegate_->AssertStateConsistent(this); 653 delegate_->AssertStateConsistent(this);
657 654
658 TransitionTo(REMOVING); 655 NotifyRemoved();
659 delegate_->DownloadRemoved(this); 656 delegate_->DownloadRemoved(this);
660 // We have now been deleted. 657 // We have now been deleted.
661 } 658 }
662 659
660 void DownloadItemImpl::NotifyRemoved() {
661 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
662 }
663
663 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { 664 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
664 if (total_bytes_ <= 0) 665 if (total_bytes_ <= 0)
665 return false; // We never received the content_length for this download. 666 return false; // We never received the content_length for this download.
666 667
667 int64 speed = CurrentSpeed(); 668 int64 speed = CurrentSpeed();
668 if (speed == 0) 669 if (speed == 0)
669 return false; 670 return false;
670 671
671 *remaining = base::TimeDelta::FromSeconds( 672 *remaining = base::TimeDelta::FromSeconds(
672 (total_bytes_ - received_bytes_) / speed); 673 (total_bytes_ - received_bytes_) / speed);
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 std::map<const void*, ExternalData*>::iterator it = 1187 std::map<const void*, ExternalData*>::iterator it =
1187 external_data_map_.find(key); 1188 external_data_map_.find(key);
1188 1189
1189 if (it == external_data_map_.end()) { 1190 if (it == external_data_map_.end()) {
1190 external_data_map_[key] = data; 1191 external_data_map_[key] = data;
1191 } else if (it->second != data) { 1192 } else if (it->second != data) {
1192 delete it->second; 1193 delete it->second;
1193 it->second = data; 1194 it->second = data;
1194 } 1195 }
1195 } 1196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698