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 #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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // - Returns true if |reserved_path| has been successfully verified. | 157 // - Returns true if |reserved_path| has been successfully verified. |
| 158 bool CreateReservation( | 158 bool CreateReservation( |
| 159 ReservationKey key, | 159 ReservationKey key, |
| 160 const base::FilePath& suggested_path, | 160 const base::FilePath& suggested_path, |
| 161 const base::FilePath& default_download_path, | 161 const base::FilePath& default_download_path, |
| 162 bool create_directory, | 162 bool create_directory, |
| 163 DownloadPathReservationTracker::FilenameConflictAction conflict_action, | 163 DownloadPathReservationTracker::FilenameConflictAction conflict_action, |
| 164 base::FilePath* reserved_path) { | 164 base::FilePath* reserved_path) { |
| 165 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 165 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 166 DCHECK(suggested_path.IsAbsolute()); | 166 DCHECK(suggested_path.IsAbsolute()); |
| 167 | |
| 168 // Create a reservation map if one doesn't exist. It will be automatically | 167 // Create a reservation map if one doesn't exist. It will be automatically |
| 169 // deleted when all the reservations are revoked. | 168 // deleted when all the reservations are revoked. |
| 170 if (g_reservation_map == NULL) | 169 if (g_reservation_map == NULL) |
| 171 g_reservation_map = new ReservationMap; | 170 g_reservation_map = new ReservationMap; |
| 172 ReservationMap& reservations = *g_reservation_map; | 171 ReservationMap& reservations = *g_reservation_map; |
| 173 | 172 |
| 174 // Erase the reservation if it already exists. This can happen during | 173 // Erase the reservation if it already exists. This can happen during |
| 175 // automatic resumption where a new target determination request may be issued | 174 // automatic resumption where a new target determination request may be issued |
| 176 // for a DownloadItem without an intervening transition to INTERRUPTED. | 175 // for a DownloadItem without an intervening transition to INTERRUPTED. |
| 177 // | 176 // |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 195 (create_directory || | 194 (create_directory || |
| 196 (!default_download_path.empty() && | 195 (!default_download_path.empty() && |
| 197 (default_download_path == target_dir)))) { | 196 (default_download_path == target_dir)))) { |
| 198 base::CreateDirectory(target_dir); | 197 base::CreateDirectory(target_dir); |
| 199 } | 198 } |
| 200 | 199 |
| 201 // Check writability of the suggested path. If we can't write to it, default | 200 // Check writability of the suggested path. If we can't write to it, default |
| 202 // to the user's "My Documents" directory. We'll prompt them in this case. | 201 // to the user's "My Documents" directory. We'll prompt them in this case. |
| 203 if (!base::PathIsWritable(target_dir)) { | 202 if (!base::PathIsWritable(target_dir)) { |
| 204 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; | 203 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; |
| 204 #if defined(OS_ANDROID) | |
|
asanka
2016/07/07 21:12:48
This code is conditioned on OS_ANDROID while the o
qinmin
2016/07/07 22:49:37
Done.
| |
| 205 // On Android, file will not be by other apps if it is downloaded to | |
| 206 // Chrome's own directory. | |
|
asanka
2016/07/07 21:12:48
The comment should mention that DIR_USER_DOCUMENTS
qinmin
2016/07/07 22:49:37
Done.
| |
| 207 return false; | |
| 208 #else | |
| 205 is_path_writeable = false; | 209 is_path_writeable = false; |
| 206 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); | 210 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); |
| 207 target_path = target_dir.Append(filename); | 211 target_path = target_dir.Append(filename); |
| 212 #endif | |
| 208 } | 213 } |
| 209 | 214 |
| 210 if (is_path_writeable) { | 215 if (is_path_writeable) { |
| 211 // Check the limit of file name length if it could be obtained. When the | 216 // Check the limit of file name length if it could be obtained. When the |
| 212 // suggested name exceeds the limit, truncate or prompt the user. | 217 // suggested name exceeds the limit, truncate or prompt the user. |
| 213 int max_length = base::GetMaximumPathComponentLength(target_dir); | 218 int max_length = base::GetMaximumPathComponentLength(target_dir); |
| 214 if (max_length != -1) { | 219 if (max_length != -1) { |
| 215 int limit = max_length - kIntermediateNameSuffixLength; | 220 int limit = max_length - kIntermediateNameSuffixLength; |
| 216 if (limit <= 0 || !TruncateFileName(&target_path, limit)) | 221 if (limit <= 0 || !TruncateFileName(&target_path, limit)) |
| 217 name_too_long = true; | 222 name_too_long = true; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 base::Bind(&RunGetReservedPathCallback, | 394 base::Bind(&RunGetReservedPathCallback, |
| 390 callback, | 395 callback, |
| 391 base::Owned(reserved_path))); | 396 base::Owned(reserved_path))); |
| 392 } | 397 } |
| 393 | 398 |
| 394 // static | 399 // static |
| 395 bool DownloadPathReservationTracker::IsPathInUseForTesting( | 400 bool DownloadPathReservationTracker::IsPathInUseForTesting( |
| 396 const base::FilePath& path) { | 401 const base::FilePath& path) { |
| 397 return IsPathInUse(path); | 402 return IsPathInUse(path); |
| 398 } | 403 } |
| OLD | NEW |