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

Side by Side Diff: net/base/net_util.h

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_context.h ('k') | net/base/network_delegate.h » ('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 (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 #ifndef NET_BASE_NET_UTIL_H_ 5 #ifndef NET_BASE_NET_UTIL_H_
6 #define NET_BASE_NET_UTIL_H_ 6 #define NET_BASE_NET_UTIL_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include <windows.h> 11 #include <windows.h>
12 #include <ws2tcpip.h> 12 #include <ws2tcpip.h>
13 #elif defined(OS_POSIX) 13 #elif defined(OS_POSIX)
14 #include <sys/types.h> 14 #include <sys/types.h>
15 #include <sys/socket.h> 15 #include <sys/socket.h>
16 #endif 16 #endif
17 17
18 #include <list> 18 #include <list>
19 #include <string> 19 #include <string>
20 #include <set> 20 #include <set>
21 #include <vector> 21 #include <vector>
22 22
23 #include "base/basictypes.h" 23 #include "base/basictypes.h"
24 #include "base/string16.h" 24 #include "base/string16.h"
25 #include "net/base/escape.h" 25 #include "net/base/escape.h"
26 #include "net/base/net_export.h" 26 #include "net/base/net_export.h"
27 #include "net/base/net_log.h" 27 #include "net/base/net_log.h"
28 28
29 class FilePath;
30 class GURL; 29 class GURL;
31 30
32 namespace base { 31 namespace base {
32 class FilePath;
33 class Time; 33 class Time;
34 } 34 }
35 35
36 namespace url_canon { 36 namespace url_canon {
37 struct CanonHostInfo; 37 struct CanonHostInfo;
38 } 38 }
39 39
40 namespace url_parse { 40 namespace url_parse {
41 struct Parsed; 41 struct Parsed;
42 } 42 }
(...skipping 29 matching lines...) Expand all
72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; 72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname;
73 73
74 // Convenience for omitting all unecessary types. 74 // Convenience for omitting all unecessary types.
75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; 75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll;
76 76
77 // Returns the number of explicitly allowed ports; for testing. 77 // Returns the number of explicitly allowed ports; for testing.
78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); 78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts();
79 79
80 // Given the full path to a file name, creates a file: URL. The returned URL 80 // Given the full path to a file name, creates a file: URL. The returned URL
81 // may not be valid if the input is malformed. 81 // may not be valid if the input is malformed.
82 NET_EXPORT GURL FilePathToFileURL(const FilePath& path); 82 NET_EXPORT GURL FilePathToFileURL(const base::FilePath& path);
83 83
84 // Converts a file: URL back to a filename that can be passed to the OS. The 84 // Converts a file: URL back to a filename that can be passed to the OS. The
85 // file URL must be well-formed (GURL::is_valid() must return true); we don't 85 // file URL must be well-formed (GURL::is_valid() must return true); we don't
86 // handle degenerate cases here. Returns true on success, false if it isn't a 86 // handle degenerate cases here. Returns true on success, false if it isn't a
87 // valid file URL. On failure, *file_path will be empty. 87 // valid file URL. On failure, *file_path will be empty.
88 NET_EXPORT bool FileURLToFilePath(const GURL& url, FilePath* file_path); 88 NET_EXPORT bool FileURLToFilePath(const GURL& url, base::FilePath* file_path);
89 89
90 // Splits an input of the form <host>[":"<port>] into its consitituent parts. 90 // Splits an input of the form <host>[":"<port>] into its consitituent parts.
91 // Saves the result into |*host| and |*port|. If the input did not have 91 // Saves the result into |*host| and |*port|. If the input did not have
92 // the optional port, sets |*port| to -1. 92 // the optional port, sets |*port| to -1.
93 // Returns true if the parsing was successful, false otherwise. 93 // Returns true if the parsing was successful, false otherwise.
94 // The returned host is NOT canonicalized, and may be invalid. If <host> is 94 // The returned host is NOT canonicalized, and may be invalid. If <host> is
95 // an IPv6 literal address, the returned host includes the square brackets. 95 // an IPv6 literal address, the returned host includes the square brackets.
96 NET_EXPORT bool ParseHostAndPort( 96 NET_EXPORT bool ParseHostAndPort(
97 std::string::const_iterator host_and_port_begin, 97 std::string::const_iterator host_and_port_begin,
98 std::string::const_iterator host_and_port_end, 98 std::string::const_iterator host_and_port_end,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // Note: |mime_type| should only be specified if this function is called from a 271 // Note: |mime_type| should only be specified if this function is called from a
272 // thread that allows IO. 272 // thread that allows IO.
273 NET_EXPORT string16 GetSuggestedFilename(const GURL& url, 273 NET_EXPORT string16 GetSuggestedFilename(const GURL& url,
274 const std::string& content_disposition, 274 const std::string& content_disposition,
275 const std::string& referrer_charset, 275 const std::string& referrer_charset,
276 const std::string& suggested_name, 276 const std::string& suggested_name,
277 const std::string& mime_type, 277 const std::string& mime_type,
278 const std::string& default_name); 278 const std::string& default_name);
279 279
280 // Similar to GetSuggestedFilename(), but returns a FilePath. 280 // Similar to GetSuggestedFilename(), but returns a FilePath.
281 NET_EXPORT FilePath GenerateFileName(const GURL& url, 281 NET_EXPORT base::FilePath GenerateFileName(
282 const std::string& content_disposition, 282 const GURL& url,
283 const std::string& referrer_charset, 283 const std::string& content_disposition,
284 const std::string& suggested_name, 284 const std::string& referrer_charset,
285 const std::string& mime_type, 285 const std::string& suggested_name,
286 const std::string& default_name); 286 const std::string& mime_type,
287 const std::string& default_name);
287 288
288 // Ensures that the filename and extension is safe to use in the filesystem. 289 // Ensures that the filename and extension is safe to use in the filesystem.
289 // 290 //
290 // Assumes that |file_path| already contains a valid path or file name. On 291 // Assumes that |file_path| already contains a valid path or file name. On
291 // Windows if the extension causes the file to have an unsafe interaction with 292 // Windows if the extension causes the file to have an unsafe interaction with
292 // the shell (see net_util::IsShellIntegratedExtension()), then it will be 293 // the shell (see net_util::IsShellIntegratedExtension()), then it will be
293 // replaced by the string 'download'. If |file_path| doesn't contain an 294 // replaced by the string 'download'. If |file_path| doesn't contain an
294 // extension or |ignore_extension| is true then the preferred extension, if one 295 // extension or |ignore_extension| is true then the preferred extension, if one
295 // exists, for |mime_type| will be used as the extension. 296 // exists, for |mime_type| will be used as the extension.
296 // 297 //
297 // On Windows, the filename will be checked against a set of reserved names, and 298 // On Windows, the filename will be checked against a set of reserved names, and
298 // if so, an underscore will be prepended to the name. 299 // if so, an underscore will be prepended to the name.
299 // 300 //
300 // |file_name| can either be just the file name or it can be a full path to a 301 // |file_name| can either be just the file name or it can be a full path to a
301 // file. 302 // file.
302 // 303 //
303 // Note: |mime_type| should only be non-empty if this function is called from a 304 // Note: |mime_type| should only be non-empty if this function is called from a
304 // thread that allows IO. 305 // thread that allows IO.
305 NET_EXPORT void GenerateSafeFileName(const std::string& mime_type, 306 NET_EXPORT void GenerateSafeFileName(const std::string& mime_type,
306 bool ignore_extension, 307 bool ignore_extension,
307 FilePath* file_path); 308 base::FilePath* file_path);
308 309
309 // Checks |port| against a list of ports which are restricted by default. 310 // Checks |port| against a list of ports which are restricted by default.
310 // Returns true if |port| is allowed, false if it is restricted. 311 // Returns true if |port| is allowed, false if it is restricted.
311 NET_EXPORT bool IsPortAllowedByDefault(int port); 312 NET_EXPORT bool IsPortAllowedByDefault(int port);
312 313
313 // Checks |port| against a list of ports which are restricted by the FTP 314 // Checks |port| against a list of ports which are restricted by the FTP
314 // protocol. Returns true if |port| is allowed, false if it is restricted. 315 // protocol. Returns true if |port| is allowed, false if it is restricted.
315 NET_EXPORT_PRIVATE bool IsPortAllowedByFtp(int port); 316 NET_EXPORT_PRIVATE bool IsPortAllowedByFtp(int port);
316 317
317 // Check if banned |port| has been overriden by an entry in 318 // Check if banned |port| has been overriden by an entry in
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 512
512 // Returns list of network interfaces except loopback interface. If an 513 // Returns list of network interfaces except loopback interface. If an
513 // interface has more than one address, a separate entry is added to 514 // interface has more than one address, a separate entry is added to
514 // the list for each address. 515 // the list for each address.
515 // Can be called only on a thread that allows IO. 516 // Can be called only on a thread that allows IO.
516 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks); 517 NET_EXPORT bool GetNetworkList(NetworkInterfaceList* networks);
517 518
518 } // namespace net 519 } // namespace net
519 520
520 #endif // NET_BASE_NET_UTIL_H_ 521 #endif // NET_BASE_NET_UTIL_H_
OLDNEW
« no previous file with comments | « net/base/file_stream_context.h ('k') | net/base/network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698