#ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
#define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
#include <stdint.h>
#include "base/memory/scoped_refptr.h"
#include "net/base/completion_once_callback.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/simple/simple_histogram_enums.h"
namespace net {
class IOBuffer;
}
namespace disk_cache {
class SimpleEntryImpl;
class SimpleEntryOperation {
public:
typedef net::CompletionOnceCallback CompletionOnceCallback;
enum EntryOperationType {
TYPE_OPEN = 0,
TYPE_CREATE = 1,
TYPE_OPEN_OR_CREATE = 2,
TYPE_CLOSE = 3,
TYPE_READ = 4,
TYPE_WRITE = 5,
TYPE_READ_SPARSE = 6,
TYPE_WRITE_SPARSE = 7,
TYPE_GET_AVAILABLE_RANGE = 8,
TYPE_DOOM = 9,
};
enum EntryResultState {
ENTRY_ALREADY_RETURNED = 0,
ENTRY_NEEDS_CALLBACK = 1,
};
SimpleEntryOperation(SimpleEntryOperation&& other);
~SimpleEntryOperation();
static SimpleEntryOperation OpenOperation(SimpleEntryImpl* entry,
EntryResultState result_state,
EntryResultCallback);
static SimpleEntryOperation CreateOperation(SimpleEntryImpl* entry,
EntryResultState result_state,
EntryResultCallback);
static SimpleEntryOperation OpenOrCreateOperation(
SimpleEntryImpl* entry,
OpenEntryIndexEnum index_state,
EntryResultState result_state,
EntryResultCallback);
static SimpleEntryOperation CloseOperation(SimpleEntryImpl* entry);
static SimpleEntryOperation ReadOperation(SimpleEntryImpl* entry,
int index,
int64_t offset,
int length,
net::IOBuffer* buf,
CompletionOnceCallback callback);
static SimpleEntryOperation WriteOperation(SimpleEntryImpl* entry,
int index,
int64_t offset,
int length,
net::IOBuffer* buf,
bool truncate,
bool optimistic,
CompletionOnceCallback callback);
static SimpleEntryOperation ReadSparseOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
net::IOBuffer* buf,
CompletionOnceCallback callback);
static SimpleEntryOperation WriteSparseOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
net::IOBuffer* buf,
CompletionOnceCallback callback);
static SimpleEntryOperation GetAvailableRangeOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
RangeResultCallback callback);
static SimpleEntryOperation DoomOperation(SimpleEntryImpl* entry,
CompletionOnceCallback callback);
EntryOperationType type() const {
return static_cast<EntryOperationType>(type_);
}
CompletionOnceCallback ReleaseCallback() { return std::move(callback_); }
EntryResultCallback ReleaseEntryResultCallback() {
return std::move(entry_callback_);
}
RangeResultCallback ReleaseRangeResultCalback() {
return std::move(range_callback_);
}
EntryResultState entry_result_state() { return entry_result_state_; }
OpenEntryIndexEnum index_state() const { return index_state_; }
int index() const { return index_; }
int64_t offset() const { return offset_; }
int64_t sparse_offset() const { return sparse_offset_; }
int length() const { return length_; }
size_t sparse_length() const { return sparse_length_; }
net::IOBuffer* buf() { return buf_.get(); }
bool truncate() const { return truncate_; }
bool optimistic() const { return optimistic_; }
private:
SimpleEntryOperation(SimpleEntryImpl* entry,
net::IOBuffer* buf,
CompletionOnceCallback callback,
int64_t offset,
uint64_t sparse_offset,
int length,
size_t sparse_length,
EntryOperationType type,
OpenEntryIndexEnum index_state,
int index,
bool truncate,
bool optimistic);
scoped_refptr<SimpleEntryImpl> entry_;
scoped_refptr<net::IOBuffer> buf_;
CompletionOnceCallback callback_;
EntryResultCallback entry_callback_;
EntryResultState entry_result_state_;
const int64_t offset_;
const int64_t sparse_offset_;
const int length_;
const size_t sparse_length_;
RangeResultCallback range_callback_;
const EntryOperationType type_;
const OpenEntryIndexEnum index_state_;
const unsigned int index_;
const bool truncate_;
const bool optimistic_;
};
}
#endif