| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::FilePath filename = target_path.BaseName(); | 173 base::FilePath filename = target_path.BaseName(); |
| 174 bool is_path_writeable = true; | 174 bool is_path_writeable = true; |
| 175 bool has_conflicts = false; | 175 bool has_conflicts = false; |
| 176 bool name_too_long = false; | 176 bool name_too_long = false; |
| 177 | 177 |
| 178 // Create target_dir if necessary and appropriate. target_dir may be the last | 178 // Create target_dir if necessary and appropriate. target_dir may be the last |
| 179 // directory that the user selected in a FilePicker; if that directory has | 179 // directory that the user selected in a FilePicker; if that directory has |
| 180 // since been removed, do NOT automatically re-create it. Only automatically | 180 // since been removed, do NOT automatically re-create it. Only automatically |
| 181 // create the directory if it is the default Downloads directory or if the | 181 // create the directory if it is the default Downloads directory or if the |
| 182 // caller explicitly requested automatic directory creation. | 182 // caller explicitly requested automatic directory creation. |
| 183 if (!file_util::DirectoryExists(target_dir) && | 183 if (!base::DirectoryExists(target_dir) && |
| 184 (create_directory || | 184 (create_directory || |
| 185 (!default_download_path.empty() && | 185 (!default_download_path.empty() && |
| 186 (default_download_path == target_dir)))) { | 186 (default_download_path == target_dir)))) { |
| 187 file_util::CreateDirectory(target_dir); | 187 file_util::CreateDirectory(target_dir); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Check writability of the suggested path. If we can't write to it, default | 190 // Check writability of the suggested path. If we can't write to it, default |
| 191 // to the user's "My Documents" directory. We'll prompt them in this case. | 191 // to the user's "My Documents" directory. We'll prompt them in this case. |
| 192 if (!file_util::PathIsWritable(target_dir)) { | 192 if (!base::PathIsWritable(target_dir)) { |
| 193 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; | 193 DVLOG(1) << "Unable to write to directory \"" << target_dir.value() << "\""; |
| 194 is_path_writeable = false; | 194 is_path_writeable = false; |
| 195 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); | 195 PathService::Get(chrome::DIR_USER_DOCUMENTS, &target_dir); |
| 196 target_path = target_dir.Append(filename); | 196 target_path = target_dir.Append(filename); |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (is_path_writeable) { | 199 if (is_path_writeable) { |
| 200 // Check the limit of file name length if it could be obtained. When the | 200 // Check the limit of file name length if it could be obtained. When the |
| 201 // suggested name exceeds the limit, truncate or prompt the user. | 201 // suggested name exceeds the limit, truncate or prompt the user. |
| 202 int max_length = file_util::GetMaximumPathComponentLength(target_dir); | 202 int max_length = file_util::GetMaximumPathComponentLength(target_dir); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 create_directory, | 358 create_directory, |
| 359 conflict_action, | 359 conflict_action, |
| 360 callback)); | 360 callback)); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // static | 363 // static |
| 364 bool DownloadPathReservationTracker::IsPathInUseForTesting( | 364 bool DownloadPathReservationTracker::IsPathInUseForTesting( |
| 365 const base::FilePath& path) { | 365 const base::FilePath& path) { |
| 366 return IsPathInUse(path); | 366 return IsPathInUse(path); |
| 367 } | 367 } |
| OLD | NEW |