diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 18:47:25 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-23 18:47:25 +0000 |
commit | e1fcf1482fd306b7e404ed037106801840deda76 (patch) | |
tree | d5d26cf73f30a254aecca16dfba4f6f5e9bdba4c /net/disk_cache/file_posix.cc | |
parent | 8e3e066579460f88a19e2e6e091c396f3bd851c3 (diff) | |
download | chromium_src-e1fcf1482fd306b7e404ed037106801840deda76.zip chromium_src-e1fcf1482fd306b7e404ed037106801840deda76.tar.gz chromium_src-e1fcf1482fd306b7e404ed037106801840deda76.tar.bz2 |
Disk cache: Extend the internal buffering performed by each entry
to cover external files.
We now keep a variable-size buffer and use it even after we
know that the data is not going to be stored by a block-file.
The backend keeps track of the total memory used by all entries
and prevents that value from going over a max value that
depends on the total memory available.
This CL removes the tests that were checking the synchronous
operation of sparse IO because that model is no longer supported
by the public API, and this CL would add complexity to them
(they fail due to thread safety concerns).
BUG=6626
TEST=net_unittests
Review URL: http://codereview.chromium.org/3167020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/file_posix.cc')
-rw-r--r-- | net/disk_cache/file_posix.cc | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc index 295f744..1d842ed 100644 --- a/net/disk_cache/file_posix.cc +++ b/net/disk_cache/file_posix.cc @@ -37,12 +37,11 @@ class BackgroundIO : public base::RefCountedThreadSafe<BackgroundIO> { // Read and Write are the operations that can be performed asynchronously. // The actual parameters for the operation are setup in the constructor of - // the object, with the exception of |delete_buffer|, that allows a write - // without a callback. Both methods should be called from a worker thread, by - // posting a task to the WorkerPool (they are RunnableMethods). When finished, + // the object. Both methods should be called from a worker thread, by posting + // a task to the WorkerPool (they are RunnableMethods). When finished, // controller->OnIOComplete() is called. void Read(); - void Write(bool delete_buffer); + void Write(); // This method signals the controller that this operation is finished, in the // original thread (presumably the IO-Thread). In practice, this is a @@ -122,8 +121,7 @@ class InFlightIO { void PostRead(disk_cache::File* file, void* buf, size_t buf_len, size_t offset, disk_cache::FileIOCallback* callback); void PostWrite(disk_cache::File* file, const void* buf, size_t buf_len, - size_t offset, disk_cache::FileIOCallback* callback, - bool delete_buffer); + size_t offset, disk_cache::FileIOCallback* callback); // Blocks the current thread until all IO operations tracked by this object // complete. @@ -167,12 +165,8 @@ void BackgroundIO::Cancel() { } // Runs on a worker thread. -void BackgroundIO::Write(bool delete_buffer) { +void BackgroundIO::Write() { bool rv = file_->Write(buf_, buf_len_, offset_); - if (delete_buffer) { - // TODO(rvargas): remove or update this code. - delete[] reinterpret_cast<const char*>(buf_); - } bytes_ = rv ? static_cast<int>(buf_len_) : -1; controller_->OnIOComplete(this); @@ -203,8 +197,7 @@ void InFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len, void InFlightIO::PostWrite(disk_cache::File* file, const void* buf, size_t buf_len, size_t offset, - disk_cache::FileIOCallback* callback, - bool delete_buffer) { + disk_cache::FileIOCallback* callback) { scoped_refptr<BackgroundIO> operation = new BackgroundIO(file, buf, buf_len, offset, callback, this); io_list_.insert(operation.get()); @@ -214,8 +207,7 @@ void InFlightIO::PostWrite(disk_cache::File* file, const void* buf, callback_thread_ = MessageLoop::current(); WorkerPool::PostTask(FROM_HERE, - NewRunnableMethod(operation.get(), &BackgroundIO::Write, - delete_buffer), + NewRunnableMethod(operation.get(), &BackgroundIO::Write), true); } @@ -342,22 +334,17 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset, return Write(buffer, buffer_len, offset); } - return AsyncWrite(buffer, buffer_len, offset, true, callback, completed); -} - -bool File::PostWrite(const void* buffer, size_t buffer_len, size_t offset) { - DCHECK(init_); - return AsyncWrite(buffer, buffer_len, offset, false, NULL, NULL); + return AsyncWrite(buffer, buffer_len, offset, callback, completed); } bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset, - bool notify, FileIOCallback* callback, bool* completed) { + FileIOCallback* callback, bool* completed) { DCHECK(init_); if (buffer_len > ULONG_MAX || offset > ULONG_MAX) return false; InFlightIO* io_operations = Singleton<InFlightIO>::get(); - io_operations->PostWrite(this, buffer, buffer_len, offset, callback, !notify); + io_operations->PostWrite(this, buffer, buffer_len, offset, callback); if (completed) *completed = false; |