Chromium Code Reviews| Index: chrome/browser/download/download_util.cc |
| diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc |
| index cd69cc342cae0cc0bddad1a522af392313f6e436..b1896fe78e8168c0ec0d783c2d68fbfcb4267f46 100644 |
| --- a/chrome/browser/download/download_util.cc |
| +++ b/chrome/browser/download/download_util.cc |
| @@ -125,36 +125,49 @@ const int kAllNetErrorCodes[] = { |
| // Download temporary file creation -------------------------------------------- |
| -class DefaultDownloadDirectory { |
| - public: |
| - const FilePath& path() const { return path_; } |
| - private: |
| - DefaultDownloadDirectory() { |
| - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { |
| - NOTREACHED(); |
| - } |
| - if (DownloadPathIsDangerous(path_)) { |
| - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { |
| - NOTREACHED(); |
| - } |
| +bool ChooseSavableDirectory( |
| + const FilePath& website_save_dir, |
| + const FilePath& download_save_dir, |
| + const FilePath& default_download_dir, |
| + FilePath* save_dir) { |
| + bool prompt_dialog = false; |
| + if (file_util::PathIsWritable(website_save_dir)) { |
| + // If the default html/websites save folder exists, |
| + // then use the default html/websites save folder. |
| + *save_dir = website_save_dir; |
| + } else if (file_util::PathIsWritable(download_save_dir)) { |
| + // If the default html/websites save folder does not exist |
| + // but the default download folder exists, |
| + // then use the default download folder. |
| + *save_dir = download_save_dir; |
| + } else { |
| + // If both the above folders do not exist, |
| + // use the user's "Downloads" folder. |
| + *save_dir = default_download_dir; |
| + prompt_dialog = true; |
| + if (!file_util::PathIsWritable(*save_dir)) { |
| + VLOG(1) << "Cannot find the user's writable \"Downloads\" folder."; |
| + // Create the |download_save_dir| folder if we cannot get |
| + // the user's writable "Downloads" folder (This will be a rare case). |
| + *save_dir = download_save_dir; |
| } |
| + // Make sure that the folder does exist. |
| + if (!file_util::CreateDirectory(*save_dir)) |
| + LOG(ERROR) << "Failed to create " << (*save_dir).value(); |
| } |
| - friend struct base::DefaultLazyInstanceTraits<DefaultDownloadDirectory>; |
| - FilePath path_; |
| -}; |
| - |
| -static base::LazyInstance<DefaultDownloadDirectory> |
| - g_default_download_directory(base::LINKER_INITIALIZED); |
| - |
| -const FilePath& GetDefaultDownloadDirectory() { |
| - return g_default_download_directory.Get().path(); |
| + return prompt_dialog; |
| } |
| -bool CreateTemporaryFileForDownload(FilePath* temp_file) { |
| - if (file_util::CreateTemporaryFileInDir(GetDefaultDownloadDirectory(), |
| - temp_file)) |
| - return true; |
| - return file_util::CreateTemporaryFile(temp_file); |
| +FilePath GetDefaultDownloadDirectoryFromPathService() { |
| + FilePath default_download_dir; |
| + if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &default_download_dir)) |
| + NOTREACHED(); |
| + if (DownloadPathIsDangerous(default_download_dir)) { |
| + if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, |
| + &default_download_dir)) |
|
Paweł Hajdan Jr.
2011/08/12 17:00:59
nit: Braces {} here.
haraken1
2011/08/15 00:44:15
Done.
|
| + NOTREACHED(); |
| + } |
| + return default_download_dir; |
| } |
| bool DownloadPathIsDangerous(const FilePath& download_path) { |