OLD | NEW |
(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_NONE, |
| 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 }; |
| 60 |
| 61 enum Flags { |
| 62 WORK_FOR_DOOM = 1 << 0, |
| 63 WORK_FOR_RESURRECT = 1 << 1, |
| 64 WORK_FOR_EVICT = 1 << 2, |
| 65 WORK_NO_COPY = 1 << 3, // Don't copy old data on eviction. |
| 66 WORK_FOR_UPDATE = 1 << 4, |
| 67 WORK_FOR_ITERATION = 1 << 5, |
| 68 WORK_FOR_DOOM_RANGE = 1 << 6, |
| 69 WORK_COMPLETE = 1 << 7 |
| 70 }; |
| 71 |
| 72 explicit WorkItem(WorkType type); |
| 73 |
| 74 void Start(BackendImplV3::Worker* worker); |
| 75 void DoLoop(int result); |
| 76 void OnDone(); |
| 77 |
| 78 |
| 79 // Getters. |
| 80 WorkType type() const { return type_; } |
| 81 const net::CompletionCallback& user_callback() const { |
| 82 return user_callback_; |
| 83 } |
| 84 int result() const { return result_; } |
| 85 uint32 flags() const { return flags_; } |
| 86 scoped_ptr<InitResult> init_result() { return init_result_.Pass(); } |
| 87 EntrySet* entries() { return &entries_; } |
| 88 const std::string& key() const { return key_; } |
| 89 Entry** entry_buffer() { return entry_buffer_; } |
| 90 scoped_ptr<EntryRecord> entry_record() { return entry_record_.Pass(); } |
| 91 scoped_ptr<ShortEntryRecord> short_entry_record() { |
| 92 return short_entry_record_.Pass(); |
| 93 } |
| 94 EntryImplV3* owner_entry() { return owner_entry_.get(); } |
| 95 base::Time initial_time() const { return initial_time_; } |
| 96 base::Time end_time() const { return end_time_; } |
| 97 IndexIterator* iterator() { return iterator_.get(); } |
| 98 IndexIterator* ReleaseIterator() { return iterator_.release(); } |
| 99 void** iter_buffer() const { return iter_buffer_; } |
| 100 |
| 101 // Setters. |
| 102 void set_user_callback(const net::CompletionCallback& callback) { |
| 103 user_callback_ = callback; |
| 104 } |
| 105 void set_closure(const base::Callback<void(WorkItem*)>& closure) { |
| 106 closure_ = closure; |
| 107 } |
| 108 void set_flags(uint32 flags) { flags_ = flags; } |
| 109 void set_entries(EntrySet entries) { entries_ = entries; } |
| 110 void set_key(const std::string& key) { key_ = key; } |
| 111 void set_entry_buffer(Entry** entry_buffer) { entry_buffer_ = entry_buffer; } |
| 112 void set_buffer(net::IOBuffer* buffer) { buffer_ = buffer; } |
| 113 void set_buffer_len(int buffer_len) { buffer_len_ = buffer_len; } |
| 114 void set_address(Addr address) { address_ = address; } |
| 115 void set_address2(Addr address) { address2_ = address; } |
| 116 void set_offset(int offset) { offset_ = offset; } |
| 117 void set_owner_entry(EntryImplV3* entry) { owner_entry_ = entry; } |
| 118 void set_initial_time(base::Time time) { initial_time_ = time; } |
| 119 void set_end_time(base::Time time) { end_time_ = time; } |
| 120 void set_iterator(scoped_ptr<IndexIterator> iterator) { |
| 121 iterator_ = iterator.Pass(); |
| 122 } |
| 123 void set_iter_buffer(void** iter) { iter_buffer_ = iter; } |
| 124 |
| 125 private: |
| 126 friend class base::RefCountedThreadSafe<WorkItem>; |
| 127 |
| 128 enum State { |
| 129 STATE_NONE, |
| 130 STATE_OPEN_ENTRY, |
| 131 STATE_OPEN_ENTRY_COMPLETE, |
| 132 STATE_READ_KEY, |
| 133 STATE_READ_KEY_COMPLETE, |
| 134 STATE_READ_DATA, |
| 135 STATE_READ_DATA_COMPLETE, |
| 136 STATE_WRITE_DATA, |
| 137 STATE_WRITE_DATA_COMPLETE, |
| 138 STATE_MOVE_DATA, |
| 139 STATE_TRUNCATE_DATA, |
| 140 STATE_COPY_ENTRY, |
| 141 STATE_COPY_ENTRY_COMPLETE |
| 142 }; |
| 143 |
| 144 ~WorkItem(); |
| 145 |
| 146 void CompleteItem(int result); |
| 147 int DoOpenEntry(); |
| 148 int DoOpenEntryComplete(int result); |
| 149 int DoReadKey(); |
| 150 int DoReadKeyComplete(); |
| 151 int DoReadData(); |
| 152 int DoReadDataComplete(int result); |
| 153 int DoWriteData(); |
| 154 int DoWriteDataComplete(int result); |
| 155 int DoMoveData(); |
| 156 int DoTruncateData(); |
| 157 int DoCopyEntry(); |
| 158 int DoCopyEntryComplete(int result); |
| 159 |
| 160 int LoadEntryBlock(Addr address); |
| 161 int LoadShortEntryBlock(Addr address); |
| 162 |
| 163 WorkType type_; |
| 164 net::CompletionCallback user_callback_; |
| 165 base::Callback<void(WorkItem*)> closure_; |
| 166 int result_; |
| 167 scoped_refptr<BackendImplV3::Worker> worker_; |
| 168 State next_state_; |
| 169 |
| 170 // Init. |
| 171 uint32 flags_; |
| 172 scoped_ptr<InitResult> init_result_; |
| 173 |
| 174 // Open. |
| 175 EntrySet entries_; |
| 176 std::string key_; |
| 177 Entry** entry_buffer_; |
| 178 scoped_ptr<EntryRecord> entry_record_; |
| 179 scoped_ptr<ShortEntryRecord> short_entry_record_; |
| 180 scoped_ptr<CacheEntryBlockV3> entry_block_; |
| 181 scoped_ptr<CacheShortEntryBlock> short_entry_block_; |
| 182 |
| 183 // Read/Write. |
| 184 scoped_refptr<net::IOBuffer> buffer_; |
| 185 int buffer_len_; |
| 186 Addr address_; |
| 187 Addr address2_; |
| 188 int offset_; |
| 189 scoped_refptr<EntryImplV3> owner_entry_; |
| 190 |
| 191 // Iteration. |
| 192 base::Time initial_time_; |
| 193 base::Time end_time_; |
| 194 scoped_ptr<IndexIterator> iterator_; |
| 195 void** iter_buffer_; |
| 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(WorkItem); |
| 198 }; |
| 199 |
| 200 } // namespace disk_cache |
| 201 |
| 202 #endif // NET_DISK_CACHE_V3_BACKEND_WORK_ITEM_H_ |
OLD | NEW |