Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: net/disk_cache/v3/sparse_control_v3.h

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/v3/index_table_unittest.cc ('k') | net/disk_cache/v3/sparse_control_v3.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #ifndef NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
6 #define NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/base/completion_callback.h"
14 #include "net/disk_cache/bitmap.h"
15 #include "net/disk_cache/disk_format_base.h"
16
17 namespace net {
18 class IOBuffer;
19 class DrainableIOBuffer;
20 }
21
22 namespace disk_cache {
23
24 class Entry;
25 class EntryImplV3;
26
27 // This class provides support for the sparse capabilities of the disk cache.
28 // Basically, sparse IO is directed from EntryImpl to this class, and we split
29 // the operation into multiple small pieces, sending each one to the
30 // appropriate entry. An instance of this class is asociated with each entry
31 // used directly for sparse operations (the entry passed in to the constructor).
32 class SparseControlV3 {
33 public:
34 typedef net::CompletionCallback CompletionCallback;
35
36 // The operation to perform.
37 enum SparseOperation {
38 kNoOperation,
39 kReadOperation,
40 kWriteOperation,
41 kGetRangeOperation
42 };
43
44 explicit SparseControlV3(EntryImplV3* entry);
45 ~SparseControlV3();
46
47 void Close();
48
49 // Performs a quick test to see if the entry is sparse or not, without
50 // generating disk IO (so the answer provided is only a best effort).
51 bool CouldBeSparse() const;
52
53 // Performs an actual sparse read or write operation for this entry. |op| is
54 // the operation to perform, |offset| is the desired sparse offset, |buf| and
55 // |buf_len| specify the actual data to use and |callback| is the callback
56 // to use for asynchronous operations. See the description of the Read /
57 // WriteSparseData for details about the arguments. The return value is the
58 // number of bytes read or written, or a net error code.
59 int StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
60 int buf_len, const CompletionCallback& callback);
61
62 // Implements Entry::GetAvailableRange().
63 int GetAvailableRange(int64 offset, int len, int64* start,
64 const CompletionCallback& callback);
65
66 // Cancels the current sparse operation (if any).
67 void CancelIO();
68
69 // Returns OK if the entry can be used for new IO or ERR_IO_PENDING if we are
70 // busy. If the entry is busy, we'll invoke the callback when we are ready
71 // again. See disk_cache::Entry::ReadyToUse() for more info.
72 int ReadyToUse(const CompletionCallback& completion_callback);
73
74 // Deletes the children entries of |entry|.
75 static void DeleteChildren(EntryImplV3* entry);
76
77 private:
78 enum State {
79 STATE_NONE,
80 STATE_INIT,
81 STATE_CREATE_SPARSE_ENTRY,
82 STATE_CREATE_SPARSE_ENTRY_COMPLETE,
83 STATE_OPEN_SPARSE_ENTRY,
84 STATE_OPEN_SPARSE_ENTRY_COMPLETE,
85 STATE_READ_BITMAP_COMPLETE,
86 STATE_GET_CHILD_KEY,
87 STATE_OPEN_CHILD,
88 STATE_OPEN_CHILD_COMPLETE,
89 STATE_READ_SIGNATURE_COMPLETE,
90 STATE_CLOSE_CHILD,
91 STATE_CLOSE_CHILD_COMPLETE,
92 STATE_CREATE_CHILD,
93 STATE_CREATE_CHILD_COMPLETE,
94 STATE_WRITE_BITMAP,
95 STATE_WRITE_BITMAP_COMPLETE,
96 STATE_DO_CHILD_IO,
97 STATE_DO_CHILD_IO_COMPLETE,
98 STATE_CLOSE
99 };
100
101 int DoLoop(int result);
102 int DoInit();
103 int DoCreateSparseEntry();
104 int DoCreateSparseEntryComplete(int result);
105 int DoOpenSparseEntry(int data_len);
106 int DoOpenSparseEntryComplete(int result);
107 int DoReadBitmapComplete(int result);
108 int DoGetChildKey();
109 int DoOpenChild();
110 int DoOpenChildComplete(int result);
111 int DoReadSignatureComplete(int result);
112 int DoCloseChild();
113 int DoCloseChildComplete(int result);
114 int DoCreateChild();
115 int DoCreateChildComplete(int result);
116 int DoWriteBitmap();
117 int DoWriteBitmapComplete(int result);
118 int DoChildIO();
119 int DoChildIOComplete(int result);
120 int DoClose();
121
122 std::string GenerateChildKey();
123
124 // Deletes the current child and continues the current operation (open).
125 int KillChildAndContinue();
126
127 // Returns true if the required child is tracked by the parent entry, i.e. it
128 // was already created.
129 bool ChildPresent();
130
131 // Sets the bit for the current child to the provided |value|. In other words,
132 // starts or stops tracking this child.
133 void SetChildBit(bool value);
134
135 // Verify that the range to be accessed for the current child is appropriate.
136 // Returns false if an error is detected or there is no need to perform the
137 // current IO operation (for instance if the required range is not stored by
138 // the child).
139 bool VerifyRange();
140
141 // Updates the contents bitmap for the current range, based on the result of
142 // the current operation.
143 void UpdateRange(int result);
144
145 // Returns the number of bytes stored at |block_index|, if its allocation-bit
146 // is off (because it is not completely filled).
147 int PartialBlockLength(int block_index) const;
148
149 // Initializes the sparse info for the current child.
150 void InitChildData();
151
152 // Performs the required work for GetAvailableRange for one child.
153 int GetAvailableRangeImpl();
154
155 void LogChildOperationStart();
156 void LogChildOperationEnd(int result);
157 int LogCompletion(int result);
158
159 // Reports to the user that we are done.
160 void HandleResult(int result);
161 void HanldeAbortCallbacks();
162
163 // Invoked by the callback of asynchronous operations.
164 void OnIOComplete(int result);
165
166 EntryImplV3* entry_; // The sparse entry.
167 Entry* child_; // The current child entry.
168 SparseOperation operation_;
169 State next_state_;
170 bool init_;
171 bool range_found_; // True if GetAvailableRange found something.
172 bool abort_; // True if we should abort the current operation ASAP.
173 bool valid_;
174 bool closing_;
175
176 SparseHeader sparse_header_; // Data about the children of entry_.
177 Bitmap children_map_; // The actual bitmap of children.
178 SparseData child_data_; // Parent and allocation map of child_.
179 Bitmap child_map_; // The allocation map as a bitmap.
180
181 CompletionCallback user_callback_;
182 CompletionCallback callback_;
183 std::vector<CompletionCallback> abort_callbacks_;
184 int64 offset_; // Current sparse offset.
185 scoped_refptr<net::DrainableIOBuffer> user_buf_;
186 scoped_refptr<net::IOBuffer> buf_;
187 std::string key_;
188 int buf_len_; // Bytes to read or write.
189 int child_offset_; // Offset to use for the current child.
190 int child_len_; // Bytes to read or write for this child.
191 int result_;
192 int64* range_start_;
193
194 DISALLOW_COPY_AND_ASSIGN(SparseControlV3);
195 };
196
197 } // namespace disk_cache
198
199 #endif // NET_DISK_CACHE_V3_SPARSE_CONTROL_V3_H_
OLDNEW
« no previous file with comments | « net/disk_cache/v3/index_table_unittest.cc ('k') | net/disk_cache/v3/sparse_control_v3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698