| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 8 #include "net/base/file_stream.h" |
| 9 | 9 |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // calls MapSystemError() to map errno to net error codes. It tries to flush to | 98 // calls MapSystemError() to map errno to net error codes. It tries to flush to |
| 99 // completion. | 99 // completion. |
| 100 int FlushFile(base::PlatformFile file, bool record_uma) { | 100 int FlushFile(base::PlatformFile file, bool record_uma) { |
| 101 base::ThreadRestrictions::AssertIOAllowed(); | 101 base::ThreadRestrictions::AssertIOAllowed(); |
| 102 ssize_t res = HANDLE_EINTR(fsync(file)); | 102 ssize_t res = HANDLE_EINTR(fsync(file)); |
| 103 if (res == -1) | 103 if (res == -1) |
| 104 RecordAndMapError(errno, FILE_ERROR_SOURCE_FLUSH, record_uma); | 104 RecordAndMapError(errno, FILE_ERROR_SOURCE_FLUSH, record_uma); |
| 105 return res; | 105 return res; |
| 106 } | 106 } |
| 107 | 107 |
| 108 } // namespace |
| 109 |
| 108 // Cancelable wrapper around a Closure. | 110 // Cancelable wrapper around a Closure. |
| 109 class CancelableCallback { | 111 class CancelableCallback { |
| 110 public: | 112 public: |
| 111 explicit CancelableCallback(const base::Closure& callback) | 113 explicit CancelableCallback(const base::Closure& callback) |
| 112 : canceled_(false), | 114 : canceled_(false), |
| 113 callback_(callback) {} | 115 callback_(callback) {} |
| 114 | 116 |
| 115 void Run() { | 117 void Run() { |
| 116 if (!canceled_) | 118 if (!canceled_) |
| 117 callback_.Run(); | 119 callback_.Run(); |
| 118 } | 120 } |
| 119 | 121 |
| 120 void Cancel() { | 122 void Cancel() { |
| 121 canceled_ = true; | 123 canceled_ = true; |
| 122 } | 124 } |
| 123 | 125 |
| 124 private: | 126 private: |
| 125 bool canceled_; | 127 bool canceled_; |
| 126 const base::Closure callback_; | 128 const base::Closure callback_; |
| 127 }; | 129 }; |
| 128 | 130 |
| 129 } // namespace | |
| 130 | |
| 131 // FileStream::AsyncContext ---------------------------------------------- | 131 // FileStream::AsyncContext ---------------------------------------------- |
| 132 | 132 |
| 133 class FileStream::AsyncContext { | 133 class FileStream::AsyncContext { |
| 134 public: | 134 public: |
| 135 AsyncContext(); | 135 AsyncContext(); |
| 136 ~AsyncContext(); | 136 ~AsyncContext(); |
| 137 | 137 |
| 138 // These methods post synchronous read() and write() calls to a WorkerThread. | 138 // These methods post synchronous read() and write() calls to a WorkerThread. |
| 139 void InitiateAsyncRead( | 139 void InitiateAsyncRead( |
| 140 base::PlatformFile file, char* buf, int buf_len, | 140 base::PlatformFile file, char* buf, int buf_len, |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 return ERR_UNEXPECTED; | 458 return ERR_UNEXPECTED; |
| 459 | 459 |
| 460 return FlushFile(file_, record_uma_); | 460 return FlushFile(file_, record_uma_); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void FileStream::EnableErrorStatistics() { | 463 void FileStream::EnableErrorStatistics() { |
| 464 record_uma_ = true; | 464 record_uma_ = true; |
| 465 } | 465 } |
| 466 | 466 |
| 467 } // namespace net | 467 } // namespace net |
| OLD | NEW |