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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
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 const DownloadId& download_id) |
| 125 : download_id_(download_id), |
125 full_path_(info.path), | 126 full_path_(info.path), |
126 url_chain_(1, info.url), | 127 url_chain_(1, info.url), |
127 referrer_url_(info.referrer_url), | 128 referrer_url_(info.referrer_url), |
128 total_bytes_(info.total_bytes), | 129 total_bytes_(info.total_bytes), |
129 received_bytes_(info.received_bytes), | 130 received_bytes_(info.received_bytes), |
130 start_tick_(base::TimeTicks()), | 131 start_tick_(base::TimeTicks()), |
131 state_(static_cast<DownloadState>(info.state)), | 132 state_(static_cast<DownloadState>(info.state)), |
132 start_time_(info.start_time), | 133 start_time_(info.start_time), |
133 end_time_(info.end_time), | 134 end_time_(info.end_time), |
134 db_handle_(info.db_handle), | 135 db_handle_(info.db_handle), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 delegate_delayed_complete_(false) { | 192 delegate_delayed_complete_(false) { |
192 Init(true /* actively downloading */); | 193 Init(true /* actively downloading */); |
193 } | 194 } |
194 | 195 |
195 // Constructing for the "Save Page As..." feature: | 196 // Constructing for the "Save Page As..." feature: |
196 DownloadItem::DownloadItem(DownloadManager* download_manager, | 197 DownloadItem::DownloadItem(DownloadManager* download_manager, |
197 const FilePath& path, | 198 const FilePath& path, |
198 const GURL& url, | 199 const GURL& url, |
199 bool is_otr, | 200 bool is_otr, |
200 DownloadId download_id) | 201 DownloadId download_id) |
201 : download_id_(download_id.local()), | 202 : download_id_(download_id), |
202 full_path_(path), | 203 full_path_(path), |
203 url_chain_(1, url), | 204 url_chain_(1, url), |
204 referrer_url_(GURL()), | 205 referrer_url_(GURL()), |
205 total_bytes_(0), | 206 total_bytes_(0), |
206 received_bytes_(0), | 207 received_bytes_(0), |
207 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 208 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
208 start_tick_(base::TimeTicks::Now()), | 209 start_tick_(base::TimeTicks::Now()), |
209 state_(IN_PROGRESS), | 210 state_(IN_PROGRESS), |
210 start_time_(base::Time::Now()), | 211 start_time_(base::Time::Now()), |
211 db_handle_(DownloadItem::kUninitializedHandle), | 212 db_handle_(DownloadItem::kUninitializedHandle), |
(...skipping 13 matching lines...) Expand all Loading... |
225 } | 226 } |
226 | 227 |
227 DownloadItem::~DownloadItem() { | 228 DownloadItem::~DownloadItem() { |
228 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 229 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
230 | 231 |
231 TransitionTo(REMOVING); | 232 TransitionTo(REMOVING); |
232 download_manager_->AssertQueueStateConsistent(this); | 233 download_manager_->AssertQueueStateConsistent(this); |
233 } | 234 } |
234 | 235 |
235 DownloadId DownloadItem::global_id() const { | |
236 return DownloadId(download_manager_, id()); | |
237 } | |
238 | |
239 void DownloadItem::AddObserver(Observer* observer) { | 236 void DownloadItem::AddObserver(Observer* observer) { |
240 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 237 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 238 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
242 | 239 |
243 observers_.AddObserver(observer); | 240 observers_.AddObserver(observer); |
244 } | 241 } |
245 | 242 |
246 void DownloadItem::RemoveObserver(Observer* observer) { | 243 void DownloadItem::RemoveObserver(Observer* observer) { |
247 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 244 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 | 764 |
768 const GURL& DownloadItem::GetURL() const { | 765 const GURL& DownloadItem::GetURL() const { |
769 return url_chain_.empty() ? | 766 return url_chain_.empty() ? |
770 GURL::EmptyGURL() : url_chain_.back(); | 767 GURL::EmptyGURL() : url_chain_.back(); |
771 } | 768 } |
772 | 769 |
773 std::string DownloadItem::DebugString(bool verbose) const { | 770 std::string DownloadItem::DebugString(bool verbose) const { |
774 std::string description = | 771 std::string description = |
775 base::StringPrintf("{ id = %d" | 772 base::StringPrintf("{ id = %d" |
776 " state = %s", | 773 " state = %s", |
777 download_id_, | 774 download_id_.local(), |
778 DebugDownloadStateString(state())); | 775 DebugDownloadStateString(state())); |
779 | 776 |
780 // Construct a string of the URL chain. | 777 // Construct a string of the URL chain. |
781 std::string url_list("<none>"); | 778 std::string url_list("<none>"); |
782 if (!url_chain_.empty()) { | 779 if (!url_chain_.empty()) { |
783 std::vector<GURL>::const_iterator iter = url_chain_.begin(); | 780 std::vector<GURL>::const_iterator iter = url_chain_.begin(); |
784 std::vector<GURL>::const_iterator last = url_chain_.end(); | 781 std::vector<GURL>::const_iterator last = url_chain_.end(); |
785 url_list = (*iter).spec(); | 782 url_list = (*iter).spec(); |
786 ++iter; | 783 ++iter; |
787 for ( ; verbose && (iter != last); ++iter) { | 784 for ( ; verbose && (iter != last); ++iter) { |
(...skipping 24 matching lines...) Expand all Loading... |
812 state_info_.target_name.value().c_str(), | 809 state_info_.target_name.value().c_str(), |
813 full_path().value().c_str()); | 810 full_path().value().c_str()); |
814 } else { | 811 } else { |
815 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 812 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
816 } | 813 } |
817 | 814 |
818 description += " }"; | 815 description += " }"; |
819 | 816 |
820 return description; | 817 return description; |
821 } | 818 } |
OLD | NEW |