Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1236)

Unified Diff: chrome/browser/download/download_history.cc

Issue 2508503002: Fix an issue that temp files are left permanently on storage after chrome crash (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}

Powered by Google App Engine
This is Rietveld 408576698