summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 17:18:14 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-03 17:18:14 +0000
commit21da6eb1f8a9740de03cb1435bf935f5a3609a37 (patch)
tree47e6bdd8db72ee4b66f526bbe79cbca74ef85560 /base
parent0a173a23af355f6b4eceeb18f28b453063e4287c (diff)
downloadchromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.zip
chromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.tar.gz
chromium_src-21da6eb1f8a9740de03cb1435bf935f5a3609a37.tar.bz2
* Add write and read/write support to FileStream (renamed from FileInputStream).
* Moved net/disk_cache/os_file to base/platform_file. Review URL: http://codereview.chromium.org/8843 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.xcodeproj/project.pbxproj16
-rw-r--r--base/base_lib.scons2
-rw-r--r--base/build/base.vcproj8
-rw-r--r--base/platform_file.h46
-rw-r--r--base/platform_file_posix.cc64
-rw-r--r--base/platform_file_win.cc63
6 files changed, 189 insertions, 10 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index 1c438c3..3e8ed71 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -142,6 +142,7 @@
93E703170E5D63E00046259B /* platform_thread_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 93E703160E5D63E00046259B /* platform_thread_posix.cc */; };
93E7031B0E5D64390046259B /* thread_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 93E7031A0E5D64390046259B /* thread_unittest.cc */; };
93E703240E5D64F00046259B /* thread.cc in Sources */ = {isa = PBXBuildFile; fileRef = 93E703230E5D64F00046259B /* thread.cc */; };
+ A573F5D90EBB78260055A84A /* platform_file_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A573F5D80EBB78260055A84A /* platform_file_posix.cc */; };
A5A026550E4A214600498DA9 /* file_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A026540E4A214600498DA9 /* file_util.cc */; };
A5A0268E0E4A2BDC00498DA9 /* file_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */; };
A5A0270B0E4A630D00498DA9 /* file_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */; };
@@ -171,9 +172,6 @@
B57E4D780E9C26340090055D /* idletimer_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B57E4D770E9C26340090055D /* idletimer_unittest.cc */; };
B5D544AB0EAFB7E000272A1C /* sys_string_conversions_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D544AA0EAFB7E000272A1C /* sys_string_conversions_unittest.cc */; };
B5EF235C0E89ABF500E1E114 /* platform_canvas_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABE1BA0C0E756EC4009041DA /* platform_canvas_unittest.cc */; };
- B5F7AFD20EB77ACA00EDB165 /* stats_table_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5F7AFD10EB77ACA00EDB165 /* stats_table_unittest.cc */; };
- B5F7AFD80EB77B1600EDB165 /* process_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5F7AFD70EB77B1600EDB165 /* process_util_mac.mm */; };
- B5F7B1F30EB7B3DA00EDB165 /* process_util_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BD8F4A00E65AA2400034DE9 /* process_util_unittest.cc */; };
BA0F69870E79D7980079A8A1 /* thread_local_storage_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */; };
BA5CC5840E788093004EDD45 /* shared_memory_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA5CC5830E788093004EDD45 /* shared_memory_unittest.cc */; };
BA739A020E5E3242009842A7 /* tracked_objects_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA739A000E5E3242009842A7 /* tracked_objects_unittest.cc */; };
@@ -607,6 +605,8 @@
93E703160E5D63E00046259B /* platform_thread_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = platform_thread_posix.cc; sourceTree = "<group>"; };
93E7031A0E5D64390046259B /* thread_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_unittest.cc; sourceTree = "<group>"; };
93E703230E5D64F00046259B /* thread.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread.cc; sourceTree = "<group>"; };
+ A573F5D70EBB78260055A84A /* platform_file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = platform_file.h; sourceTree = "<group>"; };
+ A573F5D80EBB78260055A84A /* platform_file_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = platform_file_posix.cc; sourceTree = "<group>"; };
A5A026180E48FE1500498DA9 /* base_paths_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = base_paths_mac.h; sourceTree = "<group>"; };
A5A026540E4A214600498DA9 /* file_util.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util.cc; sourceTree = "<group>"; };
A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_posix.cc; sourceTree = "<group>"; };
@@ -630,8 +630,6 @@
B52C916B0E9428F500208D01 /* clipboard_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipboard_unittest.cc; sourceTree = "<group>"; };
B57E4D770E9C26340090055D /* idletimer_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = idletimer_unittest.cc; sourceTree = "<group>"; };
B5D544AA0EAFB7E000272A1C /* sys_string_conversions_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_string_conversions_unittest.cc; sourceTree = "<group>"; };
- B5F7AFD10EB77ACA00EDB165 /* stats_table_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stats_table_unittest.cc; sourceTree = "<group>"; };
- B5F7AFD70EB77B1600EDB165 /* process_util_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = process_util_mac.mm; sourceTree = "<group>"; };
BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_storage_unittest.cc; sourceTree = "<group>"; };
BA5CC5830E788093004EDD45 /* shared_memory_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shared_memory_unittest.cc; sourceTree = "<group>"; };
BA739A000E5E3242009842A7 /* tracked_objects_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tracked_objects_unittest.cc; sourceTree = "<group>"; };
@@ -933,6 +931,8 @@
8254033E0D92D2210006B936 /* pickle.cc */,
8254033F0D92D2210006B936 /* pickle.h */,
E4562C680E2803C3005E4685 /* pickle_unittest.cc */,
+ A573F5D70EBB78260055A84A /* platform_file.h */,
+ A573F5D80EBB78260055A84A /* platform_file_posix.cc */,
A5CB82960E5C74E300FD6825 /* platform_test.h */,
A5CB82970E5C74E300FD6825 /* platform_test_mac.mm */,
82E23FCB0D9C219600F8B40A /* platform_thread.h */,
@@ -945,7 +945,6 @@
820EB4F10E3A6127009668FC /* process.cc */,
820EB4F20E3A6127009668FC /* process.h */,
825403510D92D24D0006B936 /* process_util.h */,
- B5F7AFD70EB77B1600EDB165 /* process_util_mac.mm */,
7BD8F49F0E65AA2400034DE9 /* process_util_posix.cc */,
7BD8F4A00E65AA2400034DE9 /* process_util_unittest.cc */,
8254034B0D92D23C0006B936 /* prtime.cc */,
@@ -994,7 +993,6 @@
825403780D92D2CF0006B936 /* stats_counters.h */,
825403790D92D2CF0006B936 /* stats_table.cc */,
8254037A0D92D2CF0006B936 /* stats_table.h */,
- B5F7AFD10EB77ACA00EDB165 /* stats_table_unittest.cc */,
7BD8F7730E65E89800034DE9 /* string16.cc */,
821B91680DAABD7F00F350D7 /* string16.h */,
E4A133420E37A3C400110AA2 /* string_escape.cc */,
@@ -1390,7 +1388,6 @@
824654A60DC25CD7007C2BAA /* pickle.cc in Sources */,
7BF164F30E660CA500AA999E /* platform_thread_mac.mm in Sources */,
93E703170E5D63E00046259B /* platform_thread_posix.cc in Sources */,
- B5F7AFD80EB77B1600EDB165 /* process_util_mac.mm in Sources */,
7BD8F4A10E65AA4600034DE9 /* process_util_posix.cc in Sources */,
824654DF0DC26521007C2BAA /* prtime.cc in Sources */,
4D11B59A0E91730200EF7617 /* rand_util.cc in Sources */,
@@ -1425,6 +1422,7 @@
9301C03B0E54C839001EF103 /* waitable_event_generic.cc in Sources */,
824655DD0DC659B8007C2BAA /* word_iterator.cc in Sources */,
7BF1658D0E663B4800AA999E /* worker_pool_mac.mm in Sources */,
+ A573F5D90EBB78260055A84A /* platform_file_posix.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1474,7 +1472,6 @@
7B78D3970E54FE0100609465 /* pickle_unittest.cc in Sources */,
B5EF235C0E89ABF500E1E114 /* platform_canvas_unittest.cc in Sources */,
A5CB82980E5C74E300FD6825 /* platform_test_mac.mm in Sources */,
- B5F7B1F30EB7B3DA00EDB165 /* process_util_unittest.cc in Sources */,
7B8505D50E5B441000730B43 /* png_codec_unittest.cc in Sources */,
7B78D3980E54FE0100609465 /* pr_time_unittest.cc in Sources */,
4D11B59C0E91730500EF7617 /* rand_util_unittest.cc in Sources */,
@@ -1487,7 +1484,6 @@
7BAE30E60E6D939F00C3F750 /* simple_thread_unittest.cc in Sources */,
7B78D39C0E54FE0100609465 /* singleton_unittest.cc in Sources */,
7B78D39D0E54FE0100609465 /* stack_container_unittest.cc in Sources */,
- B5F7AFD20EB77ACA00EDB165 /* stats_table_unittest.cc in Sources */,
7B78D39E0E54FE0100609465 /* string_escape_unittest.cc in Sources */,
7B78D39F0E54FE0100609465 /* string_piece_unittest.cc in Sources */,
7B78D3A00E54FE0100609465 /* string_tokenizer_unittest.cc in Sources */,
diff --git a/base/base_lib.scons b/base/base_lib.scons
index 6bedfdb..0ef9cf4 100644
--- a/base/base_lib.scons
+++ b/base/base_lib.scons
@@ -121,6 +121,7 @@ if env['PLATFORM'] == 'win32':
'lock_impl_win.cc',
'message_pump_win.cc',
'pe_image.cc',
+ 'platform_file_win.cc',
'platform_thread_win.cc',
'process_util_win.cc',
'process_win.cc',
@@ -146,6 +147,7 @@ if env['PLATFORM'] in ('darwin', 'posix'):
'file_util_posix.cc',
'lock_impl_posix.cc',
'message_pump_libevent.cc',
+ 'platform_file_posix.cc',
'platform_thread_posix.cc',
'process_util_posix.cc',
'rand_util_posix.cc',
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index a1731da..f031e75 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -530,6 +530,14 @@
>
</File>
<File
+ RelativePath="..\platform_file.h"
+ >
+ </File>
+ <File
+ RelativePath="..\platform_file_win.cc"
+ >
+ </File>
+ <File
RelativePath="..\platform_thread.h"
>
</File>
diff --git a/base/platform_file.h b/base/platform_file.h
new file mode 100644
index 0000000..2230b40
--- /dev/null
+++ b/base/platform_file.h
@@ -0,0 +1,46 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_PLATFORM_FILE_H_
+#define BASE_PLATFORM_FILE_H_
+
+#include "build/build_config.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
+#include <string>
+
+namespace base {
+
+#if defined(OS_WIN)
+typedef HANDLE PlatformFile;
+const PlatformFile kInvalidPlatformFileValue = INVALID_HANDLE_VALUE;
+#elif defined(OS_POSIX)
+typedef int PlatformFile;
+const PlatformFile kInvalidPlatformFileValue = -1;
+#endif
+
+enum PlatformFileFlags {
+ PLATFORM_FILE_OPEN = 1,
+ PLATFORM_FILE_CREATE = 2,
+ PLATFORM_FILE_OPEN_ALWAYS = 4, // May create a new file.
+ PLATFORM_FILE_CREATE_ALWAYS = 8, // May overwrite an old file.
+ PLATFORM_FILE_READ = 16,
+ PLATFORM_FILE_WRITE = 32,
+ PLATFORM_FILE_EXCLUSIVE_READ = 64, // EXCLUSIVE is opposite of Windows SHARE
+ PLATFORM_FILE_EXCLUSIVE_WRITE = 128,
+ PLATFORM_FILE_ASYNC = 256
+};
+
+// Creates or open 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 std::wstring& name,
+ int flags,
+ bool* created);
+
+} // namespace base
+
+#endif // BASE_PLATFORM_FILE_H_
diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc
new file mode 100644
index 0000000..6aa7aa1
--- /dev/null
+++ b/base/platform_file_posix.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/platform_file.h"
+
+#include <fcntl.h>
+#include <errno.h>
+
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace base {
+
+// TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here?
+PlatformFile CreatePlatformFile(const std::wstring& name,
+ int flags,
+ bool* created) {
+ int open_flags = 0;
+ if (flags & PLATFORM_FILE_CREATE)
+ open_flags = O_CREAT | O_EXCL;
+
+ if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
+ DCHECK(!open_flags);
+ open_flags = O_CREAT | O_TRUNC;
+ }
+
+ if (!open_flags && !(flags & PLATFORM_FILE_OPEN) &&
+ !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
+ NOTREACHED();
+ errno = ENOTSUP;
+ return INVALID_HANDLE_VALUE;
+ }
+
+ if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) {
+ open_flags |= O_RDWR;
+ } else if (flags & PLATFORM_FILE_WRITE) {
+ open_flags |= O_WRONLY;
+ } else if (!(flags & PLATFORM_FILE_READ)) {
+ NOTREACHED();
+ }
+
+ DCHECK(O_RDONLY == 0);
+
+ int descriptor = open(WideToUTF8(name).c_str(), open_flags,
+ S_IRUSR | S_IWUSR);
+
+ if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
+ if (descriptor > 0) {
+ if (created)
+ *created = false;
+ } else {
+ open_flags |= O_CREAT;
+ descriptor = open(WideToUTF8(name).c_str(), open_flags,
+ S_IRUSR | S_IWUSR);
+ if (created && descriptor > 0)
+ *created = true;
+ }
+ }
+
+ return descriptor;
+}
+
+} // namespace base
diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc
new file mode 100644
index 0000000..987085d
--- /dev/null
+++ b/base/platform_file_win.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/platform_file.h"
+
+#include "base/logging.h"
+
+namespace base {
+
+PlatformFile CreatePlatformFile(const std::wstring& name,
+ int flags,
+ bool* created) {
+ DWORD disposition = 0;
+
+ if (flags & PLATFORM_FILE_OPEN)
+ disposition = OPEN_EXISTING;
+
+ if (flags & PLATFORM_FILE_CREATE) {
+ DCHECK(!disposition);
+ disposition = CREATE_NEW;
+ }
+
+ if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
+ DCHECK(!disposition);
+ disposition = OPEN_ALWAYS;
+ }
+
+ if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
+ DCHECK(!disposition);
+ disposition = CREATE_ALWAYS;
+ }
+
+ if (!disposition) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ DWORD access = (flags & PLATFORM_FILE_READ) ? GENERIC_READ : 0;
+ if (flags & PLATFORM_FILE_WRITE)
+ access |= GENERIC_WRITE;
+
+ DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ;
+ if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE))
+ sharing |= FILE_SHARE_WRITE;
+
+ DWORD create_flags = 0;
+ if (flags & PLATFORM_FILE_ASYNC)
+ create_flags |= FILE_FLAG_OVERLAPPED;
+
+ HANDLE file = CreateFile(name.c_str(), access, sharing, NULL, disposition,
+ create_flags, NULL);
+
+ if ((flags & PLATFORM_FILE_OPEN_ALWAYS) && created &&
+ INVALID_HANDLE_VALUE != file) {
+ *created = (ERROR_ALREADY_EXISTS != GetLastError());
+ }
+
+ return file;
+}
+
+} // namespace disk_cache
+