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

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: merge 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 const char* DebugDownloadStateString(DownloadItem::DownloadState state) { 81 const char* DebugDownloadStateString(DownloadItem::DownloadState state) {
82 switch (state) { 82 switch (state) {
83 case DownloadItem::IN_PROGRESS: 83 case DownloadItem::IN_PROGRESS:
84 return "IN_PROGRESS"; 84 return "IN_PROGRESS";
85 case DownloadItem::COMPLETE: 85 case DownloadItem::COMPLETE:
86 return "COMPLETE"; 86 return "COMPLETE";
87 case DownloadItem::CANCELLED: 87 case DownloadItem::CANCELLED:
88 return "CANCELLED"; 88 return "CANCELLED";
89 case DownloadItem::REMOVING:
90 return "REMOVING";
91 case DownloadItem::INTERRUPTED: 89 case DownloadItem::INTERRUPTED:
92 return "INTERRUPTED"; 90 return "INTERRUPTED";
93 default: 91 default:
94 NOTREACHED() << "Unknown download state " << state; 92 NOTREACHED() << "Unknown download state " << state;
95 return "unknown"; 93 return "unknown";
96 }; 94 };
97 } 95 }
98 96
99 // Classes to null out request handle calls (for SavePage DownloadItems, which 97 // Classes to null out request handle calls (for SavePage DownloadItems, which
100 // may have, e.g., Cancel() called on them without it doing anything) 98 // may have, e.g., Cancel() called on them without it doing anything)
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 delegate_delayed_complete_(false), 307 delegate_delayed_complete_(false),
310 bound_net_log_(bound_net_log), 308 bound_net_log_(bound_net_log),
311 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 309 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
312 delegate_->Attach(); 310 delegate_->Attach();
313 Init(true /* actively downloading */, 311 Init(true /* actively downloading */,
314 download_net_logs::SRC_SAVE_PAGE_AS); 312 download_net_logs::SRC_SAVE_PAGE_AS);
315 } 313 }
316 314
317 DownloadItemImpl::~DownloadItemImpl() { 315 DownloadItemImpl::~DownloadItemImpl() {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 317 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this));
320 TransitionTo(REMOVING);
321 STLDeleteContainerPairSecondPointers( 318 STLDeleteContainerPairSecondPointers(
322 external_data_map_.begin(), external_data_map_.end()); 319 external_data_map_.begin(), external_data_map_.end());
323 delegate_->AssertStateConsistent(this); 320 delegate_->AssertStateConsistent(this);
324 delegate_->Detach(); 321 delegate_->Detach();
325 } 322 }
326 323
327 void DownloadItemImpl::AddObserver(Observer* observer) { 324 void DownloadItemImpl::AddObserver(Observer* observer) {
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
329 326
330 observers_.AddObserver(observer); 327 observers_.AddObserver(observer);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // We have now been deleted. 651 // We have now been deleted.
655 } 652 }
656 653
657 void DownloadItemImpl::Remove() { 654 void DownloadItemImpl::Remove() {
658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
659 656
660 delegate_->AssertStateConsistent(this); 657 delegate_->AssertStateConsistent(this);
661 Cancel(true); 658 Cancel(true);
662 delegate_->AssertStateConsistent(this); 659 delegate_->AssertStateConsistent(this);
663 660
664 TransitionTo(REMOVING); 661 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
665 delegate_->DownloadRemoved(this); 662 delegate_->DownloadRemoved(this);
666 // We have now been deleted. 663 // We have now been deleted.
667 } 664 }
668 665
669 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { 666 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
670 if (total_bytes_ <= 0) 667 if (total_bytes_ <= 0)
671 return false; // We never received the content_length for this download. 668 return false; // We never received the content_length for this download.
672 669
673 int64 speed = CurrentSpeed(); 670 int64 speed = CurrentSpeed();
674 if (speed == 0) 671 if (speed == 0)
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 std::map<const void*, ExternalData*>::iterator it = 1183 std::map<const void*, ExternalData*>::iterator it =
1187 external_data_map_.find(key); 1184 external_data_map_.find(key);
1188 1185
1189 if (it == external_data_map_.end()) { 1186 if (it == external_data_map_.end()) {
1190 external_data_map_[key] = data; 1187 external_data_map_[key] = data;
1191 } else if (it->second != data) { 1188 } else if (it->second != data) {
1192 delete it->second; 1189 delete it->second;
1193 it->second = data; 1190 it->second = data;
1194 } 1191 }
1195 } 1192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698