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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 by_ext_id = by_ext->id(); | 124 by_ext_id = by_ext->id(); |
125 by_ext_name = by_ext->name(); | 125 by_ext_name = by_ext->name(); |
126 } | 126 } |
127 #endif | 127 #endif |
128 | 128 |
129 return history::DownloadRow( | 129 return history::DownloadRow( |
130 item->GetFullPath(), | 130 item->GetFullPath(), |
131 item->GetTargetFilePath(), | 131 item->GetTargetFilePath(), |
132 item->GetUrlChain(), | 132 item->GetUrlChain(), |
133 item->GetReferrerUrl(), | 133 item->GetReferrerUrl(), |
| 134 std::string(), // HTTP method (not available yet) |
134 item->GetMimeType(), | 135 item->GetMimeType(), |
135 item->GetOriginalMimeType(), | 136 item->GetOriginalMimeType(), |
136 item->GetStartTime(), | 137 item->GetStartTime(), |
137 item->GetEndTime(), | 138 item->GetEndTime(), |
138 item->GetETag(), | 139 item->GetETag(), |
139 item->GetLastModifiedTime(), | 140 item->GetLastModifiedTime(), |
140 item->GetReceivedBytes(), | 141 item->GetReceivedBytes(), |
141 item->GetTotalBytes(), | 142 item->GetTotalBytes(), |
142 history::ToHistoryDownloadState(item->GetState()), | 143 history::ToHistoryDownloadState(item->GetState()), |
143 history::ToHistoryDownloadDangerType(item->GetDangerType()), | 144 history::ToHistoryDownloadDangerType(item->GetDangerType()), |
144 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), | 145 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), |
| 146 std::string(), // Hash value (not available yet) |
145 history::ToHistoryDownloadId(item->GetId()), | 147 history::ToHistoryDownloadId(item->GetId()), |
| 148 item->GetGuid(), |
146 item->GetOpened(), | 149 item->GetOpened(), |
147 by_ext_id, | 150 by_ext_id, |
148 by_ext_name); | 151 by_ext_name); |
149 } | 152 } |
150 | 153 |
151 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 154 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
152 const history::DownloadRow& current) { | 155 const history::DownloadRow& current) { |
153 // Ignore url, referrer, mime_type, original_mime_type, start_time, | 156 // Ignore url_chain, referrer, http_method, mime_type, original_mime_type, |
154 // id, db_handle, which don't change. | 157 // start_time, id, guid, which don't change. |
155 return ((previous == NULL) || | 158 return ((previous == NULL) || |
156 (previous->current_path != current.current_path) || | 159 (previous->current_path != current.current_path) || |
157 (previous->target_path != current.target_path) || | 160 (previous->target_path != current.target_path) || |
158 (previous->end_time != current.end_time) || | 161 (previous->end_time != current.end_time) || |
159 (previous->received_bytes != current.received_bytes) || | 162 (previous->received_bytes != current.received_bytes) || |
160 (previous->total_bytes != current.total_bytes) || | 163 (previous->total_bytes != current.total_bytes) || |
161 (previous->etag != current.etag) || | 164 (previous->etag != current.etag) || |
162 (previous->last_modified != current.last_modified) || | 165 (previous->last_modified != current.last_modified) || |
163 (previous->state != current.state) || | 166 (previous->state != current.state) || |
164 (previous->danger_type != current.danger_type) || | 167 (previous->danger_type != current.danger_type) || |
165 (previous->interrupt_reason != current.interrupt_reason) || | 168 (previous->interrupt_reason != current.interrupt_reason) || |
| 169 (previous->hash != current.hash) || |
166 (previous->opened != current.opened) || | 170 (previous->opened != current.opened) || |
167 (previous->by_ext_id != current.by_ext_id) || | 171 (previous->by_ext_id != current.by_ext_id) || |
168 (previous->by_ext_name != current.by_ext_name)); | 172 (previous->by_ext_name != current.by_ext_name)); |
169 } | 173 } |
170 | 174 |
171 typedef std::vector<history::DownloadRow> InfoVector; | 175 typedef std::vector<history::DownloadRow> InfoVector; |
172 | 176 |
173 } // anonymous namespace | 177 } // anonymous namespace |
174 | 178 |
175 DownloadHistory::HistoryAdapter::HistoryAdapter( | 179 DownloadHistory::HistoryAdapter::HistoryAdapter( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 261 |
258 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { | 262 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { |
259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 263 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
260 // ManagerGoingDown() may have happened before the history loaded. | 264 // ManagerGoingDown() may have happened before the history loaded. |
261 if (!notifier_.GetManager()) | 265 if (!notifier_.GetManager()) |
262 return; | 266 return; |
263 for (InfoVector::const_iterator it = infos->begin(); | 267 for (InfoVector::const_iterator it = infos->begin(); |
264 it != infos->end(); ++it) { | 268 it != infos->end(); ++it) { |
265 loading_id_ = history::ToContentDownloadId(it->id); | 269 loading_id_ = history::ToContentDownloadId(it->id); |
266 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 270 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
| 271 it->guid, |
267 loading_id_, | 272 loading_id_, |
268 it->current_path, | 273 it->current_path, |
269 it->target_path, | 274 it->target_path, |
270 it->url_chain, | 275 it->url_chain, |
271 it->referrer_url, | 276 it->referrer_url, |
272 it->mime_type, | 277 it->mime_type, |
273 it->original_mime_type, | 278 it->original_mime_type, |
274 it->start_time, | 279 it->start_time, |
275 it->end_time, | 280 it->end_time, |
276 it->etag, | 281 it->etag, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 removing_ids_.insert(download_id); | 465 removing_ids_.insert(download_id); |
461 } | 466 } |
462 | 467 |
463 void DownloadHistory::RemoveDownloadsBatch() { | 468 void DownloadHistory::RemoveDownloadsBatch() { |
464 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 469 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
465 IdSet remove_ids; | 470 IdSet remove_ids; |
466 removing_ids_.swap(remove_ids); | 471 removing_ids_.swap(remove_ids); |
467 history_->RemoveDownloads(remove_ids); | 472 history_->RemoveDownloads(remove_ids); |
468 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 473 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
469 } | 474 } |
OLD | NEW |