| 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 by_ext_id = by_ext->id(); | 121 by_ext_id = by_ext->id(); |
| 122 by_ext_name = by_ext->name(); | 122 by_ext_name = by_ext->name(); |
| 123 } | 123 } |
| 124 #endif | 124 #endif |
| 125 | 125 |
| 126 return history::DownloadRow( | 126 return history::DownloadRow( |
| 127 item->GetFullPath(), | 127 item->GetFullPath(), |
| 128 item->GetTargetFilePath(), | 128 item->GetTargetFilePath(), |
| 129 item->GetUrlChain(), | 129 item->GetUrlChain(), |
| 130 item->GetReferrerUrl(), | 130 item->GetReferrerUrl(), |
| 131 item->GetMimeType(), |
| 132 item->GetOriginalMimeType(), |
| 131 item->GetStartTime(), | 133 item->GetStartTime(), |
| 132 item->GetEndTime(), | 134 item->GetEndTime(), |
| 133 item->GetETag(), | 135 item->GetETag(), |
| 134 item->GetLastModifiedTime(), | 136 item->GetLastModifiedTime(), |
| 135 item->GetReceivedBytes(), | 137 item->GetReceivedBytes(), |
| 136 item->GetTotalBytes(), | 138 item->GetTotalBytes(), |
| 137 item->GetState(), | 139 item->GetState(), |
| 138 item->GetDangerType(), | 140 item->GetDangerType(), |
| 139 item->GetLastReason(), | 141 item->GetLastReason(), |
| 140 item->GetId(), | 142 item->GetId(), |
| 141 item->GetOpened(), | 143 item->GetOpened(), |
| 142 by_ext_id, | 144 by_ext_id, |
| 143 by_ext_name); | 145 by_ext_name); |
| 144 } | 146 } |
| 145 | 147 |
| 146 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 148 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
| 147 const history::DownloadRow& current) { | 149 const history::DownloadRow& current) { |
| 148 // Ignore url, referrer, start_time, id, which don't change. | 150 // Ignore url, referrer, mime_type, original_mime_type, start_time, |
| 151 // id, db_handle, which don't change. |
| 149 return ((previous == NULL) || | 152 return ((previous == NULL) || |
| 150 (previous->current_path != current.current_path) || | 153 (previous->current_path != current.current_path) || |
| 151 (previous->target_path != current.target_path) || | 154 (previous->target_path != current.target_path) || |
| 152 (previous->end_time != current.end_time) || | 155 (previous->end_time != current.end_time) || |
| 153 (previous->received_bytes != current.received_bytes) || | 156 (previous->received_bytes != current.received_bytes) || |
| 154 (previous->total_bytes != current.total_bytes) || | 157 (previous->total_bytes != current.total_bytes) || |
| 155 (previous->etag != current.etag) || | 158 (previous->etag != current.etag) || |
| 156 (previous->last_modified != current.last_modified) || | 159 (previous->last_modified != current.last_modified) || |
| 157 (previous->state != current.state) || | 160 (previous->state != current.state) || |
| 158 (previous->danger_type != current.danger_type) || | 161 (previous->danger_type != current.danger_type) || |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return; | 258 return; |
| 256 for (InfoVector::const_iterator it = infos->begin(); | 259 for (InfoVector::const_iterator it = infos->begin(); |
| 257 it != infos->end(); ++it) { | 260 it != infos->end(); ++it) { |
| 258 loading_id_ = it->id; | 261 loading_id_ = it->id; |
| 259 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 262 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
| 260 loading_id_, | 263 loading_id_, |
| 261 it->current_path, | 264 it->current_path, |
| 262 it->target_path, | 265 it->target_path, |
| 263 it->url_chain, | 266 it->url_chain, |
| 264 it->referrer_url, | 267 it->referrer_url, |
| 268 it->mime_type, |
| 269 it->original_mime_type, |
| 265 it->start_time, | 270 it->start_time, |
| 266 it->end_time, | 271 it->end_time, |
| 267 it->etag, | 272 it->etag, |
| 268 it->last_modified, | 273 it->last_modified, |
| 269 it->received_bytes, | 274 it->received_bytes, |
| 270 it->total_bytes, | 275 it->total_bytes, |
| 271 it->state, | 276 it->state, |
| 272 it->danger_type, | 277 it->danger_type, |
| 273 it->interrupt_reason, | 278 it->interrupt_reason, |
| 274 it->opened); | 279 it->opened); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 removing_ids_.insert(download_id); | 456 removing_ids_.insert(download_id); |
| 452 } | 457 } |
| 453 | 458 |
| 454 void DownloadHistory::RemoveDownloadsBatch() { | 459 void DownloadHistory::RemoveDownloadsBatch() { |
| 455 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 460 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 456 IdSet remove_ids; | 461 IdSet remove_ids; |
| 457 removing_ids_.swap(remove_ids); | 462 removing_ids_.swap(remove_ids); |
| 458 history_->RemoveDownloads(remove_ids); | 463 history_->RemoveDownloads(remove_ids); |
| 459 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 464 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
| 460 } | 465 } |
| OLD | NEW |