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/base/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
{
36 SimpleEntryOperation(const SimpleEntryOperation
& other
);
37 ~SimpleEntryOperation();
39 static SimpleEntryOperation
OpenOperation(SimpleEntryImpl
* entry
,
41 const CompletionCallback
& callback
,
43 static SimpleEntryOperation
CreateOperation(
44 SimpleEntryImpl
* entry
,
46 const CompletionCallback
& callback
,
48 static SimpleEntryOperation
CloseOperation(SimpleEntryImpl
* entry
);
49 static SimpleEntryOperation
ReadOperation(SimpleEntryImpl
* entry
,
54 const CompletionCallback
& callback
,
56 static SimpleEntryOperation
WriteOperation(
57 SimpleEntryImpl
* entry
,
64 const CompletionCallback
& callback
);
66 bool ConflictsWith(const SimpleEntryOperation
& other_op
) const;
67 // Releases all references. After calling this operation, SimpleEntryOperation
68 // will only hold POD members.
69 void ReleaseReferences();
71 EntryOperationType
type() const {
72 return static_cast<EntryOperationType
>(type_
);
74 const CompletionCallback
& callback() const { return callback_
; }
75 Entry
** out_entry() { return out_entry_
; }
76 bool have_index() const { return have_index_
; }
77 int index() const { return index_
; }
78 int offset() const { return offset_
; }
79 int length() const { return length_
; }
80 net::IOBuffer
* buf() { return buf_
.get(); }
81 bool truncate() const { return truncate_
; }
82 bool optimistic() const { return optimistic_
; }
83 bool alone_in_queue() const { return alone_in_queue_
; }
86 SimpleEntryOperation(SimpleEntryImpl
* entry
,
88 const CompletionCallback
& callback
,
92 EntryOperationType type
,
99 // This ensures entry will not be deleted until the operation has ran.
100 scoped_refptr
<SimpleEntryImpl
> entry_
;
101 scoped_refptr
<net::IOBuffer
> buf_
;
102 CompletionCallback callback_
;
104 // Used in open and create operations.
107 // Used in write and read operations.
111 const unsigned int type_
: 3; /* 3 */
112 // Used in open and create operations.
113 const unsigned int have_index_
: 1; /* 4 */
114 // Used in write and read operations.
115 const unsigned int index_
: 2; /* 6 */
116 // Used only in write operations.
117 const unsigned int truncate_
: 1; /* 7 */
118 const unsigned int optimistic_
: 1; /* 8 */
119 // Used only in SimpleCache.ReadIsParallelizable histogram.
120 const unsigned int alone_in_queue_
: 1; /* 9 */
123 } // namespace disk_cache
125 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_OPERATION_H_