summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 16:13:39 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-26 16:13:39 +0000
commit5a2388a2c13aa47b42357f16e336fbe7fcb3f407 (patch)
tree7d5b4caaec28b7c0e5f7ad41f9051c1b07bac92d /chrome/browser/download
parentea05398d96221f8cc20939bad5fe52d4b11d3bd4 (diff)
downloadchromium_src-5a2388a2c13aa47b42357f16e336fbe7fcb3f407.zip
chromium_src-5a2388a2c13aa47b42357f16e336fbe7fcb3f407.tar.gz
chromium_src-5a2388a2c13aa47b42357f16e336fbe7fcb3f407.tar.bz2
Append a number to make app shortcut name unique.
- Move DownloadManager's unique path helpers into download utils; - Use those functions to make shortcut file name unqiue. BUG=642 TEST=Verify fixes for issue 642. Review URL: http://codereview.chromium.org/1276003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42769 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_manager.cc43
-rw-r--r--chrome/browser/download/download_util.cc28
-rw-r--r--chrome/browser/download/download_util.h9
3 files changed, 46 insertions, 34 deletions
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 0075352..7e4740e 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -79,34 +79,6 @@ const int kUpdateTimeMs = 1000;
// more negative.
const int kUninitializedHandle = 0;
-// Appends the passed the number between parenthesis the path before the
-// extension.
-void AppendNumberToPath(FilePath* path, int number) {
- file_util::InsertBeforeExtension(path,
- StringPrintf(FILE_PATH_LITERAL(" (%d)"), number));
-}
-
-// Attempts to find a number that can be appended to that path to make it
-// unique. If |path| does not exist, 0 is returned. If it fails to find such
-// a number, -1 is returned.
-int GetUniquePathNumber(const FilePath& path) {
- const int kMaxAttempts = 100;
-
- if (!file_util::PathExists(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))
- return count;
- }
-
- return -1;
-}
-
// Used to sort download items based on descending start time.
bool CompareStartTime(DownloadItem* first, DownloadItem* second) {
return first->start_time() > second->start_time();
@@ -324,7 +296,7 @@ FilePath DownloadItem::GetFileName() const {
return file_name_;
if (path_uniquifier_ > 0) {
FilePath name(original_name_);
- AppendNumberToPath(&name, path_uniquifier_);
+ download_util::AppendNumberToPath(&name, path_uniquifier_);
return name;
}
return original_name_;
@@ -699,8 +671,10 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) {
// Do not add the path uniquifier if we are saving to a specific path as in
// the drag-out case.
- if (info->save_info.file_path.empty())
- info->path_uniquifier = GetUniquePathNumber(info->suggested_path);
+ if (info->save_info.file_path.empty()) {
+ info->path_uniquifier = download_util::GetUniquePathNumber(
+ info->suggested_path);
+ }
// If the download is deemed dangerous, we'll use a temporary name for it.
if (info->is_dangerous) {
@@ -720,7 +694,8 @@ void DownloadManager::CheckIfSuggestedPathExists(DownloadCreateInfo* info) {
} else {
// We know the final path, build it if necessary.
if (info->path_uniquifier > 0) {
- AppendNumberToPath(&(info->suggested_path), info->path_uniquifier);
+ download_util::AppendNumberToPath(&(info->suggested_path),
+ info->path_uniquifier);
// Setting path_uniquifier to 0 to make sure we don't try to unique it
// later on.
info->path_uniquifier = 0;
@@ -1016,9 +991,9 @@ void DownloadManager::ProceedWithFinishedDangerousDownload(
// have the same path. This is because we uniquify the name on download
// start, and at that time the first file does not exists yet, so the second
// file gets the same name.
- uniquifier = GetUniquePathNumber(new_path);
+ uniquifier = download_util::GetUniquePathNumber(new_path);
if (uniquifier > 0)
- AppendNumberToPath(&new_path, uniquifier);
+ download_util::AppendNumberToPath(&new_path, uniquifier);
success = file_util::Move(path, new_path);
} else {
NOTREACHED();
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 5d0c49c..720d203 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -495,4 +495,32 @@ void UpdateAppIconDownloadProgress(int download_count,
}
#endif
+// Appends the passed the number between parenthesis the path before the
+// extension.
+void AppendNumberToPath(FilePath* path, int number) {
+ file_util::InsertBeforeExtension(path,
+ StringPrintf(FILE_PATH_LITERAL(" (%d)"), number));
+}
+
+// Attempts to find a number that can be appended to that path to make it
+// unique. If |path| does not exist, 0 is returned. If it fails to find such
+// a number, -1 is returned.
+int GetUniquePathNumber(const FilePath& path) {
+ const int kMaxAttempts = 100;
+
+ if (!file_util::PathExists(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))
+ return count;
+ }
+
+ return -1;
+}
+
} // namespace download_util
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index d692a46..dee3600 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -166,6 +166,15 @@ void UpdateAppIconDownloadProgress(int download_count,
bool progress_known,
float progress);
+// Appends the passed the number between parenthesis the path before the
+// extension.
+void AppendNumberToPath(FilePath* path, int number);
+
+// Attempts to find a number that can be appended to that path to make it
+// unique. If |path| does not exist, 0 is returned. If it fails to find such
+// a number, -1 is returned.
+int GetUniquePathNumber(const FilePath& path);
+
} // namespace download_util
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_