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
3 // found in the LICENSE file.
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_
8 #include "base/memory/ref_counted.h"
9 #include "net/base/completion_callback.h"
10 #include "net/log/net_log.h"
16 namespace disk_cache
{
19 class SimpleEntryImpl
;
21 // SimpleEntryOperation stores the information regarding operations in
22 // SimpleEntryImpl, between the moment they are issued by users of the backend,
23 // and the moment when they are executed.
24 class SimpleEntryOperation
{
26 typedef net::CompletionCallback CompletionCallback
;
28 enum EntryOperationType
{
35 TYPE_WRITE_SPARSE
= 6,
36 TYPE_GET_AVAILABLE_RANGE
= 7,
40 SimpleEntryOperation(const SimpleEntryOperation
& other
);
41 ~SimpleEntryOperation();
43 static SimpleEntryOperation
OpenOperation(SimpleEntryImpl
* entry
,
45 const CompletionCallback
& callback
,
47 static SimpleEntryOperation
CreateOperation(
48 SimpleEntryImpl
* entry
,
50 const CompletionCallback
& callback
,
52 static SimpleEntryOperation
CloseOperation(SimpleEntryImpl
* entry
);
53 static SimpleEntryOperation
ReadOperation(SimpleEntryImpl
* entry
,
58 const CompletionCallback
& callback
,
60 static SimpleEntryOperation
WriteOperation(
61 SimpleEntryImpl
* entry
,
68 const CompletionCallback
& callback
);
69 static SimpleEntryOperation
ReadSparseOperation(
70 SimpleEntryImpl
* entry
,
74 const CompletionCallback
& callback
);
75 static SimpleEntryOperation
WriteSparseOperation(
76 SimpleEntryImpl
* entry
,
80 const CompletionCallback
& callback
);
81 static SimpleEntryOperation
GetAvailableRangeOperation(
82 SimpleEntryImpl
* entry
,
86 const CompletionCallback
& callback
);
87 static SimpleEntryOperation
DoomOperation(
88 SimpleEntryImpl
* entry
,
89 const CompletionCallback
& callback
);
91 bool ConflictsWith(const SimpleEntryOperation
& other_op
) const;
92 // Releases all references. After calling this operation, SimpleEntryOperation
93 // will only hold POD members.
94 void ReleaseReferences();
96 EntryOperationType
type() const {
97 return static_cast<EntryOperationType
>(type_
);
99 const CompletionCallback
& callback() const { return callback_
; }
100 Entry
** out_entry() { return out_entry_
; }
101 bool have_index() const { return have_index_
; }
102 int index() const { return index_
; }
103 int offset() const { return offset_
; }
104 int64
sparse_offset() const { return sparse_offset_
; }
105 int length() const { return length_
; }
106 int64
* out_start() { return out_start_
; }
107 net::IOBuffer
* buf() { return buf_
.get(); }
108 bool truncate() const { return truncate_
; }
109 bool optimistic() const { return optimistic_
; }
110 bool alone_in_queue() const { return alone_in_queue_
; }
113 SimpleEntryOperation(SimpleEntryImpl
* entry
,
115 const CompletionCallback
& callback
,
121 EntryOperationType type
,
126 bool alone_in_queue
);
128 // This ensures entry will not be deleted until the operation has ran.
129 scoped_refptr
<SimpleEntryImpl
> entry_
;
130 scoped_refptr
<net::IOBuffer
> buf_
;
131 CompletionCallback callback_
;
133 // Used in open and create operations.
136 // Used in write and read operations.
138 const int64 sparse_offset_
;
141 // Used in get available range operations.
142 int64
* const out_start_
;
144 const EntryOperationType type_
;
145 // Used in open and create operations.
146 const bool have_index_
;
147 // Used in write and read operations.
148 const unsigned int index_
;
149 // Used only in write operations.
150 const bool truncate_
;
151 const bool optimistic_
;
152 // Used only in SimpleCache.ReadIsParallelizable histogram.
153 const bool alone_in_queue_
;
156 } // namespace disk_cache
158 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_