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_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 Loading... |
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"; |
90 case DownloadItem::INTERRUPTED: | 92 case DownloadItem::INTERRUPTED: |
91 return "INTERRUPTED"; | 93 return "INTERRUPTED"; |
92 default: | 94 default: |
93 NOTREACHED() << "Unknown download state " << state; | 95 NOTREACHED() << "Unknown download state " << state; |
94 return "unknown"; | 96 return "unknown"; |
95 }; | 97 }; |
96 } | 98 } |
97 | 99 |
98 // Classes to null out request handle calls (for SavePage DownloadItems, which | 100 // Classes to null out request handle calls (for SavePage DownloadItems, which |
99 // may have, e.g., Cancel() called on them without it doing anything) | 101 // may have, e.g., Cancel() called on them without it doing anything) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 delegate_delayed_complete_(false), | 292 delegate_delayed_complete_(false), |
291 bound_net_log_(bound_net_log), | 293 bound_net_log_(bound_net_log), |
292 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 294 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
293 delegate_->Attach(); | 295 delegate_->Attach(); |
294 Init(true /* actively downloading */, | 296 Init(true /* actively downloading */, |
295 download_net_logs::SRC_SAVE_PAGE_AS); | 297 download_net_logs::SRC_SAVE_PAGE_AS); |
296 } | 298 } |
297 | 299 |
298 DownloadItemImpl::~DownloadItemImpl() { | 300 DownloadItemImpl::~DownloadItemImpl() { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
300 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this)); | 302 |
| 303 TransitionTo(REMOVING); |
301 STLDeleteContainerPairSecondPointers( | 304 STLDeleteContainerPairSecondPointers( |
302 external_data_map_.begin(), external_data_map_.end()); | 305 external_data_map_.begin(), external_data_map_.end()); |
303 delegate_->AssertStateConsistent(this); | 306 delegate_->AssertStateConsistent(this); |
304 delegate_->Detach(); | 307 delegate_->Detach(); |
305 } | 308 } |
306 | 309 |
307 void DownloadItemImpl::AddObserver(Observer* observer) { | 310 void DownloadItemImpl::AddObserver(Observer* observer) { |
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
309 | 312 |
310 observers_.AddObserver(observer); | 313 observers_.AddObserver(observer); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 // We have now been deleted. | 647 // We have now been deleted. |
645 } | 648 } |
646 | 649 |
647 void DownloadItemImpl::Remove() { | 650 void DownloadItemImpl::Remove() { |
648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
649 | 652 |
650 delegate_->AssertStateConsistent(this); | 653 delegate_->AssertStateConsistent(this); |
651 Cancel(true); | 654 Cancel(true); |
652 delegate_->AssertStateConsistent(this); | 655 delegate_->AssertStateConsistent(this); |
653 | 656 |
654 NotifyRemoved(); | 657 TransitionTo(REMOVING); |
655 delegate_->DownloadRemoved(this); | 658 delegate_->DownloadRemoved(this); |
656 // We have now been deleted. | 659 // We have now been deleted. |
657 } | 660 } |
658 | 661 |
659 void DownloadItemImpl::NotifyRemoved() { | |
660 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); | |
661 } | |
662 | |
663 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { | 662 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { |
664 if (total_bytes_ <= 0) | 663 if (total_bytes_ <= 0) |
665 return false; // We never received the content_length for this download. | 664 return false; // We never received the content_length for this download. |
666 | 665 |
667 int64 speed = CurrentSpeed(); | 666 int64 speed = CurrentSpeed(); |
668 if (speed == 0) | 667 if (speed == 0) |
669 return false; | 668 return false; |
670 | 669 |
671 *remaining = base::TimeDelta::FromSeconds( | 670 *remaining = base::TimeDelta::FromSeconds( |
672 (total_bytes_ - received_bytes_) / speed); | 671 (total_bytes_ - received_bytes_) / speed); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 std::map<const void*, ExternalData*>::iterator it = | 1191 std::map<const void*, ExternalData*>::iterator it = |
1193 external_data_map_.find(key); | 1192 external_data_map_.find(key); |
1194 | 1193 |
1195 if (it == external_data_map_.end()) { | 1194 if (it == external_data_map_.end()) { |
1196 external_data_map_[key] = data; | 1195 external_data_map_[key] = data; |
1197 } else if (it->second != data) { | 1196 } else if (it->second != data) { |
1198 delete it->second; | 1197 delete it->second; |
1199 it->second = data; | 1198 it->second = data; |
1200 } | 1199 } |
1201 } | 1200 } |
OLD | NEW |