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

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

Issue 9702059: Disk cache: Remove all non essential synchronization from the cache destructor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2011 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 "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/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // --------------------------------------------------------------------------- 91 // ---------------------------------------------------------------------------
92 92
93 // Runs on a worker thread. 93 // Runs on a worker thread.
94 void FileBackgroundIO::Read() { 94 void FileBackgroundIO::Read() {
95 if (file_->Read(const_cast<void*>(buf_), buf_len_, offset_)) { 95 if (file_->Read(const_cast<void*>(buf_), buf_len_, offset_)) {
96 result_ = static_cast<int>(buf_len_); 96 result_ = static_cast<int>(buf_len_);
97 } else { 97 } else {
98 result_ = net::ERR_CACHE_READ_FAILURE; 98 result_ = net::ERR_CACHE_READ_FAILURE;
99 } 99 }
100 controller_->OnIOComplete(this); 100 NotifyController();
101 } 101 }
102 102
103 // Runs on a worker thread. 103 // Runs on a worker thread.
104 void FileBackgroundIO::Write() { 104 void FileBackgroundIO::Write() {
105 bool rv = file_->Write(buf_, buf_len_, offset_); 105 bool rv = file_->Write(buf_, buf_len_, offset_);
106 106
107 result_ = rv ? static_cast<int>(buf_len_) : net::ERR_CACHE_WRITE_FAILURE; 107 result_ = rv ? static_cast<int>(buf_len_) : net::ERR_CACHE_WRITE_FAILURE;
108 controller_->OnIOComplete(this); 108 NotifyController();
109 } 109 }
110 110
111 // --------------------------------------------------------------------------- 111 // ---------------------------------------------------------------------------
112 112
113 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, 113 void FileInFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len,
114 size_t offset, disk_cache::FileIOCallback *callback) { 114 size_t offset, disk_cache::FileIOCallback *callback) {
115 scoped_refptr<FileBackgroundIO> operation( 115 scoped_refptr<FileBackgroundIO> operation(
116 new FileBackgroundIO(file, buf, buf_len, offset, callback, this)); 116 new FileBackgroundIO(file, buf, buf_len, offset, callback, this));
117 file->AddRef(); // Balanced on OnOperationComplete() 117 file->AddRef(); // Balanced on OnOperationComplete()
118 118
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 275 }
276 276
277 // Static. 277 // Static.
278 void File::WaitForPendingIO(int* num_pending_io) { 278 void File::WaitForPendingIO(int* num_pending_io) {
279 // We may be running unit tests so we should allow be able to reset the 279 // We may be running unit tests so we should allow be able to reset the
280 // message loop. 280 // message loop.
281 GetFileInFlightIO()->WaitForPendingIO(); 281 GetFileInFlightIO()->WaitForPendingIO();
282 DeleteFileInFlightIO(); 282 DeleteFileInFlightIO();
283 } 283 }
284 284
285 // Static.
286 void File::DropPendingIO() {
287 GetFileInFlightIO()->DropPendingIO();
288 DeleteFileInFlightIO();
289 }
290
285 File::~File() { 291 File::~File() {
286 if (IsValid()) 292 if (IsValid())
287 base::ClosePlatformFile(platform_file_); 293 base::ClosePlatformFile(platform_file_);
288 } 294 }
289 295
290 bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset, 296 bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
291 FileIOCallback* callback, bool* completed) { 297 FileIOCallback* callback, bool* completed) {
292 DCHECK(init_); 298 DCHECK(init_);
293 if (buffer_len > ULONG_MAX || offset > ULONG_MAX) 299 if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
294 return false; 300 return false;
295 301
296 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback); 302 GetFileInFlightIO()->PostWrite(this, buffer, buffer_len, offset, callback);
297 303
298 if (completed) 304 if (completed)
299 *completed = false; 305 *completed = false;
300 return true; 306 return true;
301 } 307 }
302 308
303 } // namespace disk_cache 309 } // namespace disk_cache
OLDNEW
« net/disk_cache/file.h ('K') | « net/disk_cache/file.h ('k') | net/disk_cache/file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698