Chromium Code Reviews| 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 utilities. | 5 // Download utilities. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| 8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 namespace gfx { | 45 namespace gfx { |
| 46 class Canvas; | 46 class Canvas; |
| 47 class Image; | 47 class Image; |
| 48 } | 48 } |
| 49 | 49 |
| 50 namespace download_util { | 50 namespace download_util { |
| 51 | 51 |
| 52 // Download temporary file creation -------------------------------------------- | 52 // Download temporary file creation -------------------------------------------- |
| 53 | 53 |
| 54 // Return the default download directory. | 54 // Overrides the path of the default download folder returned by |
| 55 const FilePath& GetDefaultDownloadDirectory(); | 55 // DefaultDownloadDirectory::Get(). |
| 56 // WARNING: We can generate an object of this class only on testing context | |
| 57 // (e.g. download tests) for temporarily switching the default download folder. | |
| 58 // WARNING: In order to override the default download folder, we must use | |
|
Paweł Hajdan Jr.
2011/06/09 19:10:38
nit: Please remove the part about PathService::Ove
haraken1
2011/06/14 11:10:05
Done.
| |
| 59 // this class instead of using PathService::Override(), | |
| 60 // since PathService::Override() can cause many problems: | |
| 61 // http://codereview.chromium.org/2805100 | |
| 62 class ScopedDefaultDownloadDirectory { | |
|
Paweł Hajdan Jr.
2011/06/09 19:10:38
Could you move this class to a special file only f
haraken1
2011/06/14 11:10:05
I moved it to download_test_util.h, download_test_
| |
| 63 public: | |
| 64 ScopedDefaultDownloadDirectory(); | |
| 65 | |
| 66 // If the path is overridden, invalidates the overriding. | |
| 67 ~ScopedDefaultDownloadDirectory(); | |
| 68 | |
| 69 // Overrides the path. | |
| 70 void Override(const FilePath& override_path); | |
|
Paweł Hajdan Jr.
2011/06/09 19:10:38
I think the ctor should take the FilePath paramete
haraken1
2011/06/14 11:10:05
Done. Now, ScopedDefaultDownloadDirectory has only
| |
| 71 | |
| 72 // Invalidates the overriding. | |
| 73 void UnOverride(); | |
|
Randy Smith (Not in Mondays)
2011/06/10 20:58:53
I'd get rid of Override and UnOverride and just ha
haraken1
2011/06/14 11:10:05
Done.
| |
| 74 }; | |
|
Paweł Hajdan Jr.
2011/06/09 19:10:38
And DISALLOW_COPY_AND_ASSIGN please.
haraken1
2011/06/14 11:10:05
Done.
| |
| 75 | |
| 76 class DefaultDownloadDirectory { | |
|
Randy Smith (Not in Mondays)
2011/06/10 20:58:53
This can be used from multiple threads *unless* Sc
haraken1
2011/06/14 11:10:05
- I wrote "DCHECK(BrowserThread::CurrentlyOn(Brows
| |
| 77 public: | |
| 78 // Returns the path of the default download folder. | |
| 79 // If the path is being overridden, returns the overridden path. | |
| 80 static const FilePath Get(); | |
| 81 | |
| 82 private: | |
| 83 friend class ScopedDefaultDownloadDirectory; | |
| 84 static FilePath override_path_; | |
| 85 }; | |
| 86 | |
| 87 // Chooses a writable directory from |website_save_dir|, |download_save_dir| | |
| 88 // and |default_downloads_dir| in this order of priority. | |
| 89 // If none of them is writable, creates |download_save_dir| and | |
| 90 // chooses |download_save_dir|. The choosed directory is stored to |save_dir|. | |
| 91 // Returns true if neither |website_save_dir| nor |download_save_dir| | |
| 92 // is writable, which indicates the select file dialog should be displayed. | |
| 93 bool ChooseSavableDirectory(const FilePath& website_save_dir, | |
| 94 const FilePath& download_save_dir, | |
| 95 const FilePath& default_downloads_dir, | |
| 96 FilePath* save_dir); | |
|
Randy Smith (Not in Mondays)
2011/06/10 20:58:53
I'm not sure I see a reason for this to be in down
haraken1
2011/06/14 11:10:05
Done. I made it a static method of DownloadManager
| |
| 56 | 97 |
| 57 // Create a temporary file for a download in the user's default download | 98 // Create a temporary file for a download in the user's default download |
| 58 // directory and return true if was successful in creating the file. | 99 // directory and return true if was successful in creating the file. |
| 59 bool CreateTemporaryFileForDownload(FilePath* path); | 100 bool CreateTemporaryFileForDownload(FilePath* path); |
| 60 | 101 |
| 61 // Return true if the |download_path| is dangerous path. | 102 // Return true if the |download_path| is dangerous path. |
| 62 bool DownloadPathIsDangerous(const FilePath& download_path); | 103 bool DownloadPathIsDangerous(const FilePath& download_path); |
| 63 | 104 |
| 64 // Create an extension based on the file name and mime type. | 105 // Create an extension based on the file name and mime type. |
| 65 void GenerateExtension(const FilePath& file_name, | 106 void GenerateExtension(const FilePath& file_name, |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 // Erases all downloaded files with the specified path and name prefix. | 330 // Erases all downloaded files with the specified path and name prefix. |
| 290 // Used by download UI tests to clean up the download directory. | 331 // Used by download UI tests to clean up the download directory. |
| 291 void EraseUniqueDownloadFiles(const FilePath& path_prefix); | 332 void EraseUniqueDownloadFiles(const FilePath& path_prefix); |
| 292 | 333 |
| 293 // Returns a .crdownload intermediate path for the |suggested_path|. | 334 // Returns a .crdownload intermediate path for the |suggested_path|. |
| 294 FilePath GetCrDownloadPath(const FilePath& suggested_path); | 335 FilePath GetCrDownloadPath(const FilePath& suggested_path); |
| 295 | 336 |
| 296 } // namespace download_util | 337 } // namespace download_util |
| 297 | 338 |
| 298 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 339 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
| OLD | NEW |