OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 196 |
197 DCHECK(!generated_name->empty()); | 197 DCHECK(!generated_name->empty()); |
198 | 198 |
199 GenerateSafeFileName(mime_type, generated_name); | 199 GenerateSafeFileName(mime_type, generated_name); |
200 } | 200 } |
201 | 201 |
202 } // namespace | 202 } // namespace |
203 | 203 |
204 // Download temporary file creation -------------------------------------------- | 204 // Download temporary file creation -------------------------------------------- |
205 | 205 |
206 class DefaultDownloadDirectory { | 206 FilePath DefaultDownloadDirectory::override_path_; |
207 public: | 207 |
208 const FilePath& path() const { return path_; } | 208 bool DefaultDownloadDirectory::Get(FilePath* path) { |
209 private: | 209 if (!override_path_.empty()) { |
210 DefaultDownloadDirectory() { | 210 *path = override_path_; |
211 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &path_)) { | 211 return true; |
212 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
| |
213 } | |
214 if (DownloadPathIsDangerous(path_)) { | |
215 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) { | |
216 NOTREACHED(); | |
217 } | |
218 } | |
219 } | 212 } |
220 friend struct base::DefaultLazyInstanceTraits<DefaultDownloadDirectory>; | 213 bool result = PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, path); |
221 FilePath path_; | 214 if (DownloadPathIsDangerous(*path)) { |
222 }; | 215 result = PathService::Get( |
216 chrome::DIR_DEFAULT_DOWNLOADS_SAFE, path); | |
217 } | |
218 return result; | |
219 } | |
223 | 220 |
224 static base::LazyInstance<DefaultDownloadDirectory> | 221 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
| |
225 g_default_download_directory(base::LINKER_INITIALIZED); | 222 override_path_ = override_path; |
223 } | |
226 | 224 |
227 const FilePath& GetDefaultDownloadDirectory() { | 225 void DefaultDownloadDirectory::UnOverride() { |
228 return g_default_download_directory.Get().path(); | 226 override_path_.clear(); |
229 } | 227 } |
230 | 228 |
231 bool CreateTemporaryFileForDownload(FilePath* temp_file) { | 229 bool CreateTemporaryFileForDownload(FilePath* temp_file) { |
232 if (file_util::CreateTemporaryFileInDir(GetDefaultDownloadDirectory(), | 230 FilePath path; |
233 temp_file)) | 231 if (!DefaultDownloadDirectory::Get(&path)) |
232 return false; | |
233 if (file_util::CreateTemporaryFileInDir(path, temp_file)) | |
234 return true; | 234 return true; |
235 return file_util::CreateTemporaryFile(temp_file); | 235 return file_util::CreateTemporaryFile(temp_file); |
236 } | 236 } |
237 | 237 |
238 bool DownloadPathIsDangerous(const FilePath& download_path) { | 238 bool DownloadPathIsDangerous(const FilePath& download_path) { |
239 FilePath desktop_dir; | 239 FilePath desktop_dir; |
240 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { | 240 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) { |
241 NOTREACHED(); | 241 NOTREACHED(); |
242 return false; | 242 return false; |
243 } | 243 } |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 923 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
924 FilePath::StringType file_name; | 924 FilePath::StringType file_name; |
925 base::SStringPrintf( | 925 base::SStringPrintf( |
926 &file_name, | 926 &file_name, |
927 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), | 927 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), |
928 suggested_path.value().c_str()); | 928 suggested_path.value().c_str()); |
929 return FilePath(file_name); | 929 return FilePath(file_name); |
930 } | 930 } |
931 | 931 |
932 } // namespace download_util | 932 } // namespace download_util |
OLD | NEW |