Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2367)

Side by Side Diff: net/disk_cache/file_posix.cc

Issue 6339012: More net/ method ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More done while waiting for previous patch to clear Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/mapped_file_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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 "net/disk_cache/file.h" 5 #include "net/disk_cache/file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/worker_pool.h" 10 #include "base/threading/worker_pool.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 platform_file_ = base::CreatePlatformFile(name, flags, NULL, NULL); 182 platform_file_ = base::CreatePlatformFile(name, flags, NULL, NULL);
183 if (platform_file_ < 0) { 183 if (platform_file_ < 0) {
184 platform_file_ = 0; 184 platform_file_ = 0;
185 return false; 185 return false;
186 } 186 }
187 187
188 init_ = true; 188 init_ = true;
189 return true; 189 return true;
190 } 190 }
191 191
192 File::~File() {
193 if (platform_file_)
194 close(platform_file_);
195 }
196
197 base::PlatformFile File::platform_file() const { 192 base::PlatformFile File::platform_file() const {
198 return platform_file_; 193 return platform_file_;
199 } 194 }
200 195
201 bool File::IsValid() const { 196 bool File::IsValid() const {
202 if (!init_) 197 if (!init_)
203 return false; 198 return false;
204 return (base::kInvalidPlatformFileValue != platform_file_); 199 return (base::kInvalidPlatformFileValue != platform_file_);
205 } 200 }
206 201
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 DCHECK(init_); 243 DCHECK(init_);
249 if (!callback) { 244 if (!callback) {
250 if (completed) 245 if (completed)
251 *completed = true; 246 *completed = true;
252 return Write(buffer, buffer_len, offset); 247 return Write(buffer, buffer_len, offset);
253 } 248 }
254 249
255 return AsyncWrite(buffer, buffer_len, offset, callback, completed); 250 return AsyncWrite(buffer, buffer_len, offset, callback, completed);
256 } 251 }
257 252
258 bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
259 FileIOCallback* callback, bool* completed) {
260 DCHECK(init_);
261 if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
262 return false;
263
264 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback);
265
266 if (completed)
267 *completed = false;
268 return true;
269 }
270
271 bool File::SetLength(size_t length) { 253 bool File::SetLength(size_t length) {
272 DCHECK(init_); 254 DCHECK(init_);
273 if (length > ULONG_MAX) 255 if (length > ULONG_MAX)
274 return false; 256 return false;
275 257
276 return 0 == ftruncate(platform_file_, length); 258 return 0 == ftruncate(platform_file_, length);
277 } 259 }
278 260
279 size_t File::GetLength() { 261 size_t File::GetLength() {
280 DCHECK(init_); 262 DCHECK(init_);
281 size_t ret = lseek(platform_file_, 0, SEEK_END); 263 size_t ret = lseek(platform_file_, 0, SEEK_END);
282 return ret; 264 return ret;
283 } 265 }
284 266
285 // Static. 267 // Static.
286 void File::WaitForPendingIO(int* num_pending_io) { 268 void File::WaitForPendingIO(int* num_pending_io) {
287 // We may be running unit tests so we should allow be able to reset the 269 // We may be running unit tests so we should allow be able to reset the
288 // message loop. 270 // message loop.
289 GetFileInFlightIO()->WaitForPendingIO(); 271 GetFileInFlightIO()->WaitForPendingIO();
290 DeleteFileInFlightIO(); 272 DeleteFileInFlightIO();
291 } 273 }
292 274
275 File::~File() {
276 if (platform_file_)
277 close(platform_file_);
278 }
279
280 bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
281 FileIOCallback* callback, bool* completed) {
282 DCHECK(init_);
283 if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
284 return false;
285
286 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback);
287
288 if (completed)
289 *completed = false;
290 return true;
291 }
292
293 } // namespace disk_cache 293 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/mapped_file_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698