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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 const char DownloadHistoryData::kKey[] = | 101 const char DownloadHistoryData::kKey[] = |
102 "DownloadItem DownloadHistoryData"; | 102 "DownloadItem DownloadHistoryData"; |
103 | 103 |
104 history::DownloadRow GetDownloadRow( | 104 history::DownloadRow GetDownloadRow( |
105 content::DownloadItem* item) { | 105 content::DownloadItem* item) { |
106 // TODO(asanka): Persist GetTargetFilePath() as well. | 106 // TODO(asanka): Persist GetTargetFilePath() as well. |
107 DownloadHistoryData* data = DownloadHistoryData::Get(item); | 107 DownloadHistoryData* data = DownloadHistoryData::Get(item); |
108 return history::DownloadRow( | 108 return history::DownloadRow( |
109 item->GetFullPath(), | 109 item->GetFullPath(), |
110 item->GetURL(), | 110 item->GetTargetFilePath(), |
| 111 item->GetUrlChain(), |
111 item->GetReferrerUrl(), | 112 item->GetReferrerUrl(), |
112 item->GetStartTime(), | 113 item->GetStartTime(), |
113 item->GetEndTime(), | 114 item->GetEndTime(), |
114 item->GetReceivedBytes(), | 115 item->GetReceivedBytes(), |
115 item->GetTotalBytes(), | 116 item->GetTotalBytes(), |
116 item->GetState(), | 117 item->GetState(), |
| 118 item->GetDangerType(), |
| 119 item->GetLastReason(), |
117 ((data != NULL) ? data->db_handle() | 120 ((data != NULL) ? data->db_handle() |
118 : history::DownloadDatabase::kUninitializedHandle), | 121 : history::DownloadDatabase::kUninitializedHandle), |
119 item->GetOpened()); | 122 item->GetOpened()); |
120 } | 123 } |
121 | 124 |
122 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 125 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
123 const history::DownloadRow& current) { | 126 const history::DownloadRow& current) { |
124 // Ignore url, referrer, start_time, db_handle, which don't change. | 127 // Ignore url, referrer, start_time, db_handle, which don't change. |
125 return ((previous == NULL) || | 128 return ((previous == NULL) || |
126 (previous->path != current.path) || | 129 (previous->current_path != current.current_path) || |
| 130 (previous->target_path != current.target_path) || |
127 (previous->end_time != current.end_time) || | 131 (previous->end_time != current.end_time) || |
128 (previous->received_bytes != current.received_bytes) || | 132 (previous->received_bytes != current.received_bytes) || |
129 (previous->total_bytes != current.total_bytes) || | 133 (previous->total_bytes != current.total_bytes) || |
130 (previous->state != current.state) || | 134 (previous->state != current.state) || |
| 135 (previous->danger_type != current.danger_type) || |
| 136 (previous->interrupt_reason != current.interrupt_reason) || |
131 (previous->opened != current.opened)); | 137 (previous->opened != current.opened)); |
132 } | 138 } |
133 | 139 |
134 typedef std::vector<history::DownloadRow> InfoVector; | 140 typedef std::vector<history::DownloadRow> InfoVector; |
135 | 141 |
136 } // anonymous namespace | 142 } // anonymous namespace |
137 | 143 |
138 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history) | 144 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history) |
139 : history_(history) { | 145 : history_(history) { |
140 } | 146 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if (!notifier_.GetManager()) | 217 if (!notifier_.GetManager()) |
212 return; | 218 return; |
213 for (InfoVector::const_iterator it = infos->begin(); | 219 for (InfoVector::const_iterator it = infos->begin(); |
214 it != infos->end(); ++it) { | 220 it != infos->end(); ++it) { |
215 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set | 221 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set |
216 // loading_db_handle_ to match up the created item with its db_handle. All | 222 // loading_db_handle_ to match up the created item with its db_handle. All |
217 // methods run on the UI thread and CreateDownloadItem() is synchronous. | 223 // methods run on the UI thread and CreateDownloadItem() is synchronous. |
218 loading_db_handle_ = it->db_handle; | 224 loading_db_handle_ = it->db_handle; |
219 content::DownloadItem* download_item = | 225 content::DownloadItem* download_item = |
220 notifier_.GetManager()->CreateDownloadItem( | 226 notifier_.GetManager()->CreateDownloadItem( |
221 it->path, | 227 it->current_path, |
222 it->url, | 228 it->target_path, |
| 229 it->url_chain, |
223 it->referrer_url, | 230 it->referrer_url, |
224 it->start_time, | 231 it->start_time, |
225 it->end_time, | 232 it->end_time, |
226 it->received_bytes, | 233 it->received_bytes, |
227 it->total_bytes, | 234 it->total_bytes, |
228 it->state, | 235 it->state, |
| 236 it->danger_type, |
| 237 it->interrupt_reason, |
229 it->opened); | 238 it->opened); |
230 DownloadHistoryData* data = DownloadHistoryData::Get(download_item); | 239 DownloadHistoryData* data = DownloadHistoryData::Get(download_item); |
231 | 240 |
232 // If this DCHECK fails, then you probably added an Observer that | 241 // If this DCHECK fails, then you probably added an Observer that |
233 // synchronously creates a DownloadItem in response to | 242 // synchronously creates a DownloadItem in response to |
234 // DownloadManager::OnDownloadCreated(), and your observer runs before | 243 // DownloadManager::OnDownloadCreated(), and your observer runs before |
235 // DownloadHistory, and DownloadManager creates items synchronously. Just | 244 // DownloadHistory, and DownloadManager creates items synchronously. Just |
236 // bounce your DownloadItem creation off the message loop to flush | 245 // bounce your DownloadItem creation off the message loop to flush |
237 // DownloadHistory::OnDownloadCreated. | 246 // DownloadHistory::OnDownloadCreated. |
238 DCHECK_EQ(it->db_handle, data->db_handle()); | 247 DCHECK_EQ(it->db_handle, data->db_handle()); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 423 |
415 void DownloadHistory::RemoveDownloadsBatch() { | 424 void DownloadHistory::RemoveDownloadsBatch() { |
416 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 425 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
417 HandleSet remove_handles; | 426 HandleSet remove_handles; |
418 IdSet remove_ids; | 427 IdSet remove_ids; |
419 removing_handles_.swap(remove_handles); | 428 removing_handles_.swap(remove_handles); |
420 removing_ids_.swap(remove_ids); | 429 removing_ids_.swap(remove_ids); |
421 history_->RemoveDownloads(remove_handles); | 430 history_->RemoveDownloads(remove_handles); |
422 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 431 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
423 } | 432 } |
OLD | NEW |