OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
14 #include "base/i18n/string_search.h" | 14 #include "base/i18n/string_search.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/stl_util.h" | |
17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
18 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
19 #include "content/browser/download/download_create_info.h" | 20 #include "content/browser/download/download_create_info.h" |
20 #include "content/browser/download/download_file.h" | 21 #include "content/browser/download/download_file.h" |
21 #include "content/browser/download/download_file_manager.h" | 22 #include "content/browser/download/download_file_manager.h" |
22 #include "content/browser/download/download_id.h" | 23 #include "content/browser/download/download_id.h" |
23 #include "content/browser/download/download_persistent_store_info.h" | 24 #include "content/browser/download/download_persistent_store_info.h" |
24 #include "content/browser/download/download_request_handle.h" | 25 #include "content/browser/download/download_request_handle.h" |
25 #include "content/browser/download/download_stats.h" | 26 #include "content/browser/download/download_stats.h" |
26 #include "content/browser/download/interrupt_reasons.h" | 27 #include "content/browser/download/interrupt_reasons.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 delegate_delayed_complete_(false) { | 254 delegate_delayed_complete_(false) { |
254 delegate_->Attach(); | 255 delegate_->Attach(); |
255 Init(true /* actively downloading */); | 256 Init(true /* actively downloading */); |
256 } | 257 } |
257 | 258 |
258 DownloadItemImpl::~DownloadItemImpl() { | 259 DownloadItemImpl::~DownloadItemImpl() { |
259 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 260 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
260 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 261 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
261 | 262 |
262 TransitionTo(REMOVING); | 263 TransitionTo(REMOVING); |
264 STLDeleteContainerPairSecondPointers( | |
265 external_data_map_.begin(), external_data_map_.end()); | |
263 delegate_->AssertStateConsistent(this); | 266 delegate_->AssertStateConsistent(this); |
264 delegate_->Detach(); | 267 delegate_->Detach(); |
265 } | 268 } |
266 | 269 |
267 void DownloadItemImpl::AddObserver(Observer* observer) { | 270 void DownloadItemImpl::AddObserver(Observer* observer) { |
268 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 271 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
269 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
270 | 273 |
271 observers_.AddObserver(observer); | 274 observers_.AddObserver(observer); |
272 } | 275 } |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 void DownloadItemImpl::OffThreadCancel(DownloadFileManager* file_manager) { | 757 void DownloadItemImpl::OffThreadCancel(DownloadFileManager* file_manager) { |
755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
756 request_handle_->CancelRequest(); | 759 request_handle_->CancelRequest(); |
757 | 760 |
758 BrowserThread::PostTask( | 761 BrowserThread::PostTask( |
759 BrowserThread::FILE, FROM_HERE, | 762 BrowserThread::FILE, FROM_HERE, |
760 base::Bind(&DownloadFileManager::CancelDownload, | 763 base::Bind(&DownloadFileManager::CancelDownload, |
761 file_manager, download_id_)); | 764 file_manager, download_id_)); |
762 } | 765 } |
763 | 766 |
767 DownloadItem::ExternalData* | |
asanka
2011/12/07 04:10:57
Style nit: The method implementation order isn't t
Randy Smith (Not in Mondays)
2011/12/07 18:36:12
Done.
| |
768 DownloadItemImpl::GetExternalData(const void* key) { | |
769 if (external_data_map_.count(key) == 0) | |
asanka
2011/12/07 04:10:57
Just curious; why not ContainsKey()?
Randy Smith (Not in Mondays)
2011/12/07 18:36:12
Prejudice on my part, which it's probably time for
| |
770 return NULL; | |
771 return external_data_map_[key]; | |
772 } | |
773 | |
774 void DownloadItemImpl::SetExternalData( | |
775 const void* key, DownloadItem::ExternalData* data) { | |
776 std::map<const void*, ExternalData*>::iterator it = | |
777 external_data_map_.find(key); | |
778 | |
779 if (it == external_data_map_.end()) { | |
780 external_data_map_[key] = data; | |
781 } else if (it->second != data) { | |
782 delete it->second; | |
783 it->second = data; | |
784 } | |
785 } | |
786 | |
764 void DownloadItemImpl::Init(bool active) { | 787 void DownloadItemImpl::Init(bool active) { |
765 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 788 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
766 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 789 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
767 | 790 |
768 UpdateTarget(); | 791 UpdateTarget(); |
769 if (active) { | 792 if (active) { |
770 download_stats::RecordDownloadCount(download_stats::START_COUNT); | 793 download_stats::RecordDownloadCount(download_stats::START_COUNT); |
771 } | 794 } |
772 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); | 795 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); |
773 } | 796 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } | 944 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } |
922 bool DownloadItemImpl::GetOpened() const { return opened_; } | 945 bool DownloadItemImpl::GetOpened() const { return opened_; } |
923 InterruptReason DownloadItemImpl::GetLastReason() const { | 946 InterruptReason DownloadItemImpl::GetLastReason() const { |
924 return last_reason_; | 947 return last_reason_; |
925 } | 948 } |
926 DownloadStateInfo DownloadItemImpl::GetStateInfo() const { return state_info_; } | 949 DownloadStateInfo DownloadItemImpl::GetStateInfo() const { return state_info_; } |
927 bool DownloadItemImpl::NeedsRename() const { | 950 bool DownloadItemImpl::NeedsRename() const { |
928 return state_info_.target_name != full_path_.BaseName(); | 951 return state_info_.target_name != full_path_.BaseName(); |
929 } | 952 } |
930 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } | 953 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } |
OLD | NEW |