Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: net/base/filename_util.cc

Issue 869233006: [net] Cleanup filename_util and make it portable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@clang-format-filename-tests
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/filename_util.h ('k') | net/base/filename_util_icu.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/base/filename_util.h ('k') | net/base/filename_util_icu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698