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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(), item->GetTargetFilePath(), item->GetUrlChain(), | 130 item->GetFullPath(), item->GetTargetFilePath(), item->GetUrlChain(), |
131 item->GetReferrerUrl(), item->GetTabUrl(), item->GetTabReferrerUrl(), | 131 item->GetReferrerUrl(), item->GetSiteUrl(), item->GetTabUrl(), |
| 132 item->GetTabReferrerUrl(), |
132 std::string(), // HTTP method (not available yet) | 133 std::string(), // HTTP method (not available yet) |
133 item->GetMimeType(), item->GetOriginalMimeType(), item->GetStartTime(), | 134 item->GetMimeType(), item->GetOriginalMimeType(), item->GetStartTime(), |
134 item->GetEndTime(), item->GetETag(), item->GetLastModifiedTime(), | 135 item->GetEndTime(), item->GetETag(), item->GetLastModifiedTime(), |
135 item->GetReceivedBytes(), item->GetTotalBytes(), | 136 item->GetReceivedBytes(), item->GetTotalBytes(), |
136 history::ToHistoryDownloadState(item->GetState()), | 137 history::ToHistoryDownloadState(item->GetState()), |
137 history::ToHistoryDownloadDangerType(item->GetDangerType()), | 138 history::ToHistoryDownloadDangerType(item->GetDangerType()), |
138 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), | 139 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), |
139 std::string(), // Hash value (not available yet) | 140 std::string(), // Hash value (not available yet) |
140 history::ToHistoryDownloadId(item->GetId()), item->GetGuid(), | 141 history::ToHistoryDownloadId(item->GetId()), item->GetGuid(), |
141 item->GetOpened(), by_ext_id, by_ext_name); | 142 item->GetOpened(), by_ext_id, by_ext_name); |
142 } | 143 } |
143 | 144 |
144 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 145 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
145 const history::DownloadRow& current) { | 146 const history::DownloadRow& current) { |
146 // Ignore url_chain, referrer, http_method, mime_type, original_mime_type, | 147 // Ignore url_chain, referrer, site_url, http_method, mime_type, |
147 // start_time, id, guid, which don't change. | 148 // original_mime_type, start_time, id, and guid. These fields don't change. |
148 return ((previous == NULL) || | 149 return ((previous == NULL) || |
149 (previous->current_path != current.current_path) || | 150 (previous->current_path != current.current_path) || |
150 (previous->target_path != current.target_path) || | 151 (previous->target_path != current.target_path) || |
151 (previous->end_time != current.end_time) || | 152 (previous->end_time != current.end_time) || |
152 (previous->received_bytes != current.received_bytes) || | 153 (previous->received_bytes != current.received_bytes) || |
153 (previous->total_bytes != current.total_bytes) || | 154 (previous->total_bytes != current.total_bytes) || |
154 (previous->etag != current.etag) || | 155 (previous->etag != current.etag) || |
155 (previous->last_modified != current.last_modified) || | 156 (previous->last_modified != current.last_modified) || |
156 (previous->state != current.state) || | 157 (previous->state != current.state) || |
157 (previous->danger_type != current.danger_type) || | 158 (previous->danger_type != current.danger_type) || |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 void DownloadHistory::QueryCallback(std::unique_ptr<InfoVector> infos) { | 257 void DownloadHistory::QueryCallback(std::unique_ptr<InfoVector> infos) { |
257 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
258 // ManagerGoingDown() may have happened before the history loaded. | 259 // ManagerGoingDown() may have happened before the history loaded. |
259 if (!notifier_.GetManager()) | 260 if (!notifier_.GetManager()) |
260 return; | 261 return; |
261 for (InfoVector::const_iterator it = infos->begin(); | 262 for (InfoVector::const_iterator it = infos->begin(); |
262 it != infos->end(); ++it) { | 263 it != infos->end(); ++it) { |
263 loading_id_ = history::ToContentDownloadId(it->id); | 264 loading_id_ = history::ToContentDownloadId(it->id); |
264 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 265 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
265 it->guid, loading_id_, it->current_path, it->target_path, it->url_chain, | 266 it->guid, loading_id_, it->current_path, it->target_path, it->url_chain, |
266 it->referrer_url, it->tab_url, it->tab_referrer_url, it->mime_type, | 267 it->referrer_url, it->site_url, it->tab_url, it->tab_referrer_url, |
267 it->original_mime_type, it->start_time, it->end_time, it->etag, | 268 it->mime_type, it->original_mime_type, it->start_time, it->end_time, |
268 it->last_modified, it->received_bytes, it->total_bytes, | 269 it->etag, it->last_modified, it->received_bytes, it->total_bytes, |
269 std::string(), // TODO(asanka): Need to persist and restore hash of | 270 std::string(), // TODO(asanka): Need to persist and restore hash of |
270 // partial file for an interrupted download. No need to | 271 // partial file for an interrupted download. No need to |
271 // store hash for a completed file. | 272 // store hash for a completed file. |
272 history::ToContentDownloadState(it->state), | 273 history::ToContentDownloadState(it->state), |
273 history::ToContentDownloadDangerType(it->danger_type), | 274 history::ToContentDownloadDangerType(it->danger_type), |
274 history::ToContentDownloadInterruptReason(it->interrupt_reason), | 275 history::ToContentDownloadInterruptReason(it->interrupt_reason), |
275 it->opened); | 276 it->opened); |
276 #if defined(ENABLE_EXTENSIONS) | 277 #if defined(ENABLE_EXTENSIONS) |
277 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { | 278 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { |
278 new extensions::DownloadedByExtension( | 279 new extensions::DownloadedByExtension( |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 removing_ids_.insert(download_id); | 456 removing_ids_.insert(download_id); |
456 } | 457 } |
457 | 458 |
458 void DownloadHistory::RemoveDownloadsBatch() { | 459 void DownloadHistory::RemoveDownloadsBatch() { |
459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 460 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
460 IdSet remove_ids; | 461 IdSet remove_ids; |
461 removing_ids_.swap(remove_ids); | 462 removing_ids_.swap(remove_ids); |
462 history_->RemoveDownloads(remove_ids); | 463 history_->RemoveDownloads(remove_ids); |
463 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 464 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
464 } | 465 } |
OLD | NEW |