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

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: lint Created 8 years, 4 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 delegate_->AssertStateConsistent(this); 301 delegate_->AssertStateConsistent(this);
305 delegate_->Detach(); 302 delegate_->Detach();
306 } 303 }
307 304
308 void DownloadItemImpl::AddObserver(Observer* observer) { 305 void DownloadItemImpl::AddObserver(Observer* observer) {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
310 307
311 observers_.AddObserver(observer); 308 observers_.AddObserver(observer);
312 } 309 }
313 310
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 // We have now been deleted. 642 // We have now been deleted.
646 } 643 }
647 644
648 void DownloadItemImpl::Remove() { 645 void DownloadItemImpl::Remove() {
649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 646 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
650 647
651 delegate_->AssertStateConsistent(this); 648 delegate_->AssertStateConsistent(this);
652 Cancel(true); 649 Cancel(true);
653 delegate_->AssertStateConsistent(this); 650 delegate_->AssertStateConsistent(this);
654 651
655 TransitionTo(REMOVING); 652 NotifyRemoved();
656 delegate_->DownloadRemoved(this); 653 delegate_->DownloadRemoved(this);
657 // We have now been deleted. 654 // We have now been deleted.
658 } 655 }
659 656
657 void DownloadItemImpl::NotifyRemoved() {
658 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
659 }
660
660 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { 661 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
661 if (total_bytes_ <= 0) 662 if (total_bytes_ <= 0)
662 return false; // We never received the content_length for this download. 663 return false; // We never received the content_length for this download.
663 664
664 int64 speed = CurrentSpeed(); 665 int64 speed = CurrentSpeed();
665 if (speed == 0) 666 if (speed == 0)
666 return false; 667 return false;
667 668
668 *remaining = base::TimeDelta::FromSeconds( 669 *remaining = base::TimeDelta::FromSeconds(
669 (total_bytes_ - received_bytes_) / speed); 670 (total_bytes_ - received_bytes_) / speed);
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } 1162 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; }
1162 bool DownloadItemImpl::GetOpened() const { return opened_; } 1163 bool DownloadItemImpl::GetOpened() const { return opened_; }
1163 const std::string& DownloadItemImpl::GetLastModifiedTime() const { 1164 const std::string& DownloadItemImpl::GetLastModifiedTime() const {
1164 return last_modified_time_; 1165 return last_modified_time_;
1165 } 1166 }
1166 const std::string& DownloadItemImpl::GetETag() const { return etag_; } 1167 const std::string& DownloadItemImpl::GetETag() const { return etag_; }
1167 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const { 1168 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
1168 return last_reason_; 1169 return last_reason_;
1169 } 1170 }
1170 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } 1171 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698