| OLD | NEW |
| 1 // Copyright (c) 2012 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/memory/mem_entry_impl.h" | 5 #include "net/disk_cache/memory/mem_entry_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend, | 75 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend, |
| 76 const std::string& key, | 76 const std::string& key, |
| 77 net::NetLog* net_log) | 77 net::NetLog* net_log) |
| 78 : MemEntryImpl(backend, | 78 : MemEntryImpl(backend, |
| 79 key, | 79 key, |
| 80 0, // child_id | 80 0, // child_id |
| 81 nullptr, // parent | 81 nullptr, // parent |
| 82 net_log) { | 82 net_log) { |
| 83 Open(); | 83 Open(); |
| 84 // Just creating the entry (without any data) could cause the storage to |
| 85 // grow beyond capacity, but we allow such infractions. |
| 84 backend_->ModifyStorageSize(GetStorageSize()); | 86 backend_->ModifyStorageSize(GetStorageSize()); |
| 85 } | 87 } |
| 86 | 88 |
| 87 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend, | 89 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend, |
| 88 int child_id, | 90 int child_id, |
| 89 MemEntryImpl* parent, | 91 MemEntryImpl* parent, |
| 90 net::NetLog* net_log) | 92 net::NetLog* net_log) |
| 91 : MemEntryImpl(backend, | 93 : MemEntryImpl(backend, |
| 92 std::string(), // key | 94 std::string(), // key |
| 93 child_id, | 95 child_id, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 int max_file_size = backend_->MaxFileSize(); | 340 int max_file_size = backend_->MaxFileSize(); |
| 339 | 341 |
| 340 // offset of buf_len could be negative numbers. | 342 // offset of buf_len could be negative numbers. |
| 341 if (offset > max_file_size || buf_len > max_file_size || | 343 if (offset > max_file_size || buf_len > max_file_size || |
| 342 offset + buf_len > max_file_size) { | 344 offset + buf_len > max_file_size) { |
| 343 return net::ERR_FAILED; | 345 return net::ERR_FAILED; |
| 344 } | 346 } |
| 345 | 347 |
| 346 int old_data_size = data_[index].size(); | 348 int old_data_size = data_[index].size(); |
| 347 if (truncate || old_data_size < offset + buf_len) { | 349 if (truncate || old_data_size < offset + buf_len) { |
| 350 int delta = offset + buf_len - old_data_size; |
| 351 backend_->ModifyStorageSize(delta); |
| 352 if (backend_->HasExceededStorageSize()) { |
| 353 backend_->ModifyStorageSize(-delta); |
| 354 return net::ERR_INSUFFICIENT_RESOURCES; |
| 355 } |
| 356 |
| 348 data_[index].resize(offset + buf_len); | 357 data_[index].resize(offset + buf_len); |
| 349 | 358 |
| 350 // Zero fill any hole. | 359 // Zero fill any hole. |
| 351 if (old_data_size < offset) { | 360 if (old_data_size < offset) { |
| 352 std::fill(data_[index].begin() + old_data_size, | 361 std::fill(data_[index].begin() + old_data_size, |
| 353 data_[index].begin() + offset, 0); | 362 data_[index].begin() + offset, 0); |
| 354 } | 363 } |
| 355 | |
| 356 backend_->ModifyStorageSize(data_[index].size() - old_data_size); | |
| 357 } | 364 } |
| 358 | 365 |
| 359 UpdateStateOnUse(ENTRY_WAS_MODIFIED); | 366 UpdateStateOnUse(ENTRY_WAS_MODIFIED); |
| 360 | 367 |
| 361 if (!buf_len) | 368 if (!buf_len) |
| 362 return 0; | 369 return 0; |
| 363 | 370 |
| 364 std::copy(buf->data(), buf->data() + buf_len, data_[index].begin() + offset); | 371 std::copy(buf->data(), buf->data() + buf_len, data_[index].begin() + offset); |
| 365 return buf_len; | 372 return buf_len; |
| 366 } | 373 } |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 scanned_len += first_pos - current_child_offset; | 594 scanned_len += first_pos - current_child_offset; |
| 588 break; | 595 break; |
| 589 } | 596 } |
| 590 } | 597 } |
| 591 scanned_len += kMaxSparseEntrySize - current_child_offset; | 598 scanned_len += kMaxSparseEntrySize - current_child_offset; |
| 592 } | 599 } |
| 593 return scanned_len; | 600 return scanned_len; |
| 594 } | 601 } |
| 595 | 602 |
| 596 } // namespace disk_cache | 603 } // namespace disk_cache |
| OLD | NEW |