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

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

Issue 447403002: Move file_util_icu to base::i18n namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/directory_lister_unittest.cc ('k') | printing/printed_document.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/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/i18n/file_util_icu.h" 9 #include "base/i18n/file_util_icu.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "net/base/filename_util_internal.h" 11 #include "net/base/filename_util_internal.h"
12 12
13 class GURL; 13 class GURL;
14 14
15 namespace net { 15 namespace net {
16 16
17 bool IsSafePortablePathComponent(const base::FilePath& component) { 17 bool IsSafePortablePathComponent(const base::FilePath& component) {
18 base::string16 component16; 18 base::string16 component16;
19 base::FilePath::StringType sanitized = component.value(); 19 base::FilePath::StringType sanitized = component.value();
20 SanitizeGeneratedFileName(&sanitized, true); 20 SanitizeGeneratedFileName(&sanitized, true);
21 base::FilePath::StringType extension = component.Extension(); 21 base::FilePath::StringType extension = component.Extension();
22 if (!extension.empty()) 22 if (!extension.empty())
23 extension.erase(extension.begin()); // Erase preceding '.'. 23 extension.erase(extension.begin()); // Erase preceding '.'.
24 return !component.empty() && (component == component.BaseName()) && 24 return !component.empty() && (component == component.BaseName()) &&
25 (component == component.StripTrailingSeparators()) && 25 (component == component.StripTrailingSeparators()) &&
26 FilePathToString16(component, &component16) && 26 FilePathToString16(component, &component16) &&
27 file_util::IsFilenameLegal(component16) && 27 base::i18n::IsFilenameLegal(component16) &&
28 !IsShellIntegratedExtension(extension) && 28 !IsShellIntegratedExtension(extension) &&
29 (sanitized == component.value()) && !IsReservedName(component.value()); 29 (sanitized == component.value()) && !IsReservedName(component.value());
30 } 30 }
31 31
32 bool IsSafePortableRelativePath(const base::FilePath& path) { 32 bool IsSafePortableRelativePath(const base::FilePath& path) {
33 if (path.empty() || path.IsAbsolute() || path.EndsWithSeparator()) 33 if (path.empty() || path.IsAbsolute() || path.EndsWithSeparator())
34 return false; 34 return false;
35 std::vector<base::FilePath::StringType> components; 35 std::vector<base::FilePath::StringType> components;
36 path.GetComponents(&components); 36 path.GetComponents(&components);
37 if (components.empty()) 37 if (components.empty())
(...skipping 11 matching lines...) Expand all
49 const std::string& suggested_name, 49 const std::string& suggested_name,
50 const std::string& mime_type, 50 const std::string& mime_type,
51 const std::string& default_name) { 51 const std::string& default_name) {
52 return GetSuggestedFilenameImpl( 52 return GetSuggestedFilenameImpl(
53 url, 53 url,
54 content_disposition, 54 content_disposition,
55 referrer_charset, 55 referrer_charset,
56 suggested_name, 56 suggested_name,
57 mime_type, 57 mime_type,
58 default_name, 58 default_name,
59 base::Bind(&file_util::ReplaceIllegalCharactersInPath)); 59 base::Bind(&base::i18n::ReplaceIllegalCharactersInPath));
60 } 60 }
61 61
62 base::FilePath GenerateFileName(const GURL& url, 62 base::FilePath GenerateFileName(const GURL& url,
63 const std::string& content_disposition, 63 const std::string& content_disposition,
64 const std::string& referrer_charset, 64 const std::string& referrer_charset,
65 const std::string& suggested_name, 65 const std::string& suggested_name,
66 const std::string& mime_type, 66 const std::string& mime_type,
67 const std::string& default_file_name) { 67 const std::string& default_file_name) {
68 base::FilePath generated_name(GenerateFileNameImpl( 68 base::FilePath generated_name(GenerateFileNameImpl(
69 url, 69 url,
70 content_disposition, 70 content_disposition,
71 referrer_charset, 71 referrer_charset,
72 suggested_name, 72 suggested_name,
73 mime_type, 73 mime_type,
74 default_file_name, 74 default_file_name,
75 base::Bind(&file_util::ReplaceIllegalCharactersInPath))); 75 base::Bind(&base::i18n::ReplaceIllegalCharactersInPath)));
76 76
77 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
78 // When doing file manager operations on ChromeOS, the file paths get 78 // When doing file manager operations on ChromeOS, the file paths get
79 // normalized in WebKit layer, so let's ensure downloaded files have 79 // normalized in WebKit layer, so let's ensure downloaded files have
80 // normalized names. Otherwise, we won't be able to handle files with NFD 80 // normalized names. Otherwise, we won't be able to handle files with NFD
81 // utf8 encoded characters in name. 81 // utf8 encoded characters in name.
82 file_util::NormalizeFileNameEncoding(&generated_name); 82 base::i18n::NormalizeFileNameEncoding(&generated_name);
83 #endif 83 #endif
84 84
85 DCHECK(!generated_name.empty()); 85 DCHECK(!generated_name.empty());
86 86
87 return generated_name; 87 return generated_name;
88 } 88 }
89 89
90 } // namespace net 90 } // namespace net
OLDNEW
« no previous file with comments | « net/base/directory_lister_unittest.cc ('k') | printing/printed_document.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698