| 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 "webkit/glue/webfileutilities_impl.h" | 5 #include "webkit/glue/webfileutilities_impl.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return; | 109 return; |
| 110 if (base::ClosePlatformFile(handle)) | 110 if (base::ClosePlatformFile(handle)) |
| 111 handle = base::kInvalidPlatformFileValue; | 111 handle = base::kInvalidPlatformFileValue; |
| 112 } | 112 } |
| 113 | 113 |
| 114 long long WebFileUtilitiesImpl::seekFile(base::PlatformFile handle, | 114 long long WebFileUtilitiesImpl::seekFile(base::PlatformFile handle, |
| 115 long long offset, | 115 long long offset, |
| 116 int origin) { | 116 int origin) { |
| 117 if (handle == base::kInvalidPlatformFileValue) | 117 if (handle == base::kInvalidPlatformFileValue) |
| 118 return -1; | 118 return -1; |
| 119 net::FileStream file_stream(handle, 0, NULL); | 119 return base::SeekPlatformFile(handle, |
| 120 return file_stream.SeekSync(static_cast<net::Whence>(origin), offset); | 120 static_cast<base::PlatformFileWhence>(origin), |
| 121 offset); |
| 121 } | 122 } |
| 122 | 123 |
| 123 bool WebFileUtilitiesImpl::truncateFile(base::PlatformFile handle, | 124 bool WebFileUtilitiesImpl::truncateFile(base::PlatformFile handle, |
| 124 long long offset) { | 125 long long offset) { |
| 125 if (handle == base::kInvalidPlatformFileValue || offset < 0) | 126 if (handle == base::kInvalidPlatformFileValue || offset < 0) |
| 126 return false; | 127 return false; |
| 127 net::FileStream file_stream(handle, base::PLATFORM_FILE_WRITE, NULL); | 128 return base::TruncatePlatformFile(handle, offset); |
| 128 return file_stream.Truncate(offset) >= 0; | |
| 129 } | 129 } |
| 130 | 130 |
| 131 int WebFileUtilitiesImpl::readFromFile(base::PlatformFile handle, | 131 int WebFileUtilitiesImpl::readFromFile(base::PlatformFile handle, |
| 132 char* data, | 132 char* data, |
| 133 int length) { | 133 int length) { |
| 134 if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) | 134 if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) |
| 135 return -1; | 135 return -1; |
| 136 std::string buffer; | 136 return base::ReadPlatformFileCurPosNoBestEffort(handle, data, length); |
| 137 buffer.resize(length); | |
| 138 net::FileStream file_stream(handle, base::PLATFORM_FILE_READ, NULL); | |
| 139 return file_stream.ReadSync(data, length); | |
| 140 } | 137 } |
| 141 | 138 |
| 142 int WebFileUtilitiesImpl::writeToFile(base::PlatformFile handle, | 139 int WebFileUtilitiesImpl::writeToFile(base::PlatformFile handle, |
| 143 const char* data, | 140 const char* data, |
| 144 int length) { | 141 int length) { |
| 145 if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) | 142 if (handle == base::kInvalidPlatformFileValue || !data || length <= 0) |
| 146 return -1; | 143 return -1; |
| 147 net::FileStream file_stream(handle, base::PLATFORM_FILE_WRITE, NULL); | 144 return base::WritePlatformFileCurPosNoBestEffort(handle, data, length); |
| 148 return file_stream.WriteSync(data, length); | |
| 149 } | 145 } |
| 150 | 146 |
| 151 } // namespace webkit_glue | 147 } // namespace webkit_glue |
| OLD | NEW |