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 // DownloadHistory manages persisting DownloadItems to the history service by | 5 // DownloadHistory manages persisting DownloadItems to the history service by |
6 // observing a single DownloadManager and all its DownloadItems using an | 6 // observing a single DownloadManager and all its DownloadItems using an |
7 // AllDownloadItemNotifier. | 7 // AllDownloadItemNotifier. |
8 // | 8 // |
9 // DownloadHistory decides whether and when to add items to, remove items from, | 9 // DownloadHistory decides whether and when to add items to, remove items from, |
10 // and update items in the database. DownloadHistory uses DownloadHistoryData to | 10 // and update items in the database. DownloadHistory uses DownloadHistoryData to |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 item->GetTabReferrerUrl(), | 134 item->GetTabReferrerUrl(), |
135 std::string(), // HTTP method (not available yet) | 135 std::string(), // HTTP method (not available yet) |
136 item->GetMimeType(), item->GetOriginalMimeType(), item->GetStartTime(), | 136 item->GetMimeType(), item->GetOriginalMimeType(), item->GetStartTime(), |
137 item->GetEndTime(), item->GetETag(), item->GetLastModifiedTime(), | 137 item->GetEndTime(), item->GetETag(), item->GetLastModifiedTime(), |
138 item->GetReceivedBytes(), item->GetTotalBytes(), | 138 item->GetReceivedBytes(), item->GetTotalBytes(), |
139 history::ToHistoryDownloadState(item->GetState()), | 139 history::ToHistoryDownloadState(item->GetState()), |
140 history::ToHistoryDownloadDangerType(item->GetDangerType()), | 140 history::ToHistoryDownloadDangerType(item->GetDangerType()), |
141 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), | 141 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), |
142 std::string(), // Hash value (not available yet) | 142 std::string(), // Hash value (not available yet) |
143 history::ToHistoryDownloadId(item->GetId()), item->GetGuid(), | 143 history::ToHistoryDownloadId(item->GetId()), item->GetGuid(), |
144 item->GetOpened(), by_ext_id, by_ext_name, | 144 item->GetOpened(), item->GetLastAccessTime(), by_ext_id, by_ext_name, |
145 history::GetHistoryDownloadSliceInfos(*item)); | 145 history::GetHistoryDownloadSliceInfos(*item)); |
146 } | 146 } |
147 | 147 |
148 enum class ShouldUpdateHistoryResult { | 148 enum class ShouldUpdateHistoryResult { |
149 NO_UPDATE, | 149 NO_UPDATE, |
150 UPDATE, | 150 UPDATE, |
151 UPDATE_IMMEDIATELY, | 151 UPDATE_IMMEDIATELY, |
152 }; | 152 }; |
153 | 153 |
154 ShouldUpdateHistoryResult ShouldUpdateHistory( | 154 ShouldUpdateHistoryResult ShouldUpdateHistory( |
(...skipping 16 matching lines...) Expand all Loading... |
171 (previous->end_time != current.end_time) || | 171 (previous->end_time != current.end_time) || |
172 (previous->received_bytes != current.received_bytes) || | 172 (previous->received_bytes != current.received_bytes) || |
173 (previous->total_bytes != current.total_bytes) || | 173 (previous->total_bytes != current.total_bytes) || |
174 (previous->etag != current.etag) || | 174 (previous->etag != current.etag) || |
175 (previous->last_modified != current.last_modified) || | 175 (previous->last_modified != current.last_modified) || |
176 (previous->state != current.state) || | 176 (previous->state != current.state) || |
177 (previous->danger_type != current.danger_type) || | 177 (previous->danger_type != current.danger_type) || |
178 (previous->interrupt_reason != current.interrupt_reason) || | 178 (previous->interrupt_reason != current.interrupt_reason) || |
179 (previous->hash != current.hash) || | 179 (previous->hash != current.hash) || |
180 (previous->opened != current.opened) || | 180 (previous->opened != current.opened) || |
| 181 (previous->last_access_time != current.last_access_time) || |
181 (previous->by_ext_id != current.by_ext_id) || | 182 (previous->by_ext_id != current.by_ext_id) || |
182 (previous->by_ext_name != current.by_ext_name) || | 183 (previous->by_ext_name != current.by_ext_name) || |
183 (previous->download_slice_info != current.download_slice_info)) { | 184 (previous->download_slice_info != current.download_slice_info)) { |
184 return ShouldUpdateHistoryResult::UPDATE; | 185 return ShouldUpdateHistoryResult::UPDATE; |
185 } | 186 } |
186 | 187 |
187 return ShouldUpdateHistoryResult::NO_UPDATE; | 188 return ShouldUpdateHistoryResult::NO_UPDATE; |
188 } | 189 } |
189 | 190 |
190 typedef std::vector<history::DownloadRow> InfoVector; | 191 typedef std::vector<history::DownloadRow> InfoVector; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 it->guid, loading_id_, it->current_path, it->target_path, it->url_chain, | 292 it->guid, loading_id_, it->current_path, it->target_path, it->url_chain, |
292 it->referrer_url, it->site_url, it->tab_url, it->tab_referrer_url, | 293 it->referrer_url, it->site_url, it->tab_url, it->tab_referrer_url, |
293 it->mime_type, it->original_mime_type, it->start_time, it->end_time, | 294 it->mime_type, it->original_mime_type, it->start_time, it->end_time, |
294 it->etag, it->last_modified, it->received_bytes, it->total_bytes, | 295 it->etag, it->last_modified, it->received_bytes, it->total_bytes, |
295 std::string(), // TODO(asanka): Need to persist and restore hash of | 296 std::string(), // TODO(asanka): Need to persist and restore hash of |
296 // partial file for an interrupted download. No need to | 297 // partial file for an interrupted download. No need to |
297 // store hash for a completed file. | 298 // store hash for a completed file. |
298 history::ToContentDownloadState(it->state), | 299 history::ToContentDownloadState(it->state), |
299 history::ToContentDownloadDangerType(it->danger_type), | 300 history::ToContentDownloadDangerType(it->danger_type), |
300 history::ToContentDownloadInterruptReason(it->interrupt_reason), | 301 history::ToContentDownloadInterruptReason(it->interrupt_reason), |
301 it->opened, history::ToContentReceivedSlices(it->download_slice_info)); | 302 it->opened, it->last_access_time, |
| 303 history::ToContentReceivedSlices(it->download_slice_info)); |
302 #if BUILDFLAG(ENABLE_EXTENSIONS) | 304 #if BUILDFLAG(ENABLE_EXTENSIONS) |
303 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { | 305 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { |
304 new extensions::DownloadedByExtension( | 306 new extensions::DownloadedByExtension( |
305 item, it->by_ext_id, it->by_ext_name); | 307 item, it->by_ext_id, it->by_ext_name); |
306 item->UpdateObservers(); | 308 item->UpdateObservers(); |
307 } | 309 } |
308 #endif | 310 #endif |
309 DCHECK_EQ(DownloadHistoryData::PERSISTED, | 311 DCHECK_EQ(DownloadHistoryData::PERSISTED, |
310 DownloadHistoryData::Get(item)->state()); | 312 DownloadHistoryData::Get(item)->state()); |
311 ++history_size_; | 313 ++history_size_; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 494 } |
493 | 495 |
494 void DownloadHistory::RemoveDownloadsBatch() { | 496 void DownloadHistory::RemoveDownloadsBatch() { |
495 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 497 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
496 IdSet remove_ids; | 498 IdSet remove_ids; |
497 removing_ids_.swap(remove_ids); | 499 removing_ids_.swap(remove_ids); |
498 history_->RemoveDownloads(remove_ids); | 500 history_->RemoveDownloads(remove_ids); |
499 for (Observer& observer : observers_) | 501 for (Observer& observer : observers_) |
500 observer.OnDownloadsRemoved(remove_ids); | 502 observer.OnDownloadsRemoved(remove_ids); |
501 } | 503 } |
OLD | NEW |