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