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

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

Issue 2877008: Rename the download to its final name only after the download is finished (Closed)
Patch Set: rebase Created 10 years, 5 months 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_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_util.cc
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index a5323272b92501aa1ae0bdb8a26ca2b8ee69472f..3f97452e7b22bdca298d8b725155e867404199fe 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -548,4 +548,31 @@ void CancelDownloadRequest(ResourceDispatcherHost* rdh,
rdh->CancelRequest(render_process_id, request_id, false);
}
+int GetUniquePathNumberWithCrDownload(const FilePath& path) {
+ const int kMaxAttempts = 100;
+
+ if (!file_util::PathExists(path) &&
+ !file_util::PathExists(GetCrDownloadPath(path)))
+ return 0;
+
+ FilePath new_path;
+ for (int count = 1; count <= kMaxAttempts; ++count) {
+ new_path = FilePath(path);
+ AppendNumberToPath(&new_path, count);
+
+ if (!file_util::PathExists(new_path) &&
+ !file_util::PathExists(GetCrDownloadPath(new_path)))
+ return count;
+ }
+
+ return -1;
+}
+
+FilePath GetCrDownloadPath(const FilePath& suggested_path) {
+ FilePath::StringType file_name;
+ SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"),
+ suggested_path.value().c_str());
+ return FilePath(file_name);
+}
+
} // namespace download_util
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698