| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/filename_util.h" | 5 #include "net/base/filename_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 ReplaceSubstringsAfterOffset(&new_path, 0, "//", "/"); | 131 ReplaceSubstringsAfterOffset(&new_path, 0, "//", "/"); |
| 132 path.swap(new_path); | 132 path.swap(new_path); |
| 133 } while (new_path != path); | 133 } while (new_path != path); |
| 134 | 134 |
| 135 file_path_str.assign(path); | 135 file_path_str.assign(path); |
| 136 #endif // !defined(OS_WIN) | 136 #endif // !defined(OS_WIN) |
| 137 | 137 |
| 138 return !file_path_str.empty(); | 138 return !file_path_str.empty(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void GenerateSafeFileName(const std::string& mime_type, | |
| 142 bool ignore_extension, | |
| 143 base::FilePath* file_path) { | |
| 144 // Make sure we get the right file extension | |
| 145 EnsureSafeExtension(mime_type, ignore_extension, file_path); | |
| 146 | |
| 147 #if defined(OS_WIN) | |
| 148 // Prepend "_" to the file name if it's a reserved name | |
| 149 base::FilePath::StringType leaf_name = file_path->BaseName().value(); | |
| 150 DCHECK(!leaf_name.empty()); | |
| 151 if (IsReservedName(leaf_name)) { | |
| 152 leaf_name = base::FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; | |
| 153 *file_path = file_path->DirName(); | |
| 154 if (file_path->value() == base::FilePath::kCurrentDirectory) { | |
| 155 *file_path = base::FilePath(leaf_name); | |
| 156 } else { | |
| 157 *file_path = file_path->Append(leaf_name); | |
| 158 } | |
| 159 } | |
| 160 #endif | |
| 161 } | |
| 162 | |
| 163 } // namespace net | 141 } // namespace net |
| OLD | NEW |