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 108aa7a61c8a92da13f4054169177ee2a817d6d8..6d41fe8ddc003f602d67c11e8a3d16bb60cedb80 100644 |
| --- a/chrome/browser/download/download_util.cc |
| +++ b/chrome/browser/download/download_util.cc |
| @@ -203,34 +203,34 @@ void GenerateFileNameInternal(const GURL& url, |
| // Download temporary file creation -------------------------------------------- |
| -class DefaultDownloadDirectory { |
| - public: |
| - const FilePath& path() const { return path_; } |
| - private: |
| - DefaultDownloadDirectory() { |
| - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { |
| - NOTREACHED(); |
|
Randy Smith (Not in Mondays)
2011/06/08 22:31:18
This may generate disagreement from you or Pawel,
Paweł Hajdan Jr.
2011/06/09 09:07:45
I'm fine with the NOTREACHED in that case.
haraken1
2011/06/09 10:16:56
Done. I left NOTREACHED() here and changed the sig
|
| - } |
| - if (DownloadPathIsDangerous(path_)) { |
| - if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { |
| - NOTREACHED(); |
| - } |
| - } |
| +FilePath DefaultDownloadDirectory::override_path_; |
| + |
| +bool DefaultDownloadDirectory::Get(FilePath* path) { |
| + if (!override_path_.empty()) { |
| + *path = override_path_; |
| + return true; |
| } |
| - friend struct base::DefaultLazyInstanceTraits<DefaultDownloadDirectory>; |
| - FilePath path_; |
| -}; |
| + bool result = PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, path); |
| + if (DownloadPathIsDangerous(*path)) { |
| + result = PathService::Get( |
| + chrome::DIR_DEFAULT_DOWNLOADS_SAFE, path); |
| + } |
| + return result; |
| +} |
| -static base::LazyInstance<DefaultDownloadDirectory> |
| - g_default_download_directory(base::LINKER_INITIALIZED); |
| +void DefaultDownloadDirectory::Override(const FilePath& override_path) { |
|
Paweł Hajdan Jr.
2011/06/08 09:50:23
Now the problem is that we have prefs::kDownloadDe
Randy Smith (Not in Mondays)
2011/06/08 22:31:18
I agree about not adding more logic to download_ut
Paweł Hajdan Jr.
2011/06/09 09:07:45
I added DownloadPrefs with that kind of code in mi
haraken1
2011/06/09 10:16:56
I am sorry but I am a bit confused. First of all,
Randy Smith (Not in Mondays)
2011/06/10 20:58:53
Ok, I'm willing to accept this. It's not ideal, b
haraken1
2011/06/14 11:10:05
I moved the functionality of DefaultDownloadDirect
|
| + override_path_ = override_path; |
| +} |
| -const FilePath& GetDefaultDownloadDirectory() { |
| - return g_default_download_directory.Get().path(); |
| +void DefaultDownloadDirectory::UnOverride() { |
| + override_path_.clear(); |
| } |
| bool CreateTemporaryFileForDownload(FilePath* temp_file) { |
| - if (file_util::CreateTemporaryFileInDir(GetDefaultDownloadDirectory(), |
| - temp_file)) |
| + FilePath path; |
| + if (!DefaultDownloadDirectory::Get(&path)) |
| + return false; |
| + if (file_util::CreateTemporaryFileInDir(path, temp_file)) |
| return true; |
| return file_util::CreateTemporaryFile(temp_file); |
| } |