Chromium Code Reviews| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 (previous->last_modified != current.last_modified) || | 156 (previous->last_modified != current.last_modified) || |
| 157 (previous->state != current.state) || | 157 (previous->state != current.state) || |
| 158 (previous->danger_type != current.danger_type) || | 158 (previous->danger_type != current.danger_type) || |
| 159 (previous->interrupt_reason != current.interrupt_reason) || | 159 (previous->interrupt_reason != current.interrupt_reason) || |
| 160 (previous->hash != current.hash) || | 160 (previous->hash != current.hash) || |
| 161 (previous->opened != current.opened) || | 161 (previous->opened != current.opened) || |
| 162 (previous->by_ext_id != current.by_ext_id) || | 162 (previous->by_ext_id != current.by_ext_id) || |
| 163 (previous->by_ext_name != current.by_ext_name)); | 163 (previous->by_ext_name != current.by_ext_name)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool ShouldCommitHistoryImmediately(const history::DownloadRow* previous, | |
| 167 const history::DownloadRow& current) { | |
|
asanka
2016/11/16 23:15:57
Minor nit: You could fold this into ShouldUpdateHi
qinmin
2016/11/17 00:46:30
Done.
| |
| 168 #if defined(OS_ANDROID) | |
|
asanka
2016/11/16 23:15:57
Let's make this work on all platforms.
qinmin
2016/11/17 00:46:30
Done.
| |
| 169 // When download path is determined, Chrome should commit the history | |
| 170 // immediately. Otherwise the file will be left permanently on the external | |
| 171 // storage if Chrome crashes right away. | |
| 172 return (previous != nullptr) && | |
| 173 (previous->current_path.empty() && !current.current_path.empty()); | |
| 174 #endif | |
| 175 return false; | |
| 176 } | |
| 177 | |
| 166 typedef std::vector<history::DownloadRow> InfoVector; | 178 typedef std::vector<history::DownloadRow> InfoVector; |
| 167 | 179 |
| 168 } // anonymous namespace | 180 } // anonymous namespace |
| 169 | 181 |
| 170 DownloadHistory::HistoryAdapter::HistoryAdapter( | 182 DownloadHistory::HistoryAdapter::HistoryAdapter( |
| 171 history::HistoryService* history) | 183 history::HistoryService* history) |
| 172 : history_(history) { | 184 : history_(history) { |
| 173 } | 185 } |
| 174 DownloadHistory::HistoryAdapter::~HistoryAdapter() {} | 186 DownloadHistory::HistoryAdapter::~HistoryAdapter() {} |
| 175 | 187 |
| 176 void DownloadHistory::HistoryAdapter::QueryDownloads( | 188 void DownloadHistory::HistoryAdapter::QueryDownloads( |
| 177 const history::HistoryService::DownloadQueryCallback& callback) { | 189 const history::HistoryService::DownloadQueryCallback& callback) { |
| 178 history_->QueryDownloads(callback); | 190 history_->QueryDownloads(callback); |
| 179 } | 191 } |
| 180 | 192 |
| 181 void DownloadHistory::HistoryAdapter::CreateDownload( | 193 void DownloadHistory::HistoryAdapter::CreateDownload( |
| 182 const history::DownloadRow& info, | 194 const history::DownloadRow& info, |
| 183 const history::HistoryService::DownloadCreateCallback& callback) { | 195 const history::HistoryService::DownloadCreateCallback& callback) { |
| 184 history_->CreateDownload(info, callback); | 196 history_->CreateDownload(info, callback); |
| 185 } | 197 } |
| 186 | 198 |
| 187 void DownloadHistory::HistoryAdapter::UpdateDownload( | 199 void DownloadHistory::HistoryAdapter::UpdateDownload( |
| 188 const history::DownloadRow& data) { | 200 const history::DownloadRow& data, bool should_commit_immediately) { |
| 189 history_->UpdateDownload(data); | 201 history_->UpdateDownload(data, should_commit_immediately); |
| 190 } | 202 } |
| 191 | 203 |
| 192 void DownloadHistory::HistoryAdapter::RemoveDownloads( | 204 void DownloadHistory::HistoryAdapter::RemoveDownloads( |
| 193 const std::set<uint32_t>& ids) { | 205 const std::set<uint32_t>& ids) { |
| 194 history_->RemoveDownloads(ids); | 206 history_->RemoveDownloads(ids); |
| 195 } | 207 } |
| 196 | 208 |
| 197 DownloadHistory::Observer::Observer() {} | 209 DownloadHistory::Observer::Observer() {} |
| 198 DownloadHistory::Observer::~Observer() {} | 210 DownloadHistory::Observer::~Observer() {} |
| 199 | 211 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 if (item->IsTemporary()) { | 416 if (item->IsTemporary()) { |
| 405 OnDownloadRemoved(notifier_.GetManager(), item); | 417 OnDownloadRemoved(notifier_.GetManager(), item); |
| 406 return; | 418 return; |
| 407 } | 419 } |
| 408 | 420 |
| 409 history::DownloadRow current_info(GetDownloadRow(item)); | 421 history::DownloadRow current_info(GetDownloadRow(item)); |
| 410 bool should_update = ShouldUpdateHistory(data->info(), current_info); | 422 bool should_update = ShouldUpdateHistory(data->info(), current_info); |
| 411 UMA_HISTOGRAM_ENUMERATION("Download.HistoryPropagatedUpdate", | 423 UMA_HISTOGRAM_ENUMERATION("Download.HistoryPropagatedUpdate", |
| 412 should_update, 2); | 424 should_update, 2); |
| 413 if (should_update) { | 425 if (should_update) { |
| 414 history_->UpdateDownload(current_info); | 426 history_->UpdateDownload( |
| 427 current_info, | |
| 428 ShouldCommitHistoryImmediately(data->info(), current_info)); | |
| 415 for (Observer& observer : observers_) | 429 for (Observer& observer : observers_) |
| 416 observer.OnDownloadStored(item, current_info); | 430 observer.OnDownloadStored(item, current_info); |
| 417 } | 431 } |
| 418 if (item->GetState() == content::DownloadItem::IN_PROGRESS) { | 432 if (item->GetState() == content::DownloadItem::IN_PROGRESS) { |
| 419 data->set_info(current_info); | 433 data->set_info(current_info); |
| 420 } else { | 434 } else { |
| 421 data->clear_info(); | 435 data->clear_info(); |
| 422 } | 436 } |
| 423 } | 437 } |
| 424 | 438 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 } | 477 } |
| 464 | 478 |
| 465 void DownloadHistory::RemoveDownloadsBatch() { | 479 void DownloadHistory::RemoveDownloadsBatch() { |
| 466 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 480 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 467 IdSet remove_ids; | 481 IdSet remove_ids; |
| 468 removing_ids_.swap(remove_ids); | 482 removing_ids_.swap(remove_ids); |
| 469 history_->RemoveDownloads(remove_ids); | 483 history_->RemoveDownloads(remove_ids); |
| 470 for (Observer& observer : observers_) | 484 for (Observer& observer : observers_) |
| 471 observer.OnDownloadsRemoved(remove_ids); | 485 observer.OnDownloadsRemoved(remove_ids); |
| 472 } | 486 } |
| OLD | NEW |