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

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

Issue 2229393003: net: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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/expiring_cache_unittest.cc ('k') | net/base/network_activity_monitor_unittest.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/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // type. 47 // type.
48 base::FilePath::StringType preferred_mime_extension; 48 base::FilePath::StringType preferred_mime_extension;
49 if (!GetPreferredExtensionForMimeType(mime_type, &preferred_mime_extension)) 49 if (!GetPreferredExtensionForMimeType(mime_type, &preferred_mime_extension))
50 return extension; 50 return extension;
51 51
52 // If the existing extension is in the list of valid extensions for the 52 // If the existing extension is in the list of valid extensions for the
53 // given type, use it. This avoids doing things like pointlessly renaming 53 // given type, use it. This avoids doing things like pointlessly renaming
54 // "foo.jpg" to "foo.jpeg". 54 // "foo.jpg" to "foo.jpeg".
55 std::vector<base::FilePath::StringType> all_mime_extensions; 55 std::vector<base::FilePath::StringType> all_mime_extensions;
56 GetExtensionsForMimeType(mime_type, &all_mime_extensions); 56 GetExtensionsForMimeType(mime_type, &all_mime_extensions);
57 if (ContainsValue(all_mime_extensions, extension)) 57 if (base::ContainsValue(all_mime_extensions, extension))
58 return extension; 58 return extension;
59 59
60 // Get the "final" extension. In most cases, this is the same as the 60 // Get the "final" extension. In most cases, this is the same as the
61 // |extension|, but in cases like "foo.tar.gz", it's "gz" while 61 // |extension|, but in cases like "foo.tar.gz", it's "gz" while
62 // |extension| is "tar.gz". 62 // |extension| is "tar.gz".
63 base::FilePath::StringType final_extension = file_name.FinalExtension(); 63 base::FilePath::StringType final_extension = file_name.FinalExtension();
64 // Erase preceding '.'. 64 // Erase preceding '.'.
65 if (!final_extension.empty()) 65 if (!final_extension.empty())
66 final_extension.erase(final_extension.begin()); 66 final_extension.erase(final_extension.begin());
67 67
68 // If there's a double extension, and the second extension is in the 68 // If there's a double extension, and the second extension is in the
69 // list of valid extensions for the given type, keep the double extension. 69 // list of valid extensions for the given type, keep the double extension.
70 // This avoids renaming things like "foo.tar.gz" to "foo.gz". 70 // This avoids renaming things like "foo.tar.gz" to "foo.gz".
71 if (ContainsValue(all_mime_extensions, final_extension)) 71 if (base::ContainsValue(all_mime_extensions, final_extension))
72 return extension; 72 return extension;
73 return preferred_mime_extension; 73 return preferred_mime_extension;
74 } 74 }
75 75
76 } // namespace 76 } // namespace
77 77
78 void SanitizeGeneratedFileName(base::FilePath::StringType* filename, 78 void SanitizeGeneratedFileName(base::FilePath::StringType* filename,
79 bool replace_trailing) { 79 bool replace_trailing) {
80 const base::FilePath::CharType kReplace[] = FILE_PATH_LITERAL("-"); 80 const base::FilePath::CharType kReplace[] = FILE_PATH_LITERAL("-");
81 if (filename->empty()) 81 if (filename->empty())
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 base::FilePath generated_name( 321 base::FilePath generated_name(
322 base::SysWideToNativeMB(base::UTF16ToWide(file_name))); 322 base::SysWideToNativeMB(base::UTF16ToWide(file_name)));
323 #endif 323 #endif
324 324
325 DCHECK(!generated_name.empty()); 325 DCHECK(!generated_name.empty());
326 326
327 return generated_name; 327 return generated_name;
328 } 328 }
329 329
330 } // namespace net 330 } // namespace net
OLDNEW
« no previous file with comments | « net/base/expiring_cache_unittest.cc ('k') | net/base/network_activity_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698