Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "chrome/browser/download/download_target_result.h" | |
| 9 | 10 |
| 10 namespace base { | 11 namespace base { |
| 11 class FilePath; | 12 class FilePath; |
| 12 } | 13 } |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 class DownloadItem; | 16 class DownloadItem; |
| 16 } | 17 } |
| 17 | 18 |
| 18 // Chrome attempts to uniquify filenames that are assigned to downloads in order | 19 // Chrome attempts to uniquify filenames that are assigned to downloads in order |
| 19 // to avoid overwriting files that already exist on the file system. Downloads | 20 // to avoid overwriting files that already exist on the file system. Downloads |
| 20 // that are considered potentially dangerous use random intermediate filenames. | 21 // that are considered potentially dangerous use random intermediate filenames. |
| 21 // Therefore only considering files that exist on the filesystem is | 22 // Therefore only considering files that exist on the filesystem is |
| 22 // insufficient. This class tracks files that are assigned to active downloads | 23 // insufficient. This class tracks files that are assigned to active downloads |
| 23 // so that uniquification can take those into account as well. | 24 // so that uniquification can take those into account as well. |
| 24 class DownloadPathReservationTracker { | 25 class DownloadPathReservationTracker { |
| 25 public: | 26 public: |
| 26 // Callback used with |GetReservedPath|. |target_path| specifies the target | 27 // Callback used with |GetReservedPath|. |target_path| specifies the target |
| 27 // path for the download. |target_path_verified| is true if all of the | 28 // path for the download. |target_path_verified| is true if all of the |
| 28 // following is true: | 29 // following is true: |
| 29 // - |requested_target_path| (passed into GetReservedPath()) was writeable. | 30 // - |requested_target_path| (passed into GetReservedPath()) was writeable. |
| 30 // - |target_path| was verified as being unique if uniqueness was | 31 // - |target_path| was verified as being unique if uniqueness was |
| 31 // required. | 32 // required. |
| 32 // | 33 // |
| 33 // If |requested_target_path| was not writeable, then the parent directory of | 34 // If |requested_target_path| was not writeable, then the parent directory of |
| 34 // |target_path| may be different from that of |requested_target_path|. | 35 // |target_path| may be different from that of |requested_target_path|. |
| 35 typedef base::Callback<void(const base::FilePath& target_path, | 36 typedef base::Callback<void(const base::FilePath& target_path, |
|
svaldez
2016/10/28 17:29:35
Might want to be consistent about whether the "Dow
asanka
2016/11/07 19:50:15
Yeah. I made the result be the first argument sinc
| |
| 36 bool target_path_verified)> ReservedPathCallback; | 37 DownloadTargetResult result)> |
| 38 ReservedPathCallback; | |
| 37 | 39 |
| 38 // The largest index for the uniquification suffix that we will try while | 40 // The largest index for the uniquification suffix that we will try while |
| 39 // attempting to come up with a unique path. | 41 // attempting to come up with a unique path. |
| 40 static const int kMaxUniqueFiles = 100; | 42 static const int kMaxUniqueFiles = 100; |
| 41 | 43 |
| 42 enum FilenameConflictAction { | 44 enum FilenameConflictAction { |
| 43 UNIQUIFY, | 45 UNIQUIFY, |
| 44 OVERWRITE, | 46 OVERWRITE, |
| 45 PROMPT, | 47 PROMPT, |
| 46 }; | 48 }; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 bool create_directory, | 93 bool create_directory, |
| 92 FilenameConflictAction conflict_action, | 94 FilenameConflictAction conflict_action, |
| 93 const ReservedPathCallback& callback); | 95 const ReservedPathCallback& callback); |
| 94 | 96 |
| 95 // Returns true if |path| is in use by an existing path reservation. Should | 97 // Returns true if |path| is in use by an existing path reservation. Should |
| 96 // only be called on the FILE thread. Currently only used by tests. | 98 // only be called on the FILE thread. Currently only used by tests. |
| 97 static bool IsPathInUseForTesting(const base::FilePath& path); | 99 static bool IsPathInUseForTesting(const base::FilePath& path); |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ | 102 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PATH_RESERVATION_TRACKER_H_ |
| OLD | NEW |