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 #include "chrome/browser/download/download_path_reservation_tracker.h" | 5 #include "chrome/browser/download/download_path_reservation_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 (create_directory || | 196 (create_directory || |
197 (!default_download_path.empty() && | 197 (!default_download_path.empty() && |
198 (default_download_path == target_dir)))) { | 198 (default_download_path == target_dir)))) { |
199 base::CreateDirectory(target_dir); | 199 base::CreateDirectory(target_dir); |
200 } | 200 } |
201 | 201 |
202 // Check writability of the suggested path. If we can't write to it, default | 202 // Check writability of the suggested path. If we can't write to it, default |
203 // to the user's "My Documents" directory. We'll prompt them in this case. | 203 // to the user's "My Documents" directory. We'll prompt them in this case. |
204 if (!base::PathIsWritable(target_dir)) { | 204 if (!base::PathIsWritable(target_dir)) { |
205 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; | 205 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; |
206 #if BUILDFLAG(ANDROID_JAVA_UI) | 206 #if defined(OS_ANDROID) |
207 // On Android, DIR_USER_DOCUMENTS is in reality a subdirectory | 207 // On Android, DIR_USER_DOCUMENTS is in reality a subdirectory |
208 // of DIR_ANDROID_APP_DATA which isn't accessible by other apps. | 208 // of DIR_ANDROID_APP_DATA which isn't accessible by other apps. |
209 reserved_path->clear(); | 209 reserved_path->clear(); |
210 (*g_reservation_map)[key] = *reserved_path; | 210 (*g_reservation_map)[key] = *reserved_path; |
211 return false; | 211 return false; |
212 #else | 212 #else |
213 is_path_writeable = false; | 213 is_path_writeable = false; |
214 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); | 214 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); |
215 target_path = target_dir.Append(filename); | 215 target_path = target_dir.Append(filename); |
216 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 216 #endif // defined(OS_ANDROID) |
217 } | 217 } |
218 | 218 |
219 if (is_path_writeable) { | 219 if (is_path_writeable) { |
220 // Check the limit of file name length if it could be obtained. When the | 220 // Check the limit of file name length if it could be obtained. When the |
221 // suggested name exceeds the limit, truncate or prompt the user. | 221 // suggested name exceeds the limit, truncate or prompt the user. |
222 int max_length = base::GetMaximumPathComponentLength(target_dir); | 222 int max_length = base::GetMaximumPathComponentLength(target_dir); |
223 if (max_length != -1) { | 223 if (max_length != -1) { |
224 int limit = max_length - kIntermediateNameSuffixLength; | 224 int limit = max_length - kIntermediateNameSuffixLength; |
225 if (limit <= 0 || !TruncateFileName(&target_path, limit)) | 225 if (limit <= 0 || !TruncateFileName(&target_path, limit)) |
226 name_too_long = true; | 226 name_too_long = true; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 base::Bind(&RunGetReservedPathCallback, | 398 base::Bind(&RunGetReservedPathCallback, |
399 callback, | 399 callback, |
400 base::Owned(reserved_path))); | 400 base::Owned(reserved_path))); |
401 } | 401 } |
402 | 402 |
403 // static | 403 // static |
404 bool DownloadPathReservationTracker::IsPathInUseForTesting( | 404 bool DownloadPathReservationTracker::IsPathInUseForTesting( |
405 const base::FilePath& path) { | 405 const base::FilePath& path) { |
406 return IsPathInUse(path); | 406 return IsPathInUse(path); |
407 } | 407 } |
OLD | NEW |