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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 #if defined(ENABLE_EXTENSIONS) | 120 #if defined(ENABLE_EXTENSIONS) |
121 extensions::DownloadedByExtension* by_ext = | 121 extensions::DownloadedByExtension* by_ext = |
122 extensions::DownloadedByExtension::Get(item); | 122 extensions::DownloadedByExtension::Get(item); |
123 if (by_ext) { | 123 if (by_ext) { |
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(), item->GetTargetFilePath(), item->GetUrlChain(), |
131 item->GetTargetFilePath(), | |
132 item->GetUrlChain(), | |
133 item->GetReferrerUrl(), | 131 item->GetReferrerUrl(), |
134 item->GetMimeType(), | 132 std::string(), // HTTP method (not available yet) |
135 item->GetOriginalMimeType(), | 133 item->GetMimeType(), item->GetOriginalMimeType(), item->GetStartTime(), |
136 item->GetStartTime(), | 134 item->GetEndTime(), item->GetETag(), item->GetLastModifiedTime(), |
137 item->GetEndTime(), | 135 item->GetReceivedBytes(), item->GetTotalBytes(), |
138 item->GetETag(), | |
139 item->GetLastModifiedTime(), | |
140 item->GetReceivedBytes(), | |
141 item->GetTotalBytes(), | |
142 history::ToHistoryDownloadState(item->GetState()), | 136 history::ToHistoryDownloadState(item->GetState()), |
143 history::ToHistoryDownloadDangerType(item->GetDangerType()), | 137 history::ToHistoryDownloadDangerType(item->GetDangerType()), |
144 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), | 138 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), |
145 history::ToHistoryDownloadId(item->GetId()), | 139 std::string(), // Hash value (not available yet) |
146 item->GetOpened(), | 140 history::ToHistoryDownloadId(item->GetId()), item->GetGuid(), |
147 by_ext_id, | 141 item->GetOpened(), by_ext_id, by_ext_name); |
148 by_ext_name); | |
149 } | 142 } |
150 | 143 |
151 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 144 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
152 const history::DownloadRow& current) { | 145 const history::DownloadRow& current) { |
153 // Ignore url, referrer, mime_type, original_mime_type, start_time, | 146 // Ignore url_chain, referrer, http_method, mime_type, original_mime_type, |
154 // id, db_handle, which don't change. | 147 // start_time, id, guid, which don't change. |
155 return ((previous == NULL) || | 148 return ((previous == NULL) || |
156 (previous->current_path != current.current_path) || | 149 (previous->current_path != current.current_path) || |
157 (previous->target_path != current.target_path) || | 150 (previous->target_path != current.target_path) || |
158 (previous->end_time != current.end_time) || | 151 (previous->end_time != current.end_time) || |
159 (previous->received_bytes != current.received_bytes) || | 152 (previous->received_bytes != current.received_bytes) || |
160 (previous->total_bytes != current.total_bytes) || | 153 (previous->total_bytes != current.total_bytes) || |
161 (previous->etag != current.etag) || | 154 (previous->etag != current.etag) || |
162 (previous->last_modified != current.last_modified) || | 155 (previous->last_modified != current.last_modified) || |
163 (previous->state != current.state) || | 156 (previous->state != current.state) || |
164 (previous->danger_type != current.danger_type) || | 157 (previous->danger_type != current.danger_type) || |
165 (previous->interrupt_reason != current.interrupt_reason) || | 158 (previous->interrupt_reason != current.interrupt_reason) || |
| 159 (previous->hash != current.hash) || |
166 (previous->opened != current.opened) || | 160 (previous->opened != current.opened) || |
167 (previous->by_ext_id != current.by_ext_id) || | 161 (previous->by_ext_id != current.by_ext_id) || |
168 (previous->by_ext_name != current.by_ext_name)); | 162 (previous->by_ext_name != current.by_ext_name)); |
169 } | 163 } |
170 | 164 |
171 typedef std::vector<history::DownloadRow> InfoVector; | 165 typedef std::vector<history::DownloadRow> InfoVector; |
172 | 166 |
173 } // anonymous namespace | 167 } // anonymous namespace |
174 | 168 |
175 DownloadHistory::HistoryAdapter::HistoryAdapter( | 169 DownloadHistory::HistoryAdapter::HistoryAdapter( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 251 |
258 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { | 252 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { |
259 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 253 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
260 // ManagerGoingDown() may have happened before the history loaded. | 254 // ManagerGoingDown() may have happened before the history loaded. |
261 if (!notifier_.GetManager()) | 255 if (!notifier_.GetManager()) |
262 return; | 256 return; |
263 for (InfoVector::const_iterator it = infos->begin(); | 257 for (InfoVector::const_iterator it = infos->begin(); |
264 it != infos->end(); ++it) { | 258 it != infos->end(); ++it) { |
265 loading_id_ = history::ToContentDownloadId(it->id); | 259 loading_id_ = history::ToContentDownloadId(it->id); |
266 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 260 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
267 loading_id_, | 261 it->guid, loading_id_, it->current_path, it->target_path, it->url_chain, |
268 it->current_path, | 262 it->referrer_url, it->mime_type, it->original_mime_type, it->start_time, |
269 it->target_path, | 263 it->end_time, it->etag, it->last_modified, it->received_bytes, |
270 it->url_chain, | 264 it->total_bytes, history::ToContentDownloadState(it->state), |
271 it->referrer_url, | |
272 it->mime_type, | |
273 it->original_mime_type, | |
274 it->start_time, | |
275 it->end_time, | |
276 it->etag, | |
277 it->last_modified, | |
278 it->received_bytes, | |
279 it->total_bytes, | |
280 history::ToContentDownloadState(it->state), | |
281 history::ToContentDownloadDangerType(it->danger_type), | 265 history::ToContentDownloadDangerType(it->danger_type), |
282 history::ToContentDownloadInterruptReason(it->interrupt_reason), | 266 history::ToContentDownloadInterruptReason(it->interrupt_reason), |
283 it->opened); | 267 it->opened); |
284 #if defined(ENABLE_EXTENSIONS) | 268 #if defined(ENABLE_EXTENSIONS) |
285 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { | 269 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { |
286 new extensions::DownloadedByExtension( | 270 new extensions::DownloadedByExtension( |
287 item, it->by_ext_id, it->by_ext_name); | 271 item, it->by_ext_id, it->by_ext_name); |
288 item->UpdateObservers(); | 272 item->UpdateObservers(); |
289 } | 273 } |
290 #endif | 274 #endif |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 removing_ids_.insert(download_id); | 444 removing_ids_.insert(download_id); |
461 } | 445 } |
462 | 446 |
463 void DownloadHistory::RemoveDownloadsBatch() { | 447 void DownloadHistory::RemoveDownloadsBatch() { |
464 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 448 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
465 IdSet remove_ids; | 449 IdSet remove_ids; |
466 removing_ids_.swap(remove_ids); | 450 removing_ids_.swap(remove_ids); |
467 history_->RemoveDownloads(remove_ids); | 451 history_->RemoveDownloads(remove_ids); |
468 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 452 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
469 } | 453 } |
OLD | NEW |