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

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: rebase 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
« no previous file with comments | « chrome/browser/download/download_history.h ('k') | chrome/browser/download/download_history_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_history.cc
diff --git a/chrome/browser/download/download_history.cc b/chrome/browser/download/download_history.cc
index c472e7c112535870f0cacb482dce7ff11cae35af..d86d720eb736ad1cc6d372b288f8c26bc7bd2a2d 100644
--- a/chrome/browser/download/download_history.cc
+++ b/chrome/browser/download/download_history.cc
@@ -143,25 +143,45 @@ history::DownloadRow GetDownloadRow(
item->GetOpened(), by_ext_id, by_ext_name);
}
-bool ShouldUpdateHistory(const history::DownloadRow* previous,
- const history::DownloadRow& current) {
+enum class ShouldUpdateHistoryResult {
+ NO,
+ UPDATE,
+ UPDATE_IMMEDIATELY,
+};
+
+ShouldUpdateHistoryResult ShouldUpdateHistory(
+ const history::DownloadRow* previous,
+ const history::DownloadRow& current) {
+ // 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.
+ // TODO(qinmin): this doesn't solve all the issues. When download starts,
+ // Chrome will write the http response data to a temporary file, and later
+ // rename it. If Chrome is killed before committing the history here,
+ // that temporary file will still get permanently left.
+ // See http://crbug.com/664677.
+ if (previous == nullptr || previous->current_path != current.current_path)
+ return ShouldUpdateHistoryResult::UPDATE_IMMEDIATELY;
+
// Ignore url_chain, referrer, site_url, http_method, mime_type,
// original_mime_type, start_time, id, and guid. These fields don't change.
- return ((previous == NULL) ||
- (previous->current_path != current.current_path) ||
- (previous->target_path != current.target_path) ||
- (previous->end_time != current.end_time) ||
- (previous->received_bytes != current.received_bytes) ||
- (previous->total_bytes != current.total_bytes) ||
- (previous->etag != current.etag) ||
- (previous->last_modified != current.last_modified) ||
- (previous->state != current.state) ||
- (previous->danger_type != current.danger_type) ||
- (previous->interrupt_reason != current.interrupt_reason) ||
- (previous->hash != current.hash) ||
- (previous->opened != current.opened) ||
- (previous->by_ext_id != current.by_ext_id) ||
- (previous->by_ext_name != current.by_ext_name));
+ if ((previous->target_path != current.target_path) ||
+ (previous->end_time != current.end_time) ||
+ (previous->received_bytes != current.received_bytes) ||
+ (previous->total_bytes != current.total_bytes) ||
+ (previous->etag != current.etag) ||
+ (previous->last_modified != current.last_modified) ||
+ (previous->state != current.state) ||
+ (previous->danger_type != current.danger_type) ||
+ (previous->interrupt_reason != current.interrupt_reason) ||
+ (previous->hash != current.hash) ||
+ (previous->opened != current.opened) ||
+ (previous->by_ext_id != current.by_ext_id) ||
+ (previous->by_ext_name != current.by_ext_name)) {
+ return ShouldUpdateHistoryResult::UPDATE;
+ }
+
+ return ShouldUpdateHistoryResult::NO;
}
typedef std::vector<history::DownloadRow> InfoVector;
@@ -186,8 +206,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(
@@ -408,11 +428,15 @@ void DownloadHistory::OnDownloadUpdated(
}
history::DownloadRow current_info(GetDownloadRow(item));
- bool should_update = ShouldUpdateHistory(data->info(), current_info);
+ ShouldUpdateHistoryResult should_update_result =
+ ShouldUpdateHistory(data->info(), current_info);
+ bool should_update = (should_update_result != ShouldUpdateHistoryResult::NO);
UMA_HISTOGRAM_ENUMERATION("Download.HistoryPropagatedUpdate",
should_update, 2);
if (should_update) {
- history_->UpdateDownload(current_info);
+ history_->UpdateDownload(
+ current_info,
+ should_update_result == ShouldUpdateHistoryResult::UPDATE_IMMEDIATELY);
for (Observer& observer : observers_)
observer.OnDownloadStored(item, current_info);
}
« no previous file with comments | « chrome/browser/download/download_history.h ('k') | chrome/browser/download/download_history_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698