diff options
author | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 21:39:37 +0000 |
---|---|---|
committer | tony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 21:39:37 +0000 |
commit | f294da7127cd4c278aa1f172e94d382250e92e4e (patch) | |
tree | 2a7e899a35be6d2a899ae7916a3a250c362a53a9 /base | |
parent | 59fea0a2182828f3410a16ae68296cc9dcbbf8c2 (diff) | |
download | chromium_src-f294da7127cd4c278aa1f172e94d382250e92e4e.zip chromium_src-f294da7127cd4c278aa1f172e94d382250e92e4e.tar.gz chromium_src-f294da7127cd4c278aa1f172e94d382250e92e4e.tar.bz2 |
Step 2 in porting disk cache to using FilePath.
BUG=24444
Review URL: http://codereview.chromium.org/270066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28742 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/platform_file.h | 6 | ||||
-rw-r--r-- | base/platform_file_posix.cc | 17 | ||||
-rw-r--r-- | base/platform_file_win.cc | 12 |
3 files changed, 25 insertions, 10 deletions
diff --git a/base/platform_file.h b/base/platform_file.h index 5d84262..0dbf4e4 100644 --- a/base/platform_file.h +++ b/base/platform_file.h @@ -12,6 +12,8 @@ #include <string> +class FilePath; + namespace base { #if defined(OS_WIN) @@ -40,6 +42,10 @@ enum PlatformFileFlags { // Creates or opens the given file. If PLATFORM_FILE_OPEN_ALWAYS is used, and // |created| is provided, |created| will be set to true if the file was created // or to false in case the file was just opened. +PlatformFile CreatePlatformFile(const FilePath& name, + int flags, + bool* created); +// Deprecated. PlatformFile CreatePlatformFile(const std::wstring& name, int flags, bool* created); diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc index 623223c..46039b9 100644 --- a/base/platform_file_posix.cc +++ b/base/platform_file_posix.cc @@ -8,14 +8,14 @@ #include <errno.h> #include <sys/stat.h> +#include "base/file_path.h" #include "base/logging.h" #include "base/utf_string_conversions.h" namespace base { // TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here? -PlatformFile CreatePlatformFile(const std::wstring& name, - int flags, +PlatformFile CreatePlatformFile(const FilePath& name, int flags, bool* created) { int open_flags = 0; if (flags & PLATFORM_FILE_CREATE) @@ -43,8 +43,7 @@ PlatformFile CreatePlatformFile(const std::wstring& name, DCHECK(O_RDONLY == 0); - int descriptor = open(WideToUTF8(name).c_str(), open_flags, - S_IRUSR | S_IWUSR); + int descriptor = open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR); if (flags & PLATFORM_FILE_OPEN_ALWAYS) { if (descriptor > 0) { @@ -56,20 +55,24 @@ PlatformFile CreatePlatformFile(const std::wstring& name, flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW } - descriptor = open(WideToUTF8(name).c_str(), open_flags, - S_IRUSR | S_IWUSR); + descriptor = open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR); if (created && descriptor > 0) *created = true; } } if ((descriptor > 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { - unlink(WideToUTF8(name).c_str()); + unlink(name.value().c_str()); } return descriptor; } +PlatformFile CreatePlatformFile(const std::wstring& name, int flags, + bool* created) { + return CreatePlatformFile(FilePath::FromWStringHack(name), flags, created); +} + bool ClosePlatformFile(PlatformFile file) { return close(file); } diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc index 06e6200..1143487 100644 --- a/base/platform_file_win.cc +++ b/base/platform_file_win.cc @@ -4,11 +4,12 @@ #include "base/platform_file.h" +#include "base/file_path.h" #include "base/logging.h" namespace base { -PlatformFile CreatePlatformFile(const std::wstring& name, +PlatformFile CreatePlatformFile(const FilePath& name, int flags, bool* created) { DWORD disposition = 0; @@ -54,8 +55,8 @@ PlatformFile CreatePlatformFile(const std::wstring& name, if (flags & PLATFORM_FILE_DELETE_ON_CLOSE) create_flags |= FILE_FLAG_DELETE_ON_CLOSE; - HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition, - create_flags, NULL); + HANDLE file = CreateFile(name.value().c_str(), access, sharing, NULL, + disposition, create_flags, NULL); if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created && INVALID_HANDLE_VALUE != file) { @@ -65,6 +66,11 @@ PlatformFile CreatePlatformFile(const std::wstring& name, return file; } +PlatformFile CreatePlatformFile(const std::wstring& name, int flags, + bool* created) { + return CreatePlatformFile(FilePath::FromWStringHack(name), flags, created); +} + bool ClosePlatformFile(PlatformFile file) { return (CloseHandle(file) == 0); } |