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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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_, OnDownloadDestructed(this)); |
Randy Smith (Not in Mondays)
2012/06/29 19:34:54
nit, suggestion: Destroyed.
benjhayden
2012/07/10 16:58:57
Done.
| |
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); | |
Randy Smith (Not in Mondays)
2012/06/29 19:34:54
Why? I could imagine us yanking out the queue sta
benjhayden
2012/07/10 16:58:57
Done.
| |
324 delegate_->Detach(); | 320 delegate_->Detach(); |
325 } | 321 } |
326 | 322 |
327 void DownloadItemImpl::AddObserver(Observer* observer) { | 323 void DownloadItemImpl::AddObserver(Observer* observer) { |
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
329 | 325 |
330 observers_.AddObserver(observer); | 326 observers_.AddObserver(observer); |
331 } | 327 } |
332 | 328 |
333 void DownloadItemImpl::RemoveObserver(Observer* observer) { | 329 void DownloadItemImpl::RemoveObserver(Observer* observer) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 // We have now been deleted. | 647 // We have now been deleted. |
652 } | 648 } |
653 | 649 |
654 void DownloadItemImpl::Remove() { | 650 void DownloadItemImpl::Remove() { |
655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
656 | 652 |
657 delegate_->AssertStateConsistent(this); | 653 delegate_->AssertStateConsistent(this); |
658 Cancel(true); | 654 Cancel(true); |
659 delegate_->AssertStateConsistent(this); | 655 delegate_->AssertStateConsistent(this); |
660 | 656 |
661 TransitionTo(REMOVING); | 657 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this)); |
Randy Smith (Not in Mondays)
2012/06/29 19:34:54
I'm torn about this. This *does* seem like a stat
benjhayden
2012/07/10 16:58:57
When we talked about this, we were talking about t
| |
662 delegate_->DownloadRemoved(this); | 658 delegate_->DownloadRemoved(this); |
663 // We have now been deleted. | 659 // We have now been deleted. |
664 } | 660 } |
665 | 661 |
666 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { | 662 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { |
667 if (total_bytes_ <= 0) | 663 if (total_bytes_ <= 0) |
668 return false; // We never received the content_length for this download. | 664 return false; // We never received the content_length for this download. |
669 | 665 |
670 int64 speed = CurrentSpeed(); | 666 int64 speed = CurrentSpeed(); |
671 if (speed == 0) | 667 if (speed == 0) |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1178 std::map<const void*, ExternalData*>::iterator it = | 1174 std::map<const void*, ExternalData*>::iterator it = |
1179 external_data_map_.find(key); | 1175 external_data_map_.find(key); |
1180 | 1176 |
1181 if (it == external_data_map_.end()) { | 1177 if (it == external_data_map_.end()) { |
1182 external_data_map_[key] = data; | 1178 external_data_map_[key] = data; |
1183 } else if (it->second != data) { | 1179 } else if (it->second != data) { |
1184 delete it->second; | 1180 delete it->second; |
1185 it->second = data; | 1181 it->second = data; |
1186 } | 1182 } |
1187 } | 1183 } |
OLD | NEW |