1bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 2bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// found in the LICENSE file. 4bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 5bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "net/disk_cache/simple/simple_entry_operation.h" 6bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 7bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "base/logging.h" 8bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "net/base/io_buffer.h" 9bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "net/disk_cache/disk_cache.h" 10bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "net/disk_cache/simple/simple_entry_impl.h" 11bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 12bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochnamespace disk_cache { 13bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace { 150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)bool IsReadWriteType(unsigned int type) { 170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return type == SimpleEntryOperation::TYPE_READ || 180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type == SimpleEntryOperation::TYPE_WRITE || 190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type == SimpleEntryOperation::TYPE_READ_SPARSE || 200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type == SimpleEntryOperation::TYPE_WRITE_SPARSE; 210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)bool IsReadType(unsigned type) { 240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return type == SimpleEntryOperation::TYPE_READ || 250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type == SimpleEntryOperation::TYPE_READ_SPARSE; 260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)bool IsSparseType(unsigned type) { 290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return type == SimpleEntryOperation::TYPE_READ_SPARSE || 300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) type == SimpleEntryOperation::TYPE_WRITE_SPARSE; 310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 35bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation::SimpleEntryOperation(const SimpleEntryOperation& other) 36bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch : entry_(other.entry_.get()), 37bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch buf_(other.buf_), 38bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback_(other.callback_), 39bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch out_entry_(other.out_entry_), 40bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch offset_(other.offset_), 410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset_(other.sparse_offset_), 42bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch length_(other.length_), 430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) out_start_(other.out_start_), 44bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch type_(other.type_), 45bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch have_index_(other.have_index_), 46bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch index_(other.index_), 47bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch truncate_(other.truncate_), 48bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch optimistic_(other.optimistic_), 49bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch alone_in_queue_(other.alone_in_queue_) { 50bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 51bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 52bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation::~SimpleEntryOperation() {} 53bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 55bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation SimpleEntryOperation::OpenOperation( 56bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch SimpleEntryImpl* entry, 57bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool have_index, 58bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const CompletionCallback& callback, 59bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch Entry** out_entry) { 60bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SimpleEntryOperation(entry, 61bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 62bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback, 63bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch out_entry, 64bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 65bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 68bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch TYPE_OPEN, 69bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch have_index, 70bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 71bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 72bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 73bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false); 74bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 75bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 7658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 77bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation SimpleEntryOperation::CreateOperation( 78bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch SimpleEntryImpl* entry, 79bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool have_index, 80bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const CompletionCallback& callback, 81bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch Entry** out_entry) { 82bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SimpleEntryOperation(entry, 83bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 84bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback, 85bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch out_entry, 86bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 87bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 90bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch TYPE_CREATE, 91bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch have_index, 92bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 93bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 94bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 95bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false); 96bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 97bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 9858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 99bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation SimpleEntryOperation::CloseOperation( 100bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch SimpleEntryImpl* entry) { 101bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SimpleEntryOperation(entry, 102bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 103bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch CompletionCallback(), 104bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 105bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 106bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 1070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 1080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 109bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch TYPE_CLOSE, 110bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 111bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 0, 112bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 113bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 114bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false); 115bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 116bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 11758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 118bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation SimpleEntryOperation::ReadOperation( 119bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch SimpleEntryImpl* entry, 120bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int index, 121bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int offset, 122bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int length, 123bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch net::IOBuffer* buf, 124bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const CompletionCallback& callback, 125bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool alone_in_queue) { 126bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SimpleEntryOperation(entry, 127bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch buf, 128bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback, 129bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 130bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch offset, 1310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 132bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch length, 1330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 134bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch TYPE_READ, 135bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 136bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch index, 137bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 138bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 139bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch alone_in_queue); 140bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 141bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 14258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 143bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation SimpleEntryOperation::WriteOperation( 144bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch SimpleEntryImpl* entry, 145bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int index, 146bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int offset, 147bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int length, 148bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch net::IOBuffer* buf, 149bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool truncate, 150bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool optimistic, 151bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const CompletionCallback& callback) { 152bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SimpleEntryOperation(entry, 153bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch buf, 154bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback, 155bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch NULL, 156bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch offset, 1570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 158bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch length, 1590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 160bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch TYPE_WRITE, 161bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false, 162bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch index, 163bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch truncate, 164bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch optimistic, 165bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch false); 166bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 167bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 16858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// static 1690f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)SimpleEntryOperation SimpleEntryOperation::ReadSparseOperation( 1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) SimpleEntryImpl* entry, 1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 sparse_offset, 1720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int length, 1730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) net::IOBuffer* buf, 1740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const CompletionCallback& callback) { 1750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return SimpleEntryOperation(entry, 1760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) buf, 1770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) callback, 1780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 1790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 1800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset, 1810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) length, 1820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 1830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) TYPE_READ_SPARSE, 1840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 1850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 1860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 1870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 1880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false); 1890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 1900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static 1920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)SimpleEntryOperation SimpleEntryOperation::WriteSparseOperation( 1930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) SimpleEntryImpl* entry, 1940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 sparse_offset, 1950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int length, 1960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) net::IOBuffer* buf, 1970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const CompletionCallback& callback) { 1980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return SimpleEntryOperation(entry, 1990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) buf, 2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) callback, 2010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 2020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 2030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset, 2040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) length, 2050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 2060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) TYPE_WRITE_SPARSE, 2070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 2090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false); 2120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 2130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static 2150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)SimpleEntryOperation SimpleEntryOperation::GetAvailableRangeOperation( 2160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) SimpleEntryImpl* entry, 2170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 sparse_offset, 2180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int length, 2190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64* out_start, 2200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const CompletionCallback& callback) { 2210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return SimpleEntryOperation(entry, 2220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 2230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) callback, 2240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) NULL, 2250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset, 2270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) length, 2280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) out_start, 2290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) TYPE_GET_AVAILABLE_RANGE, 2300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 0, 2320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false, 2340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) false); 2350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)} 2360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// static 23858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)SimpleEntryOperation SimpleEntryOperation::DoomOperation( 23958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) SimpleEntryImpl* entry, 24058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const CompletionCallback& callback) { 24158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) net::IOBuffer* const buf = NULL; 24258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Entry** const out_entry = NULL; 24358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const int offset = 0; 2440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) const int64 sparse_offset = 0; 24558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const int length = 0; 2460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64* const out_start = NULL; 24758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const bool have_index = false; 24858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const int index = 0; 24958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const bool truncate = false; 25058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const bool optimistic = false; 25158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const bool alone_in_queue = false; 25258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return SimpleEntryOperation(entry, 25358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) buf, 25458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) callback, 25558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) out_entry, 25658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) offset, 2570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset, 25858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) length, 2590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) out_start, 26058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) TYPE_DOOM, 26158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) have_index, 26258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) index, 26358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) truncate, 26458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) optimistic, 26558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) alone_in_queue); 26658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 268bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochbool SimpleEntryOperation::ConflictsWith( 269bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const SimpleEntryOperation& other_op) const { 2700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EntryOperationType other_type = other_op.type(); 2710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2720f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Non-read/write operations conflict with everything. 2730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (!IsReadWriteType(type_) || !IsReadWriteType(other_type)) 274bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return true; 2750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Reads (sparse or otherwise) conflict with nothing. 2770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (IsReadType(type_) && IsReadType(other_type)) 278bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return false; 2790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // Sparse and non-sparse operations do not conflict with each other. 2810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (IsSparseType(type_) != IsSparseType(other_type)) { 2820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return false; 2830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) } 2840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // There must be two read/write operations, at least one must be a write, and 2860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // they must be either both non-sparse or both sparse. Compare the streams 2870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // and offsets to see whether they overlap. 2880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 2890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) if (IsSparseType(type_)) { 2900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 end = sparse_offset_ + length_; 2910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 other_op_end = other_op.sparse_offset() + other_op.length(); 2920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return sparse_offset_ < other_op_end && other_op.sparse_offset() < end; 2930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) } 2940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 295bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if (index_ != other_op.index_) 296bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return false; 297bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int end = (type_ == TYPE_WRITE && truncate_) ? INT_MAX : offset_ + length_; 298bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int other_op_end = (other_op.type() == TYPE_WRITE && other_op.truncate()) 299bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch ? INT_MAX 300bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch : other_op.offset() + other_op.length(); 3010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) return offset_ < other_op_end && other_op.offset() < end; 302bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 303bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 304bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochvoid SimpleEntryOperation::ReleaseReferences() { 305bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback_ = CompletionCallback(); 306bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch buf_ = NULL; 307bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch entry_ = NULL; 308bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 309bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 310bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben MurdochSimpleEntryOperation::SimpleEntryOperation(SimpleEntryImpl* entry, 311bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch net::IOBuffer* buf, 312bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch const CompletionCallback& callback, 313bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch Entry** out_entry, 314bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int offset, 3150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64 sparse_offset, 316bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int length, 3170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int64* out_start, 318bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch EntryOperationType type, 319bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool have_index, 320bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch int index, 321bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool truncate, 322bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool optimistic, 323bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch bool alone_in_queue) 324bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch : entry_(entry), 325bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch buf_(buf), 326bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch callback_(callback), 327bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch out_entry_(out_entry), 328bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch offset_(offset), 3290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) sparse_offset_(sparse_offset), 330bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch length_(length), 3310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) out_start_(out_start), 332bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch type_(type), 333bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch have_index_(have_index), 334bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch index_(index), 335bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch truncate_(truncate), 336bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch optimistic_(optimistic), 337bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch alone_in_queue_(alone_in_queue) { 338bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 339bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 340bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} // namespace disk_cache 341