| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/simple/simple_entry_operation.h" | 5 #include "net/disk_cache/simple/simple_entry_operation.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/disk_cache/disk_cache.h" | 9 #include "net/disk_cache/disk_cache.h" |
| 10 #include "net/disk_cache/simple/simple_entry_impl.h" | 10 #include "net/disk_cache/simple/simple_entry_impl.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 false, | 161 false, |
| 162 index, | 162 index, |
| 163 truncate, | 163 truncate, |
| 164 optimistic, | 164 optimistic, |
| 165 false); | 165 false); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // static | 168 // static |
| 169 SimpleEntryOperation SimpleEntryOperation::ReadSparseOperation( | 169 SimpleEntryOperation SimpleEntryOperation::ReadSparseOperation( |
| 170 SimpleEntryImpl* entry, | 170 SimpleEntryImpl* entry, |
| 171 int64 sparse_offset, | 171 int64_t sparse_offset, |
| 172 int length, | 172 int length, |
| 173 net::IOBuffer* buf, | 173 net::IOBuffer* buf, |
| 174 const CompletionCallback& callback) { | 174 const CompletionCallback& callback) { |
| 175 return SimpleEntryOperation(entry, | 175 return SimpleEntryOperation(entry, |
| 176 buf, | 176 buf, |
| 177 callback, | 177 callback, |
| 178 NULL, | 178 NULL, |
| 179 0, | 179 0, |
| 180 sparse_offset, | 180 sparse_offset, |
| 181 length, | 181 length, |
| 182 NULL, | 182 NULL, |
| 183 TYPE_READ_SPARSE, | 183 TYPE_READ_SPARSE, |
| 184 false, | 184 false, |
| 185 0, | 185 0, |
| 186 false, | 186 false, |
| 187 false, | 187 false, |
| 188 false); | 188 false); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // static | 191 // static |
| 192 SimpleEntryOperation SimpleEntryOperation::WriteSparseOperation( | 192 SimpleEntryOperation SimpleEntryOperation::WriteSparseOperation( |
| 193 SimpleEntryImpl* entry, | 193 SimpleEntryImpl* entry, |
| 194 int64 sparse_offset, | 194 int64_t sparse_offset, |
| 195 int length, | 195 int length, |
| 196 net::IOBuffer* buf, | 196 net::IOBuffer* buf, |
| 197 const CompletionCallback& callback) { | 197 const CompletionCallback& callback) { |
| 198 return SimpleEntryOperation(entry, | 198 return SimpleEntryOperation(entry, |
| 199 buf, | 199 buf, |
| 200 callback, | 200 callback, |
| 201 NULL, | 201 NULL, |
| 202 0, | 202 0, |
| 203 sparse_offset, | 203 sparse_offset, |
| 204 length, | 204 length, |
| 205 NULL, | 205 NULL, |
| 206 TYPE_WRITE_SPARSE, | 206 TYPE_WRITE_SPARSE, |
| 207 false, | 207 false, |
| 208 0, | 208 0, |
| 209 false, | 209 false, |
| 210 false, | 210 false, |
| 211 false); | 211 false); |
| 212 } | 212 } |
| 213 | 213 |
| 214 // static | 214 // static |
| 215 SimpleEntryOperation SimpleEntryOperation::GetAvailableRangeOperation( | 215 SimpleEntryOperation SimpleEntryOperation::GetAvailableRangeOperation( |
| 216 SimpleEntryImpl* entry, | 216 SimpleEntryImpl* entry, |
| 217 int64 sparse_offset, | 217 int64_t sparse_offset, |
| 218 int length, | 218 int length, |
| 219 int64* out_start, | 219 int64_t* out_start, |
| 220 const CompletionCallback& callback) { | 220 const CompletionCallback& callback) { |
| 221 return SimpleEntryOperation(entry, | 221 return SimpleEntryOperation(entry, |
| 222 NULL, | 222 NULL, |
| 223 callback, | 223 callback, |
| 224 NULL, | 224 NULL, |
| 225 0, | 225 0, |
| 226 sparse_offset, | 226 sparse_offset, |
| 227 length, | 227 length, |
| 228 out_start, | 228 out_start, |
| 229 TYPE_GET_AVAILABLE_RANGE, | 229 TYPE_GET_AVAILABLE_RANGE, |
| 230 false, | 230 false, |
| 231 0, | 231 0, |
| 232 false, | 232 false, |
| 233 false, | 233 false, |
| 234 false); | 234 false); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // static | 237 // static |
| 238 SimpleEntryOperation SimpleEntryOperation::DoomOperation( | 238 SimpleEntryOperation SimpleEntryOperation::DoomOperation( |
| 239 SimpleEntryImpl* entry, | 239 SimpleEntryImpl* entry, |
| 240 const CompletionCallback& callback) { | 240 const CompletionCallback& callback) { |
| 241 net::IOBuffer* const buf = NULL; | 241 net::IOBuffer* const buf = NULL; |
| 242 Entry** const out_entry = NULL; | 242 Entry** const out_entry = NULL; |
| 243 const int offset = 0; | 243 const int offset = 0; |
| 244 const int64 sparse_offset = 0; | 244 const int64_t sparse_offset = 0; |
| 245 const int length = 0; | 245 const int length = 0; |
| 246 int64* const out_start = NULL; | 246 int64_t* const out_start = NULL; |
| 247 const bool have_index = false; | 247 const bool have_index = false; |
| 248 const int index = 0; | 248 const int index = 0; |
| 249 const bool truncate = false; | 249 const bool truncate = false; |
| 250 const bool optimistic = false; | 250 const bool optimistic = false; |
| 251 const bool alone_in_queue = false; | 251 const bool alone_in_queue = false; |
| 252 return SimpleEntryOperation(entry, | 252 return SimpleEntryOperation(entry, |
| 253 buf, | 253 buf, |
| 254 callback, | 254 callback, |
| 255 out_entry, | 255 out_entry, |
| 256 offset, | 256 offset, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 280 // Sparse and non-sparse operations do not conflict with each other. | 280 // Sparse and non-sparse operations do not conflict with each other. |
| 281 if (IsSparseType(type_) != IsSparseType(other_type)) { | 281 if (IsSparseType(type_) != IsSparseType(other_type)) { |
| 282 return false; | 282 return false; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // There must be two read/write operations, at least one must be a write, and | 285 // There must be two read/write operations, at least one must be a write, and |
| 286 // they must be either both non-sparse or both sparse. Compare the streams | 286 // they must be either both non-sparse or both sparse. Compare the streams |
| 287 // and offsets to see whether they overlap. | 287 // and offsets to see whether they overlap. |
| 288 | 288 |
| 289 if (IsSparseType(type_)) { | 289 if (IsSparseType(type_)) { |
| 290 int64 end = sparse_offset_ + length_; | 290 int64_t end = sparse_offset_ + length_; |
| 291 int64 other_op_end = other_op.sparse_offset() + other_op.length(); | 291 int64_t other_op_end = other_op.sparse_offset() + other_op.length(); |
| 292 return sparse_offset_ < other_op_end && other_op.sparse_offset() < end; | 292 return sparse_offset_ < other_op_end && other_op.sparse_offset() < end; |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (index_ != other_op.index_) | 295 if (index_ != other_op.index_) |
| 296 return false; | 296 return false; |
| 297 int end = (type_ == TYPE_WRITE && truncate_) ? INT_MAX : offset_ + length_; | 297 int end = (type_ == TYPE_WRITE && truncate_) ? INT_MAX : offset_ + length_; |
| 298 int other_op_end = (other_op.type() == TYPE_WRITE && other_op.truncate()) | 298 int other_op_end = (other_op.type() == TYPE_WRITE && other_op.truncate()) |
| 299 ? INT_MAX | 299 ? INT_MAX |
| 300 : other_op.offset() + other_op.length(); | 300 : other_op.offset() + other_op.length(); |
| 301 return offset_ < other_op_end && other_op.offset() < end; | 301 return offset_ < other_op_end && other_op.offset() < end; |
| 302 } | 302 } |
| 303 | 303 |
| 304 void SimpleEntryOperation::ReleaseReferences() { | 304 void SimpleEntryOperation::ReleaseReferences() { |
| 305 callback_ = CompletionCallback(); | 305 callback_ = CompletionCallback(); |
| 306 buf_ = NULL; | 306 buf_ = NULL; |
| 307 entry_ = NULL; | 307 entry_ = NULL; |
| 308 } | 308 } |
| 309 | 309 |
| 310 SimpleEntryOperation::SimpleEntryOperation(SimpleEntryImpl* entry, | 310 SimpleEntryOperation::SimpleEntryOperation(SimpleEntryImpl* entry, |
| 311 net::IOBuffer* buf, | 311 net::IOBuffer* buf, |
| 312 const CompletionCallback& callback, | 312 const CompletionCallback& callback, |
| 313 Entry** out_entry, | 313 Entry** out_entry, |
| 314 int offset, | 314 int offset, |
| 315 int64 sparse_offset, | 315 int64_t sparse_offset, |
| 316 int length, | 316 int length, |
| 317 int64* out_start, | 317 int64_t* out_start, |
| 318 EntryOperationType type, | 318 EntryOperationType type, |
| 319 bool have_index, | 319 bool have_index, |
| 320 int index, | 320 int index, |
| 321 bool truncate, | 321 bool truncate, |
| 322 bool optimistic, | 322 bool optimistic, |
| 323 bool alone_in_queue) | 323 bool alone_in_queue) |
| 324 : entry_(entry), | 324 : entry_(entry), |
| 325 buf_(buf), | 325 buf_(buf), |
| 326 callback_(callback), | 326 callback_(callback), |
| 327 out_entry_(out_entry), | 327 out_entry_(out_entry), |
| 328 offset_(offset), | 328 offset_(offset), |
| 329 sparse_offset_(sparse_offset), | 329 sparse_offset_(sparse_offset), |
| 330 length_(length), | 330 length_(length), |
| 331 out_start_(out_start), | 331 out_start_(out_start), |
| 332 type_(type), | 332 type_(type), |
| 333 have_index_(have_index), | 333 have_index_(have_index), |
| 334 index_(index), | 334 index_(index), |
| 335 truncate_(truncate), | 335 truncate_(truncate), |
| 336 optimistic_(optimistic), | 336 optimistic_(optimistic), |
| 337 alone_in_queue_(alone_in_queue) { | 337 alone_in_queue_(alone_in_queue) {} |
| 338 } | |
| 339 | 338 |
| 340 } // namespace disk_cache | 339 } // namespace disk_cache |
| OLD | NEW |