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

Side by Side Diff: net/disk_cache/v3/backend_work_item.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: Created 7 years, 6 months 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/backend_impl_v3.cc ('k') | net/disk_cache/v3/backend_work_item.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_BACKEND_WORK_ITEM_H_
6 #define NET_DISK_CACHE_V3_BACKEND_WORK_ITEM_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "net/base/completion_callback.h"
15 #include "net/base/io_buffer.h"
16 #include "net/disk_cache/storage_block.h"
17 #include "net/disk_cache/v3/backend_impl_v3.h"
18 #include "net/disk_cache/v3/entry_impl_v3.h"
19
20 namespace disk_cache {
21
22 struct EntryRecord;
23 struct EntrySet;
24 struct IndexBitmap;
25 struct IndexBucket;
26 struct IndexHeaderV3;
27 typedef StorageBlock<EntryRecord> CacheEntryBlockV3;
28 typedef StorageBlock<ShortEntryRecord> CacheShortEntryBlock;
29
30 struct InitResult {
31 // The index:
32 IndexBitmap* index_bitmap;
33 IndexBucket* main_table;
34 IndexBucket* extra_table;
35 scoped_ptr<IndexHeaderV3> backup_header;
36 scoped_ptr<uint32[]> backup_bitmap;
37 // Block files:
38 BlockFilesBitmaps block_bitmaps;
39 // Stats:
40 scoped_ptr<char[]> stats_data;
41 };
42
43 class BackendImplV3::WorkItem : public base::RefCountedThreadSafe<WorkItem> {
44 public:
45 enum WorkType {
46 WORK_INIT,
47 WORK_CLEANUP,
48 WORK_RESTART,
49 WORK_GROW_INDEX,
50 WORK_GROW_FILES,
51 WORK_WRITE_INDEX,
52 WORK_OPEN_ENTRY,
53 WORK_READ_DATA,
54 WORK_WRITE_DATA,
55 WORK_MOVE_DATA,
56 WORK_TRUNCATE,
57 WORK_DELETE,
58 WORK_CLOSE,
59 WORK_NONE
60 };
61
62 enum Flags {
63 WORK_FOR_DOOM = 1 << 0,
64 WORK_FOR_RESURRECT = 1 << 1,
65 WORK_FOR_EVICT = 1 << 2,
66 WORK_NO_COPY = 1 << 3, // Don't copy old data on eviction.
67 WORK_FOR_UPDATE = 1 << 4,
68 WORK_FOR_ITERATION = 1 << 5,
69 WORK_FOR_DOOM_RANGE = 1 << 6,
70 WORK_COMPLETE = 1 << 7
71 };
72
73 explicit WorkItem(WorkType type);
74
75 void Start(BackendImplV3::Worker* worker);
76 void DoLoop(int result);
77 void OnDone();
78
79
80 // Getters.
81 WorkType type() const { return type_; }
82 const net::CompletionCallback& user_callback() const {
83 return user_callback_;
84 }
85 int result() const { return result_; }
86 uint32 flags() const { return flags_; }
87 scoped_ptr<InitResult> init_result() { return init_result_.Pass(); }
88 EntrySet* entries() { return &entries_; }
89 const std::string& key() const { return key_; }
90 Entry** entry_buffer() { return entry_buffer_; }
91 scoped_ptr<EntryRecord> entry_record() { return entry_record_.Pass(); }
92 scoped_ptr<ShortEntryRecord> short_entry_record() {
93 return short_entry_record_.Pass();
94 }
95 EntryImplV3* owner_entry() { return owner_entry_.get(); }
96 base::Time initial_time() const { return initial_time_; }
97 base::Time end_time() const { return end_time_; }
98 IndexIterator* iterator() { return iterator_.get(); }
99 IndexIterator* ReleaseIterator() { return iterator_.release(); }
100 void** iter_buffer() const { return iter_buffer_; }
101
102 // Setters.
103 void set_user_callback(const net::CompletionCallback& callback) {
104 user_callback_ = callback;
105 }
106 void set_closure(const base::Callback<void(WorkItem*)>& closure) {
107 closure_ = closure;
108 }
109 void set_flags(uint32 flags) { flags_ = flags; }
110 void set_entries(EntrySet entries) { entries_ = entries; }
111 void set_key(const std::string& key) { key_ = key; }
112 void set_entry_buffer(Entry** entry_buffer) { entry_buffer_ = entry_buffer; }
113 void set_buffer(net::IOBuffer* buffer) { buffer_ = buffer; }
114 void set_buffer_len(int buffer_len) { buffer_len_ = buffer_len; }
115 void set_address(Addr address) { address_ = address; }
116 void set_address2(Addr address) { address2_ = address; }
117 void set_offset(int offset) { offset_ = offset; }
118 void set_owner_entry(EntryImplV3* entry) { owner_entry_ = entry; }
119 void set_initial_time(base::Time time) { initial_time_ = time; }
120 void set_end_time(base::Time time) { end_time_ = time; }
121 void set_iterator(scoped_ptr<IndexIterator> iterator) {
122 iterator_ = iterator.Pass();
123 }
124 void set_iter_buffer(void** iter) { iter_buffer_ = iter; }
125
126 private:
127 friend class base::RefCountedThreadSafe<WorkItem>;
128
129 enum State {
130 STATE_NONE,
131 STATE_OPEN_ENTRY,
132 STATE_OPEN_ENTRY_COMPLETE,
133 STATE_READ_KEY,
134 STATE_READ_KEY_COMPLETE,
135 STATE_READ_DATA,
136 STATE_READ_DATA_COMPLETE,
137 STATE_WRITE_DATA,
138 STATE_WRITE_DATA_COMPLETE,
139 STATE_MOVE_DATA,
140 STATE_TRUNCATE_DATA,
141 STATE_COPY_ENTRY,
142 STATE_COPY_ENTRY_COMPLETE
143 };
144
145 ~WorkItem();
146
147 void CompleteItem(int result);
148 int DoOpenEntry();
149 int DoOpenEntryComplete(int result);
150 int DoReadKey();
151 int DoReadKeyComplete();
152 int DoReadData();
153 int DoReadDataComplete(int result);
154 int DoWriteData();
155 int DoWriteDataComplete(int result);
156 int DoMoveData();
157 int DoTruncateData();
158 int DoCopyEntry();
159 int DoCopyEntryComplete(int result);
160
161 int LoadEntryBlock(Addr address);
162 int LoadShortEntryBlock(Addr address);
163
164 WorkType type_;
165 net::CompletionCallback user_callback_;
166 base::Callback<void(WorkItem*)> closure_;
167 int result_;
168 scoped_refptr<BackendImplV3::Worker> worker_;
169 State next_state_;
170
171 // Init.
172 uint32 flags_;
173 scoped_ptr<InitResult> init_result_;
174
175 // Open.
176 EntrySet entries_;
177 std::string key_;
178 Entry** entry_buffer_;
179 scoped_ptr<EntryRecord> entry_record_;
180 scoped_ptr<ShortEntryRecord> short_entry_record_;
181 scoped_ptr<CacheEntryBlockV3> entry_block_;
182 scoped_ptr<CacheShortEntryBlock> short_entry_block_;
183
184 // Read/Write.
185 scoped_refptr<net::IOBuffer> buffer_;
186 int buffer_len_;
187 Addr address_;
188 Addr address2_;
189 int offset_;
190 scoped_refptr<EntryImplV3> owner_entry_;
191
192 // Iteration.
193 base::Time initial_time_;
194 base::Time end_time_;
195 scoped_ptr<IndexIterator> iterator_;
196 void** iter_buffer_;
197
198 DISALLOW_COPY_AND_ASSIGN(WorkItem);
199 };
200
201 } // namespace disk_cache
202
203 #endif // NET_DISK_CACHE_V3_BACKEND_WORK_ITEM_H_
OLDNEW
« no previous file with comments | « net/disk_cache/v3/backend_impl_v3.cc ('k') | net/disk_cache/v3/backend_work_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698