OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/base/io_buffer.h" |
7 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
8 #include "net/disk_cache/mem_backend_impl.h" | 9 #include "net/disk_cache/mem_backend_impl.h" |
9 | 10 |
10 using base::Time; | 11 using base::Time; |
11 | 12 |
12 namespace disk_cache { | 13 namespace disk_cache { |
13 | 14 |
14 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { | 15 MemEntryImpl::MemEntryImpl(MemBackendImpl* backend) { |
15 doomed_ = false; | 16 doomed_ = false; |
16 backend_ = backend; | 17 backend_ = backend; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 return last_modified_; | 76 return last_modified_; |
76 } | 77 } |
77 | 78 |
78 int32 MemEntryImpl::GetDataSize(int index) const { | 79 int32 MemEntryImpl::GetDataSize(int index) const { |
79 if (index < 0 || index >= NUM_STREAMS) | 80 if (index < 0 || index >= NUM_STREAMS) |
80 return 0; | 81 return 0; |
81 | 82 |
82 return data_size_[index]; | 83 return data_size_[index]; |
83 } | 84 } |
84 | 85 |
85 int MemEntryImpl::ReadData(int index, int offset, char* buf, int buf_len, | 86 int MemEntryImpl::ReadData(int index, int offset, net::IOBuffer* buf, |
86 net::CompletionCallback* completion_callback) { | 87 int buf_len, net::CompletionCallback* completion_callback) { |
87 if (index < 0 || index >= NUM_STREAMS) | 88 if (index < 0 || index >= NUM_STREAMS) |
88 return net::ERR_INVALID_ARGUMENT; | 89 return net::ERR_INVALID_ARGUMENT; |
89 | 90 |
90 int entry_size = GetDataSize(index); | 91 int entry_size = GetDataSize(index); |
91 if (offset >= entry_size || offset < 0 || !buf_len) | 92 if (offset >= entry_size || offset < 0 || !buf_len) |
92 return 0; | 93 return 0; |
93 | 94 |
94 if (buf_len < 0) | 95 if (buf_len < 0) |
95 return net::ERR_INVALID_ARGUMENT; | 96 return net::ERR_INVALID_ARGUMENT; |
96 | 97 |
97 if (offset + buf_len > entry_size) | 98 if (offset + buf_len > entry_size) |
98 buf_len = entry_size - offset; | 99 buf_len = entry_size - offset; |
99 | 100 |
100 UpdateRank(false); | 101 UpdateRank(false); |
101 | 102 |
102 memcpy(buf , &(data_[index])[offset], buf_len); | 103 memcpy(buf->data() , &(data_[index])[offset], buf_len); |
103 return buf_len; | 104 return buf_len; |
104 } | 105 } |
105 | 106 |
106 int MemEntryImpl::WriteData(int index, int offset, const char* buf, int buf_len, | 107 int MemEntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, |
107 net::CompletionCallback* completion_callback, | 108 int buf_len, net::CompletionCallback* completion_callback, bool truncate) { |
108 bool truncate) { | |
109 if (index < 0 || index >= NUM_STREAMS) | 109 if (index < 0 || index >= NUM_STREAMS) |
110 return net::ERR_INVALID_ARGUMENT; | 110 return net::ERR_INVALID_ARGUMENT; |
111 | 111 |
112 if (offset < 0 || buf_len < 0) | 112 if (offset < 0 || buf_len < 0) |
113 return net::ERR_INVALID_ARGUMENT; | 113 return net::ERR_INVALID_ARGUMENT; |
114 | 114 |
115 int max_file_size = backend_->MaxFileSize(); | 115 int max_file_size = backend_->MaxFileSize(); |
116 | 116 |
117 // offset of buf_len could be negative numbers. | 117 // offset of buf_len could be negative numbers. |
118 if (offset > max_file_size || buf_len > max_file_size || | 118 if (offset > max_file_size || buf_len > max_file_size || |
(...skipping 17 matching lines...) Expand all Loading... |
136 backend_->ModifyStorageSize(entry_size, offset + buf_len); | 136 backend_->ModifyStorageSize(entry_size, offset + buf_len); |
137 data_size_[index] = offset + buf_len; | 137 data_size_[index] = offset + buf_len; |
138 } | 138 } |
139 } | 139 } |
140 | 140 |
141 UpdateRank(true); | 141 UpdateRank(true); |
142 | 142 |
143 if (!buf_len) | 143 if (!buf_len) |
144 return 0; | 144 return 0; |
145 | 145 |
146 memcpy(&(data_[index])[offset], buf, buf_len); | 146 memcpy(&(data_[index])[offset], buf->data(), buf_len); |
147 return buf_len; | 147 return buf_len; |
148 } | 148 } |
149 | 149 |
150 void MemEntryImpl::PrepareTarget(int index, int offset, int buf_len) { | 150 void MemEntryImpl::PrepareTarget(int index, int offset, int buf_len) { |
151 int entry_size = GetDataSize(index); | 151 int entry_size = GetDataSize(index); |
152 | 152 |
153 if (entry_size >= offset + buf_len) | 153 if (entry_size >= offset + buf_len) |
154 return; // Not growing the stored data. | 154 return; // Not growing the stored data. |
155 | 155 |
156 if (static_cast<int>(data_[index].size()) < offset + buf_len) | 156 if (static_cast<int>(data_[index].size()) < offset + buf_len) |
(...skipping 13 matching lines...) Expand all Loading... |
170 | 170 |
171 if (modified) | 171 if (modified) |
172 last_modified_ = current; | 172 last_modified_ = current; |
173 | 173 |
174 if (!doomed_) | 174 if (!doomed_) |
175 backend_->UpdateRank(this); | 175 backend_->UpdateRank(this); |
176 } | 176 } |
177 | 177 |
178 } // namespace disk_cache | 178 } // namespace disk_cache |
179 | 179 |
OLD | NEW |