1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/disk_cache/simple/simple_entry_operation.h"
#include <limits.h>
#include "net/base/io_buffer.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/simple/simple_entry_impl.h"
namespace disk_cache {
SimpleEntryOperation::SimpleEntryOperation(SimpleEntryOperation&& other) =
default;
SimpleEntryOperation::~SimpleEntryOperation() = default;
// static
SimpleEntryOperation SimpleEntryOperation::OpenOperation(
SimpleEntryImpl* entry,
EntryResultState result_state,
EntryResultCallback callback) {
SimpleEntryOperation op(entry, nullptr, CompletionOnceCallback(), 0, 0, 0, 0,
TYPE_OPEN, INDEX_NOEXIST, 0, false, false);
op.entry_callback_ = std::move(callback);
op.entry_result_state_ = result_state;
return op;
}
// static
SimpleEntryOperation SimpleEntryOperation::CreateOperation(
SimpleEntryImpl* entry,
EntryResultState result_state,
EntryResultCallback callback) {
SimpleEntryOperation op(entry, nullptr, CompletionOnceCallback(), 0, 0, 0, 0,
TYPE_CREATE, INDEX_NOEXIST, 0, false, false);
op.entry_callback_ = std::move(callback);
op.entry_result_state_ = result_state;
return op;
}
// static
SimpleEntryOperation SimpleEntryOperation::OpenOrCreateOperation(
SimpleEntryImpl* entry,
OpenEntryIndexEnum index_state,
EntryResultState result_state,
EntryResultCallback callback) {
SimpleEntryOperation op(entry, nullptr, CompletionOnceCallback(), 0, 0, 0, 0,
TYPE_OPEN_OR_CREATE, index_state, 0, false, false);
op.entry_callback_ = std::move(callback);
op.entry_result_state_ = result_state;
return op;
}
// static
SimpleEntryOperation SimpleEntryOperation::CloseOperation(
SimpleEntryImpl* entry) {
return SimpleEntryOperation(entry, nullptr, CompletionOnceCallback(), 0, 0, 0,
0, TYPE_CLOSE, INDEX_NOEXIST, 0, false, false);
}
// static
SimpleEntryOperation SimpleEntryOperation::ReadOperation(
SimpleEntryImpl* entry,
int index,
int offset,
int length,
net::IOBuffer* buf,
CompletionOnceCallback callback) {
return SimpleEntryOperation(entry, buf, std::move(callback), offset, 0,
length, 0, TYPE_READ, INDEX_NOEXIST, index, false,
false);
}
// static
SimpleEntryOperation SimpleEntryOperation::WriteOperation(
SimpleEntryImpl* entry,
int index,
int offset,
int length,
net::IOBuffer* buf,
bool truncate,
bool optimistic,
CompletionOnceCallback callback) {
return SimpleEntryOperation(entry, buf, std::move(callback), offset, 0,
length, 0, TYPE_WRITE, INDEX_NOEXIST, index,
truncate, optimistic);
}
// static
SimpleEntryOperation SimpleEntryOperation::ReadSparseOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
net::IOBuffer* buf,
CompletionOnceCallback callback) {
return SimpleEntryOperation(entry, buf, std::move(callback), 0, sparse_offset,
0, sparse_length, TYPE_READ_SPARSE, INDEX_NOEXIST,
0, false, false);
}
// static
SimpleEntryOperation SimpleEntryOperation::WriteSparseOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
net::IOBuffer* buf,
CompletionOnceCallback callback) {
return SimpleEntryOperation(entry, buf, std::move(callback), 0, sparse_offset,
0, sparse_length, TYPE_WRITE_SPARSE,
INDEX_NOEXIST, 0, false, false);
}
// static
SimpleEntryOperation SimpleEntryOperation::GetAvailableRangeOperation(
SimpleEntryImpl* entry,
uint64_t sparse_offset,
size_t sparse_length,
RangeResultCallback callback) {
SimpleEntryOperation op(
entry, nullptr, CompletionOnceCallback(), 0, sparse_offset, 0,
sparse_length, TYPE_GET_AVAILABLE_RANGE, INDEX_NOEXIST, 0, false, false);
op.range_callback_ = std::move(callback);
return op;
}
// static
SimpleEntryOperation SimpleEntryOperation::DoomOperation(
SimpleEntryImpl* entry,
net::CompletionOnceCallback callback) {
net::IOBuffer* const buf = nullptr;
const int offset = 0;
const uint64_t sparse_offset = 0;
const int length = 0;
const size_t sparse_length = 0;
const OpenEntryIndexEnum index_state = INDEX_NOEXIST;
const int index = 0;
const bool truncate = false;
const bool optimistic = false;
return SimpleEntryOperation(entry, buf, std::move(callback), offset,
sparse_offset, length, sparse_length, TYPE_DOOM,
index_state, index, truncate, optimistic);
}
SimpleEntryOperation::SimpleEntryOperation(SimpleEntryImpl* entry,
net::IOBuffer* buf,
net::CompletionOnceCallback callback,
int offset,
uint64_t sparse_offset,
int length,
size_t sparse_length,
EntryOperationType type,
OpenEntryIndexEnum index_state,
int index,
bool truncate,
bool optimistic)
: entry_(entry),
buf_(buf),
callback_(std::move(callback)),
offset_(offset),
sparse_offset_(sparse_offset),
length_(length),
sparse_length_(sparse_length),
type_(type),
index_state_(index_state),
index_(index),
truncate_(truncate),
optimistic_(optimistic) {}
} // namespace disk_cache
|