| OLD | NEW |
| 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 #include "base/file_util_proxy.h" | 5 #include "base/file_util_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 void Reply(const FileUtilProxy::ReadCallback& callback) { | 146 void Reply(const FileUtilProxy::ReadCallback& callback) { |
| 147 if (!callback.is_null()) { | 147 if (!callback.is_null()) { |
| 148 PlatformFileError error = | 148 PlatformFileError error = |
| 149 (bytes_read_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; | 149 (bytes_read_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; |
| 150 callback.Run(error, buffer_.get(), bytes_read_); | 150 callback.Run(error, buffer_.get(), bytes_read_); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 private: | 154 private: |
| 155 scoped_array<char> buffer_; | 155 scoped_ptr<char[]> buffer_; |
| 156 int bytes_to_read_; | 156 int bytes_to_read_; |
| 157 int bytes_read_; | 157 int bytes_read_; |
| 158 DISALLOW_COPY_AND_ASSIGN(ReadHelper); | 158 DISALLOW_COPY_AND_ASSIGN(ReadHelper); |
| 159 }; | 159 }; |
| 160 | 160 |
| 161 class WriteHelper { | 161 class WriteHelper { |
| 162 public: | 162 public: |
| 163 WriteHelper(const char* buffer, int bytes_to_write) | 163 WriteHelper(const char* buffer, int bytes_to_write) |
| 164 : buffer_(new char[bytes_to_write]), | 164 : buffer_(new char[bytes_to_write]), |
| 165 bytes_to_write_(bytes_to_write), | 165 bytes_to_write_(bytes_to_write), |
| 166 bytes_written_(0) { | 166 bytes_written_(0) { |
| 167 memcpy(buffer_.get(), buffer, bytes_to_write); | 167 memcpy(buffer_.get(), buffer, bytes_to_write); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void RunWork(PlatformFile file, int64 offset) { | 170 void RunWork(PlatformFile file, int64 offset) { |
| 171 bytes_written_ = WritePlatformFile(file, offset, buffer_.get(), | 171 bytes_written_ = WritePlatformFile(file, offset, buffer_.get(), |
| 172 bytes_to_write_); | 172 bytes_to_write_); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void Reply(const FileUtilProxy::WriteCallback& callback) { | 175 void Reply(const FileUtilProxy::WriteCallback& callback) { |
| 176 if (!callback.is_null()) { | 176 if (!callback.is_null()) { |
| 177 PlatformFileError error = | 177 PlatformFileError error = |
| 178 (bytes_written_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; | 178 (bytes_written_ < 0) ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; |
| 179 callback.Run(error, bytes_written_); | 179 callback.Run(error, bytes_written_); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 scoped_array<char> buffer_; | 184 scoped_ptr<char[]> buffer_; |
| 185 int bytes_to_write_; | 185 int bytes_to_write_; |
| 186 int bytes_written_; | 186 int bytes_written_; |
| 187 DISALLOW_COPY_AND_ASSIGN(WriteHelper); | 187 DISALLOW_COPY_AND_ASSIGN(WriteHelper); |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 | 190 |
| 191 PlatformFileError CreateOrOpenAdapter( | 191 PlatformFileError CreateOrOpenAdapter( |
| 192 const FilePath& file_path, int file_flags, | 192 const FilePath& file_path, int file_flags, |
| 193 PlatformFile* file_handle, bool* created) { | 193 PlatformFile* file_handle, bool* created) { |
| 194 DCHECK(file_handle); | 194 DCHECK(file_handle); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 bool FileUtilProxy::RelayClose( | 427 bool FileUtilProxy::RelayClose( |
| 428 TaskRunner* task_runner, | 428 TaskRunner* task_runner, |
| 429 const CloseTask& close_task, | 429 const CloseTask& close_task, |
| 430 PlatformFile file_handle, | 430 PlatformFile file_handle, |
| 431 const StatusCallback& callback) { | 431 const StatusCallback& callback) { |
| 432 return base::PostTaskAndReplyWithResult( | 432 return base::PostTaskAndReplyWithResult( |
| 433 task_runner, FROM_HERE, Bind(close_task, file_handle), callback); | 433 task_runner, FROM_HERE, Bind(close_task, file_handle), callback); |
| 434 } | 434 } |
| 435 | 435 |
| 436 } // namespace base | 436 } // namespace base |
| OLD | NEW |