| 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.h" | 5 #include "content/browser/download/download_item.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // Our download table ID starts at 1, so we use 0 to represent a download that | 114 // Our download table ID starts at 1, so we use 0 to represent a download that |
| 115 // has started, but has not yet had its data persisted in the table. We use fake | 115 // has started, but has not yet had its data persisted in the table. We use fake |
| 116 // database handles in incognito mode starting at -1 and progressively getting | 116 // database handles in incognito mode starting at -1 and progressively getting |
| 117 // more negative. | 117 // more negative. |
| 118 // static | 118 // static |
| 119 const int DownloadItem::kUninitializedHandle = 0; | 119 const int DownloadItem::kUninitializedHandle = 0; |
| 120 | 120 |
| 121 // Constructor for reading from the history service. | 121 // Constructor for reading from the history service. |
| 122 DownloadItem::DownloadItem(DownloadManager* download_manager, | 122 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| 123 const DownloadPersistentStoreInfo& info) | 123 const DownloadPersistentStoreInfo& info) |
| 124 : download_id_(-1), | 124 : download_id_(download_manager->GetNextId()), |
| 125 full_path_(info.path), | 125 full_path_(info.path), |
| 126 url_chain_(1, info.url), | 126 url_chain_(1, info.url), |
| 127 referrer_url_(info.referrer_url), | 127 referrer_url_(info.referrer_url), |
| 128 total_bytes_(info.total_bytes), | 128 total_bytes_(info.total_bytes), |
| 129 received_bytes_(info.received_bytes), | 129 received_bytes_(info.received_bytes), |
| 130 start_tick_(base::TimeTicks()), | 130 start_tick_(base::TimeTicks()), |
| 131 state_(static_cast<DownloadState>(info.state)), | 131 state_(static_cast<DownloadState>(info.state)), |
| 132 start_time_(info.start_time), | 132 start_time_(info.start_time), |
| 133 end_time_(info.end_time), | 133 end_time_(info.end_time), |
| 134 db_handle_(info.db_handle), | 134 db_handle_(info.db_handle), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 delegate_delayed_complete_(false) { | 190 delegate_delayed_complete_(false) { |
| 191 Init(true /* actively downloading */); | 191 Init(true /* actively downloading */); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Constructing for the "Save Page As..." feature: | 194 // Constructing for the "Save Page As..." feature: |
| 195 DownloadItem::DownloadItem(DownloadManager* download_manager, | 195 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| 196 const FilePath& path, | 196 const FilePath& path, |
| 197 const GURL& url, | 197 const GURL& url, |
| 198 bool is_otr, | 198 bool is_otr, |
| 199 DownloadId download_id) | 199 DownloadId download_id) |
| 200 : download_id_(download_id.local()), | 200 : download_id_(download_id), |
| 201 full_path_(path), | 201 full_path_(path), |
| 202 url_chain_(1, url), | 202 url_chain_(1, url), |
| 203 referrer_url_(GURL()), | 203 referrer_url_(GURL()), |
| 204 total_bytes_(0), | 204 total_bytes_(0), |
| 205 received_bytes_(0), | 205 received_bytes_(0), |
| 206 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 206 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
| 207 start_tick_(base::TimeTicks::Now()), | 207 start_tick_(base::TimeTicks::Now()), |
| 208 state_(IN_PROGRESS), | 208 state_(IN_PROGRESS), |
| 209 start_time_(base::Time::Now()), | 209 start_time_(base::Time::Now()), |
| 210 db_handle_(DownloadItem::kUninitializedHandle), | 210 db_handle_(DownloadItem::kUninitializedHandle), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 224 } | 224 } |
| 225 | 225 |
| 226 DownloadItem::~DownloadItem() { | 226 DownloadItem::~DownloadItem() { |
| 227 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 227 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 228 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 228 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 229 | 229 |
| 230 TransitionTo(REMOVING); | 230 TransitionTo(REMOVING); |
| 231 download_manager_->AssertQueueStateConsistent(this); | 231 download_manager_->AssertQueueStateConsistent(this); |
| 232 } | 232 } |
| 233 | 233 |
| 234 DownloadId DownloadItem::global_id() const { | |
| 235 return DownloadId(download_manager_, id()); | |
| 236 } | |
| 237 | |
| 238 void DownloadItem::AddObserver(Observer* observer) { | 234 void DownloadItem::AddObserver(Observer* observer) { |
| 239 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 235 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 241 | 237 |
| 242 observers_.AddObserver(observer); | 238 observers_.AddObserver(observer); |
| 243 } | 239 } |
| 244 | 240 |
| 245 void DownloadItem::RemoveObserver(Observer* observer) { | 241 void DownloadItem::RemoveObserver(Observer* observer) { |
| 246 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 242 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 | 762 |
| 767 const GURL& DownloadItem::GetURL() const { | 763 const GURL& DownloadItem::GetURL() const { |
| 768 return url_chain_.empty() ? | 764 return url_chain_.empty() ? |
| 769 GURL::EmptyGURL() : url_chain_.back(); | 765 GURL::EmptyGURL() : url_chain_.back(); |
| 770 } | 766 } |
| 771 | 767 |
| 772 std::string DownloadItem::DebugString(bool verbose) const { | 768 std::string DownloadItem::DebugString(bool verbose) const { |
| 773 std::string description = | 769 std::string description = |
| 774 base::StringPrintf("{ id = %d" | 770 base::StringPrintf("{ id = %d" |
| 775 " state = %s", | 771 " state = %s", |
| 776 download_id_, | 772 download_id_.local(), |
| 777 DebugDownloadStateString(state())); | 773 DebugDownloadStateString(state())); |
| 778 | 774 |
| 779 // Construct a string of the URL chain. | 775 // Construct a string of the URL chain. |
| 780 std::string url_list("<none>"); | 776 std::string url_list("<none>"); |
| 781 if (!url_chain_.empty()) { | 777 if (!url_chain_.empty()) { |
| 782 std::vector<GURL>::const_iterator iter = url_chain_.begin(); | 778 std::vector<GURL>::const_iterator iter = url_chain_.begin(); |
| 783 std::vector<GURL>::const_iterator last = url_chain_.end(); | 779 std::vector<GURL>::const_iterator last = url_chain_.end(); |
| 784 url_list = (*iter).spec(); | 780 url_list = (*iter).spec(); |
| 785 ++iter; | 781 ++iter; |
| 786 for ( ; verbose && (iter != last); ++iter) { | 782 for ( ; verbose && (iter != last); ++iter) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 811 state_info_.target_name.value().c_str(), | 807 state_info_.target_name.value().c_str(), |
| 812 full_path().value().c_str()); | 808 full_path().value().c_str()); |
| 813 } else { | 809 } else { |
| 814 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 810 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
| 815 } | 811 } |
| 816 | 812 |
| 817 description += " }"; | 813 description += " }"; |
| 818 | 814 |
| 819 return description; | 815 return description; |
| 820 } | 816 } |
| OLD | NEW |