summaryrefslogtreecommitdiffstats
path: root/base/file_util_proxy.cc
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 01:24:51 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-05 01:24:51 +0000
commit43fad839433bfa7561f86e0f4629f5a9b2b31b3e (patch)
tree4596d8a7f4bb5e39c927d1cb8fde338779c3401f /base/file_util_proxy.cc
parent23e2619fc7d0a817dd2f44a704b23cbac97c79da (diff)
downloadchromium_src-43fad839433bfa7561f86e0f4629f5a9b2b31b3e.zip
chromium_src-43fad839433bfa7561f86e0f4629f5a9b2b31b3e.tar.gz
chromium_src-43fad839433bfa7561f86e0f4629f5a9b2b31b3e.tar.bz2
Add truncate and cancel for FileWriter; write and more tests will come in later CLs.
This CL also contains a fair amount of plumbing for the write call itself. BUG=none TEST=none Review URL: http://codereview.chromium.org/3599011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61462 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_proxy.cc')
-rw-r--r--base/file_util_proxy.cc57
1 files changed, 50 insertions, 7 deletions
diff --git a/base/file_util_proxy.cc b/base/file_util_proxy.cc
index 7f7b03a..d71f374 100644
--- a/base/file_util_proxy.cc
+++ b/base/file_util_proxy.cc
@@ -498,7 +498,7 @@ class RelayRead : public MessageLoopRelay {
class RelayWrite : public MessageLoopRelay {
public:
RelayWrite(base::PlatformFile file,
- long long offset,
+ int64 offset,
const char* buffer,
int bytes_to_write,
base::FileUtilProxy::ReadWriteCallback* callback)
@@ -582,11 +582,11 @@ class RelayTouchFilePath : public RelayWithStatusCallback {
base::Time last_modified_time_;
};
-class RelayTruncate : public RelayWithStatusCallback {
+class RelayTruncatePlatformFile : public RelayWithStatusCallback {
public:
- RelayTruncate(base::PlatformFile file,
- int64 length,
- base::FileUtilProxy::StatusCallback* callback)
+ RelayTruncatePlatformFile(base::PlatformFile file,
+ int64 length,
+ base::FileUtilProxy::StatusCallback* callback)
: RelayWithStatusCallback(callback),
file_(file),
length_(length) {
@@ -603,6 +603,39 @@ class RelayTruncate : public RelayWithStatusCallback {
int64 length_;
};
+class RelayTruncate : public RelayWithStatusCallback {
+ public:
+ RelayTruncate(const FilePath& path,
+ int64 length,
+ base::FileUtilProxy::StatusCallback* callback)
+ : RelayWithStatusCallback(callback),
+ path_(path),
+ length_(length) {
+ }
+
+ protected:
+ virtual void RunWork() {
+ base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED);
+ base::PlatformFile file =
+ base::CreatePlatformFile(
+ path_,
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE,
+ NULL,
+ &error_code);
+ if (error_code != base::PLATFORM_FILE_OK) {
+ set_error_code(error_code);
+ return;
+ }
+ if (!base::TruncatePlatformFile(file, length_))
+ set_error_code(base::PLATFORM_FILE_ERROR_FAILED);
+ base::ClosePlatformFile(file);
+ }
+
+ private:
+ FilePath path_;
+ int64 length_;
+};
+
class RelayFlush : public RelayWithStatusCallback {
public:
RelayFlush(base::PlatformFile file,
@@ -782,10 +815,20 @@ bool FileUtilProxy::Touch(
bool FileUtilProxy::Truncate(
scoped_refptr<MessageLoopProxy> message_loop_proxy,
PlatformFile file,
- long long length,
+ int64 length,
+ StatusCallback* callback) {
+ return Start(FROM_HERE, message_loop_proxy,
+ new RelayTruncatePlatformFile(file, length, callback));
+}
+
+// static
+bool FileUtilProxy::Truncate(
+ scoped_refptr<MessageLoopProxy> message_loop_proxy,
+ const FilePath& path,
+ int64 length,
StatusCallback* callback) {
return Start(FROM_HERE, message_loop_proxy,
- new RelayTruncate(file, length, callback));
+ new RelayTruncate(path, length, callback));
}
// static