diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 18:17:36 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 18:17:36 +0000 |
commit | 9560143c62a704f58ccfe83b56f2f73cf22874bb (patch) | |
tree | b17d6b21b19225afda53ba900ccea25b9a108736 /net/base | |
parent | 1dbc0fb4856b4f200fd65c6e048194f135d50958 (diff) | |
download | chromium_src-9560143c62a704f58ccfe83b56f2f73cf22874bb.zip chromium_src-9560143c62a704f58ccfe83b56f2f73cf22874bb.tar.gz chromium_src-9560143c62a704f58ccfe83b56f2f73cf22874bb.tar.bz2 |
Disk cache: First pass to add support for sparse entries.
Adding Read/Write support.
BUG=12258
TEST=unittests.
Review URL: http://codereview.chromium.org/126179
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/io_buffer.cc | 4 | ||||
-rw-r--r-- | net/base/io_buffer.h | 39 |
2 files changed, 41 insertions, 2 deletions
diff --git a/net/base/io_buffer.cc b/net/base/io_buffer.cc index c2401ab..db2bffb 100644 --- a/net/base/io_buffer.cc +++ b/net/base/io_buffer.cc @@ -12,5 +12,9 @@ IOBuffer::IOBuffer(int buffer_size) { DCHECK(buffer_size > 0); data_ = new char[buffer_size]; } +void ReusedIOBuffer::SetOffset(int offset) { + DCHECK(offset > 0 && offset < size_); + data_ = base_->data() + offset; +} } // namespace net diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h index 122e434..ac79644 100644 --- a/net/base/io_buffer.h +++ b/net/base/io_buffer.h @@ -28,15 +28,50 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { char* data_; }; +// This version stores the size of the buffer so that the creator of the object +// doesn't have to keep track of that value. +// NOTE: This doesn't mean that we want to stop sending the size as an explictit +// argument to IO functions. Please keep using IOBuffer* for API declarations. +class IOBufferWithSize : public IOBuffer { + public: + explicit IOBufferWithSize(int size) : IOBuffer(size), size_(size) {} + ~IOBufferWithSize() {} + + int size() const { return size_; } + + private: + int size_; +}; + +// This version allows the caller to do multiple IO operations reusing a given +// IOBuffer. We don't own data_, we simply make it point to the buffer of the +// passed in IOBuffer, plus the desired offset. +class ReusedIOBuffer : public IOBuffer { + public: + ReusedIOBuffer(IOBuffer* base, int size) + : IOBuffer(base->data()), base_(base), size_(size) {} + ~ReusedIOBuffer() { + // We don't really own a buffer. + data_ = NULL; + } + + int size() const { return size_; } + void SetOffset(int offset); + + private: + scoped_refptr<IOBuffer> base_; + int size_; +}; + // This class allows the creation of a temporary IOBuffer that doesn't really // own the underlying buffer. Please use this class only as a last resort. // A good example is the buffer for a synchronous operation, where we can be // sure that nobody is keeping an extra reference to this object so the lifetime // of the buffer can be completely managed by its intended owner. -class WrappedIOBuffer : public net::IOBuffer { +class WrappedIOBuffer : public IOBuffer { public: explicit WrappedIOBuffer(const char* data) - : net::IOBuffer(const_cast<char*>(data)) {} + : IOBuffer(const_cast<char*>(data)) {} ~WrappedIOBuffer() { data_ = NULL; } |