OLD | NEW |
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/mem_entry_impl.h" | 5 #include "net/disk_cache/mem_entry_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/disk_cache/mem_backend_impl.h" | 10 #include "net/disk_cache/mem_backend_impl.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 net::CompletionCallback* completion_callback) { | 165 net::CompletionCallback* completion_callback) { |
166 DCHECK(type() == kParentEntry); | 166 DCHECK(type() == kParentEntry); |
167 | 167 |
168 if (!InitSparseInfo()) | 168 if (!InitSparseInfo()) |
169 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 169 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
170 | 170 |
171 if (offset < 0 || buf_len < 0) | 171 if (offset < 0 || buf_len < 0) |
172 return net::ERR_INVALID_ARGUMENT; | 172 return net::ERR_INVALID_ARGUMENT; |
173 | 173 |
174 // We will keep using this buffer and adjust the offset in this buffer. | 174 // We will keep using this buffer and adjust the offset in this buffer. |
175 scoped_refptr<net::DrainableIOBuffer> io_buf = | 175 scoped_refptr<net::DrainableIOBuffer> io_buf( |
176 new net::DrainableIOBuffer(buf, buf_len); | 176 new net::DrainableIOBuffer(buf, buf_len)); |
177 | 177 |
178 // Iterate until we have read enough. | 178 // Iterate until we have read enough. |
179 while (io_buf->BytesRemaining()) { | 179 while (io_buf->BytesRemaining()) { |
180 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), false); | 180 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), false); |
181 | 181 |
182 // No child present for that offset. | 182 // No child present for that offset. |
183 if (!child) | 183 if (!child) |
184 break; | 184 break; |
185 | 185 |
186 // We then need to prepare the child offset and len. | 186 // We then need to prepare the child offset and len. |
(...skipping 24 matching lines...) Expand all Loading... |
211 int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, | 211 int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
212 net::CompletionCallback* completion_callback) { | 212 net::CompletionCallback* completion_callback) { |
213 DCHECK(type() == kParentEntry); | 213 DCHECK(type() == kParentEntry); |
214 | 214 |
215 if (!InitSparseInfo()) | 215 if (!InitSparseInfo()) |
216 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 216 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
217 | 217 |
218 if (offset < 0 || buf_len < 0) | 218 if (offset < 0 || buf_len < 0) |
219 return net::ERR_INVALID_ARGUMENT; | 219 return net::ERR_INVALID_ARGUMENT; |
220 | 220 |
221 scoped_refptr<net::DrainableIOBuffer> io_buf = | 221 scoped_refptr<net::DrainableIOBuffer> io_buf( |
222 new net::DrainableIOBuffer(buf, buf_len); | 222 new net::DrainableIOBuffer(buf, buf_len)); |
223 | 223 |
224 // This loop walks through child entries continuously starting from |offset| | 224 // This loop walks through child entries continuously starting from |offset| |
225 // and writes blocks of data (of maximum size kMaxSparseEntrySize) into each | 225 // and writes blocks of data (of maximum size kMaxSparseEntrySize) into each |
226 // child entry until all |buf_len| bytes are written. The write operation can | 226 // child entry until all |buf_len| bytes are written. The write operation can |
227 // start in the middle of an entry. | 227 // start in the middle of an entry. |
228 while (io_buf->BytesRemaining()) { | 228 while (io_buf->BytesRemaining()) { |
229 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), true); | 229 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), true); |
230 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); | 230 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); |
231 | 231 |
232 // Find the right amount to write, this evaluates the remaining bytes to | 232 // Find the right amount to write, this evaluates the remaining bytes to |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 scanned_len += kMaxSparseEntrySize - current_child_offset; | 485 scanned_len += kMaxSparseEntrySize - current_child_offset; |
486 } | 486 } |
487 return scanned_len; | 487 return scanned_len; |
488 } | 488 } |
489 | 489 |
490 void MemEntryImpl::DetachChild(int child_id) { | 490 void MemEntryImpl::DetachChild(int child_id) { |
491 children_->erase(child_id); | 491 children_->erase(child_id); |
492 } | 492 } |
493 | 493 |
494 } // namespace disk_cache | 494 } // namespace disk_cache |
OLD | NEW |