Chromium Code Reviews| 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" |
| 11 #include "net/disk_cache/net_log_parameters.h" | |
| 11 | 12 |
| 12 using base::Time; | 13 using base::Time; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const int kSparseData = 1; | 17 const int kSparseData = 1; |
| 17 | 18 |
| 18 // Maximum size of a sparse entry is 2 to the power of this number. | 19 // Maximum size of a sparse entry is 2 to the power of this number. |
| 19 const int kMaxSparseEntryBits = 12; | 20 const int kMaxSparseEntryBits = 12; |
| 20 | 21 |
| 21 // Sparse entry has maximum size of 4KB. | 22 // Sparse entry has maximum size of 4KB. |
| 22 const int kMaxSparseEntrySize = 1 << kMaxSparseEntryBits; | 23 const int kMaxSparseEntrySize = 1 << kMaxSparseEntryBits; |
| 23 | 24 |
| 24 // Convert global offset to child index. | 25 // Convert global offset to child index. |
| 25 inline int ToChildIndex(int64 offset) { | 26 inline int ToChildIndex(int64 offset) { |
| 26 return static_cast<int>(offset >> kMaxSparseEntryBits); | 27 return static_cast<int>(offset >> kMaxSparseEntryBits); |
| 27 } | 28 } |
| 28 | 29 |
| 29 // Convert global offset to offset in child entry. | 30 // Convert global offset to offset in child entry. |
| 30 inline int ToChildOffset(int64 offset) { | 31 inline int ToChildOffset(int64 offset) { |
| 31 return static_cast<int>(offset & (kMaxSparseEntrySize - 1)); | 32 return static_cast<int>(offset & (kMaxSparseEntrySize - 1)); |
| 32 } | 33 } |
| 33 | 34 |
| 34 } // nemespace | 35 } // namespace |
| 35 | 36 |
| 36 namespace disk_cache { | 37 namespace disk_cache { |
| 37 | 38 |
| 38 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { | 39 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { |
| 39 doomed_ = false; | 40 doomed_ = false; |
| 40 backend_ = backend; | 41 backend_ = backend; |
| 41 ref_count_ = 0; | 42 ref_count_ = 0; |
| 42 parent_ = NULL; | 43 parent_ = NULL; |
| 43 child_id_ = 0; | 44 child_id_ = 0; |
| 44 child_first_pos_ = 0; | 45 child_first_pos_ = 0; |
| 45 next_ = NULL; | 46 next_ = NULL; |
| 46 prev_ = NULL; | 47 prev_ = NULL; |
| 47 for (int i = 0; i < NUM_STREAMS; i++) | 48 for (int i = 0; i < NUM_STREAMS; i++) |
| 48 data_size_[i] = 0; | 49 data_size_[i] = 0; |
| 49 } | 50 } |
| 50 | 51 |
| 51 // ------------------------------------------------------------------------ | 52 // ------------------------------------------------------------------------ |
| 52 | 53 |
| 53 bool MemEntryImpl::CreateEntry(const std::string& key) { | 54 bool MemEntryImpl::CreateEntry(const std::string& key, net::NetLog* net_log) { |
| 55 net_log_ = net::BoundNetLog::Make(net_log, | |
| 56 net::NetLog::SOURCE_MEMORY_CACHE_ENTRY); | |
| 57 net_log_.BeginEvent( | |
| 58 net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, | |
|
rvargas (doing something else)
2011/03/04 21:39:16
nit: indent four spaces
mmenke
2011/03/07 17:46:41
Done.
| |
| 59 make_scoped_refptr(new EntryCreationParameters(key, true))); | |
| 54 key_ = key; | 60 key_ = key; |
| 55 Time current = Time::Now(); | 61 Time current = Time::Now(); |
| 56 last_modified_ = current; | 62 last_modified_ = current; |
| 57 last_used_ = current; | 63 last_used_ = current; |
| 58 Open(); | 64 Open(); |
| 59 backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); | 65 backend_->ModifyStorageSize(0, static_cast<int32>(key.size())); |
| 60 return true; | 66 return true; |
| 61 } | 67 } |
| 62 | 68 |
| 63 void MemEntryImpl::InternalDoom() { | 69 void MemEntryImpl::InternalDoom() { |
| 70 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); | |
| 64 doomed_ = true; | 71 doomed_ = true; |
| 65 if (!ref_count_) { | 72 if (!ref_count_) { |
| 66 if (type() == kParentEntry) { | 73 if (type() == kParentEntry) { |
| 67 // If this is a parent entry, we need to doom all the child entries. | 74 // If this is a parent entry, we need to doom all the child entries. |
| 68 if (children_.get()) { | 75 if (children_.get()) { |
| 69 EntryMap children; | 76 EntryMap children; |
| 70 children.swap(*children_); | 77 children.swap(*children_); |
| 71 for (EntryMap::iterator i = children.begin(); | 78 for (EntryMap::iterator i = children.begin(); |
| 72 i != children.end(); ++i) { | 79 i != children.end(); ++i) { |
| 73 // Since a pointer to this object is also saved in the map, avoid | 80 // Since a pointer to this object is also saved in the map, avoid |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 } | 152 } |
| 146 | 153 |
| 147 int32 MemEntryImpl::GetDataSize(int index) const { | 154 int32 MemEntryImpl::GetDataSize(int index) const { |
| 148 if (index < 0 || index >= NUM_STREAMS) | 155 if (index < 0 || index >= NUM_STREAMS) |
| 149 return 0; | 156 return 0; |
| 150 return data_size_[index]; | 157 return data_size_[index]; |
| 151 } | 158 } |
| 152 | 159 |
| 153 int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, | 160 int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, |
| 154 int buf_len, net::CompletionCallback* completion_callback) { | 161 int buf_len, net::CompletionCallback* completion_callback) { |
| 162 if (net_log_.IsLoggingAllEvents()) { | |
| 163 net_log_.BeginEvent( | |
| 164 net::NetLog::TYPE_ENTRY_READ_DATA, | |
| 165 make_scoped_refptr( | |
| 166 new ReadWriteDataParameters(index, offset, buf_len, false))); | |
| 167 } | |
| 168 | |
| 169 int result = InternalReadData(index, offset, buf, buf_len); | |
| 170 | |
| 171 if (net_log_.IsLoggingAllEvents()) { | |
| 172 net_log_.EndEvent( | |
| 173 net::NetLog::TYPE_ENTRY_READ_DATA, | |
| 174 make_scoped_refptr(new ReadWriteCompleteParameters(result))); | |
| 175 } | |
| 176 return result; | |
| 177 } | |
| 178 | |
| 179 int MemEntryImpl::InternalReadData(int index, int offset, net::IOBuffer* buf, | |
|
rvargas (doing something else)
2011/03/04 21:39:16
I appreciate this being here for the review, but i
mmenke
2011/03/07 17:46:41
Once Eric's had a chance to review, I'll move them
| |
| 180 int buf_len) { | |
| 155 DCHECK(type() == kParentEntry || index == kSparseData); | 181 DCHECK(type() == kParentEntry || index == kSparseData); |
| 156 | 182 |
| 157 if (index < 0 || index >= NUM_STREAMS) | 183 if (index < 0 || index >= NUM_STREAMS) |
| 158 return net::ERR_INVALID_ARGUMENT; | 184 return net::ERR_INVALID_ARGUMENT; |
| 159 | 185 |
| 160 int entry_size = GetDataSize(index); | 186 int entry_size = GetDataSize(index); |
| 161 if (offset >= entry_size || offset < 0 || !buf_len) | 187 if (offset >= entry_size || offset < 0 || !buf_len) |
| 162 return 0; | 188 return 0; |
| 163 | 189 |
| 164 if (buf_len < 0) | 190 if (buf_len < 0) |
| 165 return net::ERR_INVALID_ARGUMENT; | 191 return net::ERR_INVALID_ARGUMENT; |
| 166 | 192 |
| 167 if (offset + buf_len > entry_size) | 193 if (offset + buf_len > entry_size) |
| 168 buf_len = entry_size - offset; | 194 buf_len = entry_size - offset; |
| 169 | 195 |
| 170 UpdateRank(false); | 196 UpdateRank(false); |
| 171 | 197 |
| 172 memcpy(buf->data() , &(data_[index])[offset], buf_len); | 198 memcpy(buf->data(), &(data_[index])[offset], buf_len); |
| 173 return buf_len; | 199 return buf_len; |
| 174 } | 200 } |
| 175 | 201 |
| 176 int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, | 202 int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, |
| 177 int buf_len, net::CompletionCallback* completion_callback, bool truncate) { | 203 int buf_len, net::CompletionCallback* completion_callback, bool truncate) { |
| 204 if (net_log_.IsLoggingAllEvents()) { | |
| 205 net_log_.BeginEvent( | |
| 206 net::NetLog::TYPE_ENTRY_WRITE_DATA, | |
| 207 make_scoped_refptr( | |
| 208 new ReadWriteDataParameters(index, offset, buf_len, truncate))); | |
| 209 } | |
| 210 | |
| 211 int result = InternalWriteData(index, offset, buf, buf_len, truncate); | |
| 212 | |
| 213 if (net_log_.IsLoggingAllEvents()) { | |
| 214 net_log_.EndEvent( | |
| 215 net::NetLog::TYPE_ENTRY_WRITE_DATA, | |
| 216 make_scoped_refptr(new ReadWriteCompleteParameters(result))); | |
| 217 } | |
| 218 return result; | |
| 219 } | |
| 220 | |
| 221 int MemEntryImpl::InternalWriteData(int index, int offset, net::IOBuffer* buf, | |
| 222 int buf_len, bool truncate) { | |
|
rvargas (doing something else)
2011/03/04 21:39:16
nit: could you indent these under index.
mmenke
2011/03/07 17:46:41
Done.
| |
| 178 DCHECK(type() == kParentEntry || index == kSparseData); | 223 DCHECK(type() == kParentEntry || index == kSparseData); |
| 179 | 224 |
| 180 if (index < 0 || index >= NUM_STREAMS) | 225 if (index < 0 || index >= NUM_STREAMS) |
| 181 return net::ERR_INVALID_ARGUMENT; | 226 return net::ERR_INVALID_ARGUMENT; |
| 182 | 227 |
| 183 if (offset < 0 || buf_len < 0) | 228 if (offset < 0 || buf_len < 0) |
| 184 return net::ERR_INVALID_ARGUMENT; | 229 return net::ERR_INVALID_ARGUMENT; |
| 185 | 230 |
| 186 int max_file_size = backend_->MaxFileSize(); | 231 int max_file_size = backend_->MaxFileSize(); |
| 187 | 232 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 210 | 255 |
| 211 if (!buf_len) | 256 if (!buf_len) |
| 212 return 0; | 257 return 0; |
| 213 | 258 |
| 214 memcpy(&(data_[index])[offset], buf->data(), buf_len); | 259 memcpy(&(data_[index])[offset], buf->data(), buf_len); |
| 215 return buf_len; | 260 return buf_len; |
| 216 } | 261 } |
| 217 | 262 |
| 218 int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, | 263 int MemEntryImpl::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
| 219 net::CompletionCallback* completion_callback) { | 264 net::CompletionCallback* completion_callback) { |
| 265 if (net_log_.IsLoggingAllEvents()) { | |
| 266 net_log_.BeginEvent( | |
| 267 net::NetLog::TYPE_SPARSE_READ, | |
| 268 make_scoped_refptr( | |
| 269 new SparseOperationParameters(offset, buf_len))); | |
| 270 } | |
| 271 int result = InternalReadSparseData(offset, buf, buf_len); | |
| 272 if (net_log_.IsLoggingAllEvents()) | |
| 273 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_READ, NULL); | |
| 274 return result; | |
| 275 } | |
| 276 | |
| 277 int MemEntryImpl::InternalReadSparseData( | |
| 278 int64 offset, net::IOBuffer* buf, int buf_len) { | |
| 220 DCHECK(type() == kParentEntry); | 279 DCHECK(type() == kParentEntry); |
| 221 | 280 |
| 222 if (!InitSparseInfo()) | 281 if (!InitSparseInfo()) |
| 223 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 282 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 224 | 283 |
| 225 if (offset < 0 || buf_len < 0) | 284 if (offset < 0 || buf_len < 0) |
| 226 return net::ERR_INVALID_ARGUMENT; | 285 return net::ERR_INVALID_ARGUMENT; |
| 227 | 286 |
| 228 // We will keep using this buffer and adjust the offset in this buffer. | 287 // We will keep using this buffer and adjust the offset in this buffer. |
| 229 scoped_refptr<net::DrainableIOBuffer> io_buf( | 288 scoped_refptr<net::DrainableIOBuffer> io_buf( |
| 230 new net::DrainableIOBuffer(buf, buf_len)); | 289 new net::DrainableIOBuffer(buf, buf_len)); |
| 231 | 290 |
| 232 // Iterate until we have read enough. | 291 // Iterate until we have read enough. |
| 233 while (io_buf->BytesRemaining()) { | 292 while (io_buf->BytesRemaining()) { |
| 234 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), false); | 293 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), false); |
| 235 | 294 |
| 236 // No child present for that offset. | 295 // No child present for that offset. |
| 237 if (!child) | 296 if (!child) |
| 238 break; | 297 break; |
| 239 | 298 |
| 240 // We then need to prepare the child offset and len. | 299 // We then need to prepare the child offset and len. |
| 241 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); | 300 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); |
| 242 | 301 |
| 243 // If we are trying to read from a position that the child entry has no data | 302 // If we are trying to read from a position that the child entry has no data |
| 244 // we should stop. | 303 // we should stop. |
| 245 if (child_offset < child->child_first_pos_) | 304 if (child_offset < child->child_first_pos_) |
| 246 break; | 305 break; |
| 306 if (net_log_.IsLoggingAllEvents()) { | |
| 307 net_log_.BeginEvent( | |
| 308 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, | |
| 309 make_scoped_refptr(new SparseReadWriteParameters( | |
| 310 child->net_log().source(), | |
| 311 io_buf->BytesRemaining()))); | |
| 312 } | |
| 247 int ret = child->ReadData(kSparseData, child_offset, io_buf, | 313 int ret = child->ReadData(kSparseData, child_offset, io_buf, |
| 248 io_buf->BytesRemaining(), NULL); | 314 io_buf->BytesRemaining(), NULL); |
| 315 if (net_log_.IsLoggingAllEvents()) { | |
| 316 net_log_.EndEventWithNetErrorCode( | |
| 317 net::NetLog::TYPE_SPARSE_READ_CHILD_DATA, ret); | |
| 318 } | |
| 249 | 319 |
| 250 // If we encounter an error in one entry, return immediately. | 320 // If we encounter an error in one entry, return immediately. |
| 251 if (ret < 0) | 321 if (ret < 0) |
| 252 return ret; | 322 return ret; |
| 253 else if (ret == 0) | 323 else if (ret == 0) |
| 254 break; | 324 break; |
| 255 | 325 |
| 256 // Increment the counter by number of bytes read in the child entry. | 326 // Increment the counter by number of bytes read in the child entry. |
| 257 io_buf->DidConsume(ret); | 327 io_buf->DidConsume(ret); |
| 258 } | 328 } |
| 259 | 329 |
| 260 UpdateRank(false); | 330 UpdateRank(false); |
| 261 | 331 |
| 262 return io_buf->BytesConsumed(); | 332 return io_buf->BytesConsumed(); |
| 263 } | 333 } |
| 264 | 334 |
| 265 int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, | 335 int MemEntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
| 266 net::CompletionCallback* completion_callback) { | 336 net::CompletionCallback* completion_callback) { |
| 337 if (net_log_.IsLoggingAllEvents()) { | |
| 338 net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_WRITE, | |
| 339 make_scoped_refptr( | |
| 340 new SparseOperationParameters(offset, buf_len))); | |
| 341 } | |
| 342 int result = InternalWriteSparseData(offset, buf, buf_len); | |
| 343 if (net_log_.IsLoggingAllEvents()) | |
| 344 net_log_.EndEvent(net::NetLog::TYPE_SPARSE_WRITE, NULL); | |
| 345 return result; | |
| 346 } | |
| 347 | |
| 348 int MemEntryImpl::InternalWriteSparseData( | |
| 349 int64 offset, net::IOBuffer* buf, int buf_len) { | |
| 267 DCHECK(type() == kParentEntry); | 350 DCHECK(type() == kParentEntry); |
| 268 | 351 |
| 269 if (!InitSparseInfo()) | 352 if (!InitSparseInfo()) |
| 270 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 353 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 271 | 354 |
| 272 if (offset < 0 || buf_len < 0) | 355 if (offset < 0 || buf_len < 0) |
| 273 return net::ERR_INVALID_ARGUMENT; | 356 return net::ERR_INVALID_ARGUMENT; |
| 274 | 357 |
| 275 scoped_refptr<net::DrainableIOBuffer> io_buf( | 358 scoped_refptr<net::DrainableIOBuffer> io_buf( |
| 276 new net::DrainableIOBuffer(buf, buf_len)); | 359 new net::DrainableIOBuffer(buf, buf_len)); |
| 277 | 360 |
| 278 // This loop walks through child entries continuously starting from |offset| | 361 // This loop walks through child entries continuously starting from |offset| |
| 279 // and writes blocks of data (of maximum size kMaxSparseEntrySize) into each | 362 // and writes blocks of data (of maximum size kMaxSparseEntrySize) into each |
| 280 // child entry until all |buf_len| bytes are written. The write operation can | 363 // child entry until all |buf_len| bytes are written. The write operation can |
| 281 // start in the middle of an entry. | 364 // start in the middle of an entry. |
| 282 while (io_buf->BytesRemaining()) { | 365 while (io_buf->BytesRemaining()) { |
| 283 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), true); | 366 MemEntryImpl* child = OpenChild(offset + io_buf->BytesConsumed(), true); |
| 284 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); | 367 int child_offset = ToChildOffset(offset + io_buf->BytesConsumed()); |
| 285 | 368 |
| 286 // Find the right amount to write, this evaluates the remaining bytes to | 369 // Find the right amount to write, this evaluates the remaining bytes to |
| 287 // write and remaining capacity of this child entry. | 370 // write and remaining capacity of this child entry. |
| 288 int write_len = std::min(static_cast<int>(io_buf->BytesRemaining()), | 371 int write_len = std::min(static_cast<int>(io_buf->BytesRemaining()), |
| 289 kMaxSparseEntrySize - child_offset); | 372 kMaxSparseEntrySize - child_offset); |
| 290 | 373 |
| 291 // Keep a record of the last byte position (exclusive) in the child. | 374 // Keep a record of the last byte position (exclusive) in the child. |
| 292 int data_size = child->GetDataSize(kSparseData); | 375 int data_size = child->GetDataSize(kSparseData); |
| 293 | 376 |
| 377 if (net_log_.IsLoggingAllEvents()) { | |
| 378 net_log_.BeginEvent( | |
| 379 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, | |
| 380 make_scoped_refptr(new SparseReadWriteParameters( | |
| 381 child->net_log().source(), | |
| 382 write_len))); | |
| 383 } | |
| 384 | |
| 294 // Always writes to the child entry. This operation may overwrite data | 385 // Always writes to the child entry. This operation may overwrite data |
| 295 // previously written. | 386 // previously written. |
| 296 // TODO(hclam): if there is data in the entry and this write is not | 387 // TODO(hclam): if there is data in the entry and this write is not |
| 297 // continuous we may want to discard this write. | 388 // continuous we may want to discard this write. |
| 298 int ret = child->WriteData(kSparseData, child_offset, io_buf, write_len, | 389 int ret = child->WriteData(kSparseData, child_offset, io_buf, write_len, |
| 299 NULL, true); | 390 NULL, true); |
| 391 if (net_log_.IsLoggingAllEvents()) { | |
| 392 net_log_.EndEventWithNetErrorCode( | |
| 393 net::NetLog::TYPE_SPARSE_WRITE_CHILD_DATA, ret); | |
| 394 } | |
| 300 if (ret < 0) | 395 if (ret < 0) |
| 301 return ret; | 396 return ret; |
| 302 else if (ret == 0) | 397 else if (ret == 0) |
| 303 break; | 398 break; |
| 304 | 399 |
| 305 // Keep a record of the first byte position in the child if the write was | 400 // Keep a record of the first byte position in the child if the write was |
| 306 // not aligned nor continuous. This is to enable witting to the middle | 401 // not aligned nor continuous. This is to enable witting to the middle |
| 307 // of an entry and still keep track of data off the aligned edge. | 402 // of an entry and still keep track of data off the aligned edge. |
| 308 if (data_size != child_offset) | 403 if (data_size != child_offset) |
| 309 child->child_first_pos_ = child_offset; | 404 child->child_first_pos_ = child_offset; |
| 310 | 405 |
| 311 // Adjust the offset in the IO buffer. | 406 // Adjust the offset in the IO buffer. |
| 312 io_buf->DidConsume(ret); | 407 io_buf->DidConsume(ret); |
| 313 } | 408 } |
| 314 | 409 |
| 315 UpdateRank(true); | 410 UpdateRank(true); |
| 316 | 411 |
| 317 return io_buf->BytesConsumed(); | 412 return io_buf->BytesConsumed(); |
| 318 } | 413 } |
| 319 | 414 |
| 320 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, | 415 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start, |
| 321 CompletionCallback* callback) { | 416 CompletionCallback* callback) { |
| 322 return GetAvailableRange(offset, len, start); | 417 if (net_log_.IsLoggingAllEvents()) |
| 418 net_log_.BeginEvent(net::NetLog::TYPE_SPARSE_GET_RANGE, NULL); | |
| 419 int result = GetAvailableRange(offset, len, start); | |
| 420 if (net_log_.IsLoggingAllEvents()) { | |
| 421 net_log_.EndEvent( | |
| 422 net::NetLog::TYPE_SPARSE_GET_RANGE, | |
| 423 make_scoped_refptr( | |
| 424 new GetAvailableRangeResultParameters(*start, result))); | |
| 425 } | |
| 426 return result; | |
| 323 } | 427 } |
| 324 | 428 |
| 325 bool MemEntryImpl::CouldBeSparse() const { | 429 bool MemEntryImpl::CouldBeSparse() const { |
| 326 DCHECK_EQ(kParentEntry, type()); | 430 DCHECK_EQ(kParentEntry, type()); |
| 327 return (children_.get() != NULL); | 431 return (children_.get() != NULL); |
| 328 } | 432 } |
| 329 | 433 |
| 330 int MemEntryImpl::ReadyForSparseIO( | 434 int MemEntryImpl::ReadyForSparseIO( |
| 331 net::CompletionCallback* completion_callback) { | 435 net::CompletionCallback* completion_callback) { |
| 332 return net::OK; | 436 return net::OK; |
| 333 } | 437 } |
| 334 | 438 |
| 335 // ------------------------------------------------------------------------ | 439 // ------------------------------------------------------------------------ |
| 336 | 440 |
| 337 MemEntryImpl::~MemEntryImpl() { | 441 MemEntryImpl::~MemEntryImpl() { |
| 338 for (int i = 0; i < NUM_STREAMS; i++) | 442 for (int i = 0; i < NUM_STREAMS; i++) |
| 339 backend_->ModifyStorageSize(data_size_[i], 0); | 443 backend_->ModifyStorageSize(data_size_[i], 0); |
| 340 backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0); | 444 backend_->ModifyStorageSize(static_cast<int32>(key_.size()), 0); |
| 445 net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_MEM_ENTRY_IMPL, NULL); | |
| 341 } | 446 } |
| 342 | 447 |
| 343 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { | 448 int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start) { |
| 344 DCHECK(type() == kParentEntry); | 449 DCHECK(type() == kParentEntry); |
| 345 DCHECK(start); | 450 DCHECK(start); |
| 346 | 451 |
| 347 if (!InitSparseInfo()) | 452 if (!InitSparseInfo()) |
| 348 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; | 453 return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
| 349 | 454 |
| 350 if (offset < 0 || len < 0 || !start) | 455 if (offset < 0 || len < 0 || !start) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 return true; | 547 return true; |
| 443 } | 548 } |
| 444 | 549 |
| 445 MemEntryImpl* MemEntryImpl::OpenChild(int64 offset, bool create) { | 550 MemEntryImpl* MemEntryImpl::OpenChild(int64 offset, bool create) { |
| 446 DCHECK(type() == kParentEntry); | 551 DCHECK(type() == kParentEntry); |
| 447 int index = ToChildIndex(offset); | 552 int index = ToChildIndex(offset); |
| 448 EntryMap::iterator i = children_->find(index); | 553 EntryMap::iterator i = children_->find(index); |
| 449 if (i != children_->end()) { | 554 if (i != children_->end()) { |
| 450 return i->second; | 555 return i->second; |
| 451 } else if (create) { | 556 } else if (create) { |
| 452 MemEntryImpl* child = new MemEntryImpl(backend_); | 557 MemEntryImpl* child = new MemEntryImpl(backend_); |
|
rvargas (doing something else)
2011/03/04 21:39:16
This creates a child entry that will miss the Begi
mmenke
2011/03/07 17:46:41
Fixed. I should add that both a build from the to
| |
| 453 child->InitChildEntry(this, index); | 558 child->InitChildEntry(this, index); |
| 454 (*children_)[index] = child; | 559 (*children_)[index] = child; |
| 455 return child; | 560 return child; |
| 456 } | 561 } |
| 457 return NULL; | 562 return NULL; |
| 458 } | 563 } |
| 459 | 564 |
| 460 int MemEntryImpl::FindNextChild(int64 offset, int len, MemEntryImpl** child) { | 565 int MemEntryImpl::FindNextChild(int64 offset, int len, MemEntryImpl** child) { |
| 461 DCHECK(child); | 566 DCHECK(child); |
| 462 *child = NULL; | 567 *child = NULL; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 487 scanned_len += kMaxSparseEntrySize - current_child_offset; | 592 scanned_len += kMaxSparseEntrySize - current_child_offset; |
| 488 } | 593 } |
| 489 return scanned_len; | 594 return scanned_len; |
| 490 } | 595 } |
| 491 | 596 |
| 492 void MemEntryImpl::DetachChild(int child_id) { | 597 void MemEntryImpl::DetachChild(int child_id) { |
| 493 children_->erase(child_id); | 598 children_->erase(child_id); |
| 494 } | 599 } |
| 495 | 600 |
| 496 } // namespace disk_cache | 601 } // namespace disk_cache |
| OLD | NEW |