| 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 // For 64-bit file access (off_t = off64_t, lseek64, etc). | 5 // For 64-bit file access (off_t = off64_t, lseek64, etc). |
| 6 #define _FILE_OFFSET_BITS 64 | 6 #define _FILE_OFFSET_BITS 64 |
| 7 | 7 |
| 8 #include "net/base/file_stream_context.h" | 8 #include "net/base/file_stream_context.h" |
| 9 | 9 |
| 10 #include <errno.h> | 10 #include <errno.h> |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return static_cast<int64>(info.st_size); | 77 return static_cast<int64>(info.st_size); |
| 78 } | 78 } |
| 79 | 79 |
| 80 int FileStream::Context::ReadAsync(IOBuffer* in_buf, | 80 int FileStream::Context::ReadAsync(IOBuffer* in_buf, |
| 81 int buf_len, | 81 int buf_len, |
| 82 const CompletionCallback& callback) { | 82 const CompletionCallback& callback) { |
| 83 DCHECK(!async_in_progress_); | 83 DCHECK(!async_in_progress_); |
| 84 | 84 |
| 85 scoped_refptr<IOBuffer> buf = in_buf; | 85 scoped_refptr<IOBuffer> buf = in_buf; |
| 86 const bool posted = base::PostTaskAndReplyWithResult( | 86 const bool posted = base::PostTaskAndReplyWithResult( |
| 87 base::WorkerPool::GetTaskRunner(true /* task is slow */), | 87 base::WorkerPool::GetTaskRunner(true /* task is slow */).get(), |
| 88 FROM_HERE, | 88 FROM_HERE, |
| 89 base::Bind(&Context::ReadFileImpl, | 89 base::Bind(&Context::ReadFileImpl, base::Unretained(this), buf, buf_len), |
| 90 base::Unretained(this), buf, buf_len), | |
| 91 base::Bind(&Context::ProcessAsyncResult, | 90 base::Bind(&Context::ProcessAsyncResult, |
| 92 base::Unretained(this), IntToInt64(callback), | 91 base::Unretained(this), |
| 92 IntToInt64(callback), |
| 93 FILE_ERROR_SOURCE_READ)); | 93 FILE_ERROR_SOURCE_READ)); |
| 94 DCHECK(posted); | 94 DCHECK(posted); |
| 95 | 95 |
| 96 async_in_progress_ = true; | 96 async_in_progress_ = true; |
| 97 return ERR_IO_PENDING; | 97 return ERR_IO_PENDING; |
| 98 } | 98 } |
| 99 | 99 |
| 100 int FileStream::Context::ReadSync(char* in_buf, int buf_len) { | 100 int FileStream::Context::ReadSync(char* in_buf, int buf_len) { |
| 101 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); | 101 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); |
| 102 IOResult result = ReadFileImpl(buf, buf_len); | 102 IOResult result = ReadFileImpl(buf, buf_len); |
| 103 RecordError(result, FILE_ERROR_SOURCE_READ); | 103 RecordError(result, FILE_ERROR_SOURCE_READ); |
| 104 return result.result; | 104 return result.result; |
| 105 } | 105 } |
| 106 | 106 |
| 107 int FileStream::Context::WriteAsync(IOBuffer* in_buf, | 107 int FileStream::Context::WriteAsync(IOBuffer* in_buf, |
| 108 int buf_len, | 108 int buf_len, |
| 109 const CompletionCallback& callback) { | 109 const CompletionCallback& callback) { |
| 110 DCHECK(!async_in_progress_); | 110 DCHECK(!async_in_progress_); |
| 111 | 111 |
| 112 scoped_refptr<IOBuffer> buf = in_buf; | 112 scoped_refptr<IOBuffer> buf = in_buf; |
| 113 const bool posted = base::PostTaskAndReplyWithResult( | 113 const bool posted = base::PostTaskAndReplyWithResult( |
| 114 base::WorkerPool::GetTaskRunner(true /* task is slow */), | 114 base::WorkerPool::GetTaskRunner(true /* task is slow */).get(), |
| 115 FROM_HERE, | 115 FROM_HERE, |
| 116 base::Bind(&Context::WriteFileImpl, | 116 base::Bind(&Context::WriteFileImpl, base::Unretained(this), buf, buf_len), |
| 117 base::Unretained(this), buf, buf_len), | |
| 118 base::Bind(&Context::ProcessAsyncResult, | 117 base::Bind(&Context::ProcessAsyncResult, |
| 119 base::Unretained(this), IntToInt64(callback), | 118 base::Unretained(this), |
| 119 IntToInt64(callback), |
| 120 FILE_ERROR_SOURCE_WRITE)); | 120 FILE_ERROR_SOURCE_WRITE)); |
| 121 DCHECK(posted); | 121 DCHECK(posted); |
| 122 | 122 |
| 123 async_in_progress_ = true; | 123 async_in_progress_ = true; |
| 124 return ERR_IO_PENDING; | 124 return ERR_IO_PENDING; |
| 125 } | 125 } |
| 126 | 126 |
| 127 int FileStream::Context::WriteSync(const char* in_buf, int buf_len) { | 127 int FileStream::Context::WriteSync(const char* in_buf, int buf_len) { |
| 128 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); | 128 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); |
| 129 IOResult result = WriteFileImpl(buf, buf_len); | 129 IOResult result = WriteFileImpl(buf, buf_len); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 scoped_refptr<IOBuffer> buf, | 175 scoped_refptr<IOBuffer> buf, |
| 176 int buf_len) { | 176 int buf_len) { |
| 177 ssize_t res = HANDLE_EINTR(write(file_, buf->data(), buf_len)); | 177 ssize_t res = HANDLE_EINTR(write(file_, buf->data(), buf_len)); |
| 178 if (res == -1) | 178 if (res == -1) |
| 179 return IOResult::FromOSError(errno); | 179 return IOResult::FromOSError(errno); |
| 180 | 180 |
| 181 return IOResult(res, 0); | 181 return IOResult(res, 0); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace net | 184 } // namespace net |
| OLD | NEW |