Chromium Code Reviews| Index: chrome/browser/download/download_history.cc |
| diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc |
| index 49262d0d42d9fca3591ac486b2b6a0d48e259efc..5e2e7e38b069bd5b4cc22bd934db236c82d77448 100644 |
| --- a/chrome/browser/download/download_history.cc |
| +++ b/chrome/browser/download/download_history.cc |
| @@ -163,6 +163,18 @@ bool ShouldUpdateHistory(const history::DownloadRow* previous, |
| (previous->by_ext_name != current.by_ext_name)); |
| } |
| +bool ShouldCommitHistoryImmediately(const history::DownloadRow* previous, |
| + 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.
|
| +#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.
|
| + // When download path is determined, Chrome should commit the history |
| + // immediately. Otherwise the file will be left permanently on the external |
| + // storage if Chrome crashes right away. |
| + return (previous != nullptr) && |
| + (previous->current_path.empty() && !current.current_path.empty()); |
| +#endif |
| + return false; |
| +} |
| + |
| typedef std::vector<history::DownloadRow> InfoVector; |
| } // anonymous namespace |
| @@ -185,8 +197,8 @@ void DownloadHistory::HistoryAdapter::CreateDownload( |
| } |
| void DownloadHistory::HistoryAdapter::UpdateDownload( |
| - const history::DownloadRow& data) { |
| - history_->UpdateDownload(data); |
| + const history::DownloadRow& data, bool should_commit_immediately) { |
| + history_->UpdateDownload(data, should_commit_immediately); |
| } |
| void DownloadHistory::HistoryAdapter::RemoveDownloads( |
| @@ -411,7 +423,9 @@ void DownloadHistory::OnDownloadUpdated( |
| UMA_HISTOGRAM_ENUMERATION("Download.HistoryPropagatedUpdate", |
| should_update, 2); |
| if (should_update) { |
| - history_->UpdateDownload(current_info); |
| + history_->UpdateDownload( |
| + current_info, |
| + ShouldCommitHistoryImmediately(data->info(), current_info)); |
| for (Observer& observer : observers_) |
| observer.OnDownloadStored(item, current_info); |
| } |