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

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