| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 by_ext_id = by_ext->id(); | 107 by_ext_id = by_ext->id(); |
| 108 by_ext_name = by_ext->name(); | 108 by_ext_name = by_ext->name(); |
| 109 } | 109 } |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 return history::DownloadRow( | 112 return history::DownloadRow( |
| 113 item->GetFullPath(), | 113 item->GetFullPath(), |
| 114 item->GetTargetFilePath(), | 114 item->GetTargetFilePath(), |
| 115 item->GetUrlChain(), | 115 item->GetUrlChain(), |
| 116 item->GetReferrerUrl(), | 116 item->GetReferrerUrl(), |
| 117 item->GetMimeType(), |
| 118 item->GetOriginalMimeType(), |
| 117 item->GetStartTime(), | 119 item->GetStartTime(), |
| 118 item->GetEndTime(), | 120 item->GetEndTime(), |
| 119 item->GetETag(), | 121 item->GetETag(), |
| 120 item->GetLastModifiedTime(), | 122 item->GetLastModifiedTime(), |
| 121 item->GetReceivedBytes(), | 123 item->GetReceivedBytes(), |
| 122 item->GetTotalBytes(), | 124 item->GetTotalBytes(), |
| 123 item->GetState(), | 125 item->GetState(), |
| 124 item->GetDangerType(), | 126 item->GetDangerType(), |
| 125 item->GetLastReason(), | 127 item->GetLastReason(), |
| 126 item->GetId(), | 128 item->GetId(), |
| 127 item->GetOpened(), | 129 item->GetOpened(), |
| 128 by_ext_id, | 130 by_ext_id, |
| 129 by_ext_name); | 131 by_ext_name); |
| 130 } | 132 } |
| 131 | 133 |
| 132 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 134 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
| 133 const history::DownloadRow& current) { | 135 const history::DownloadRow& current) { |
| 134 // Ignore url, referrer, start_time, id, which don't change. | 136 // Ignore url, referrer, mime_type, original_mime_type, start_time, |
| 137 // id, db_handle, which don't change. |
| 135 return ((previous == NULL) || | 138 return ((previous == NULL) || |
| 136 (previous->current_path != current.current_path) || | 139 (previous->current_path != current.current_path) || |
| 137 (previous->target_path != current.target_path) || | 140 (previous->target_path != current.target_path) || |
| 138 (previous->end_time != current.end_time) || | 141 (previous->end_time != current.end_time) || |
| 139 (previous->received_bytes != current.received_bytes) || | 142 (previous->received_bytes != current.received_bytes) || |
| 140 (previous->total_bytes != current.total_bytes) || | 143 (previous->total_bytes != current.total_bytes) || |
| 141 (previous->etag != current.etag) || | 144 (previous->etag != current.etag) || |
| 142 (previous->last_modified != current.last_modified) || | 145 (previous->last_modified != current.last_modified) || |
| 143 (previous->state != current.state) || | 146 (previous->state != current.state) || |
| 144 (previous->danger_type != current.danger_type) || | 147 (previous->danger_type != current.danger_type) || |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return; | 231 return; |
| 229 for (InfoVector::const_iterator it = infos->begin(); | 232 for (InfoVector::const_iterator it = infos->begin(); |
| 230 it != infos->end(); ++it) { | 233 it != infos->end(); ++it) { |
| 231 loading_id_ = it->id; | 234 loading_id_ = it->id; |
| 232 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 235 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
| 233 loading_id_, | 236 loading_id_, |
| 234 it->current_path, | 237 it->current_path, |
| 235 it->target_path, | 238 it->target_path, |
| 236 it->url_chain, | 239 it->url_chain, |
| 237 it->referrer_url, | 240 it->referrer_url, |
| 241 it->mime_type, |
| 242 it->original_mime_type, |
| 238 it->start_time, | 243 it->start_time, |
| 239 it->end_time, | 244 it->end_time, |
| 240 it->etag, | 245 it->etag, |
| 241 it->last_modified, | 246 it->last_modified, |
| 242 it->received_bytes, | 247 it->received_bytes, |
| 243 it->total_bytes, | 248 it->total_bytes, |
| 244 it->state, | 249 it->state, |
| 245 it->danger_type, | 250 it->danger_type, |
| 246 it->interrupt_reason, | 251 it->interrupt_reason, |
| 247 it->opened); | 252 it->opened); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 removing_ids_.insert(download_id); | 427 removing_ids_.insert(download_id); |
| 423 } | 428 } |
| 424 | 429 |
| 425 void DownloadHistory::RemoveDownloadsBatch() { | 430 void DownloadHistory::RemoveDownloadsBatch() { |
| 426 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 431 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 427 IdSet remove_ids; | 432 IdSet remove_ids; |
| 428 removing_ids_.swap(remove_ids); | 433 removing_ids_.swap(remove_ids); |
| 429 history_->RemoveDownloads(remove_ids); | 434 history_->RemoveDownloads(remove_ids); |
| 430 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 435 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
| 431 } | 436 } |
| OLD | NEW |