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_WORKER_H_ |
| 6 #define NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/files/file_path.h" |
| 13 #include "net/disk_cache/Addr.h" |
| 14 #include "net/disk_cache/block_files.h" |
| 15 #include "net/disk_cache/v3/backend_impl_v3.h" |
| 16 |
| 17 #include <map> |
| 18 |
| 19 namespace base { |
| 20 class MessageLoopProxy; |
| 21 } |
| 22 |
| 23 namespace disk_cache { |
| 24 |
| 25 class File; |
| 26 struct InitResult; |
| 27 class MappedFile; |
| 28 |
| 29 class BackendImplV3::Worker : public base::RefCountedThreadSafe<Worker> { |
| 30 public: |
| 31 Worker(const base::FilePath& path, base::MessageLoopProxy* main_thread); |
| 32 |
| 33 // Construction and destruction helpers. |
| 34 int Init(uint32 flags, scoped_ptr<InitResult>* result); |
| 35 int Restart(uint32 flags, scoped_ptr<InitResult>* result); |
| 36 |
| 37 int GrowIndex(uint32 flags, scoped_ptr<InitResult>* result); |
| 38 int GrowFiles(uint32 flags, scoped_ptr<InitResult>* result); |
| 39 |
| 40 int Delete(Addr address); |
| 41 int Close(Addr address); |
| 42 |
| 43 void OnDoWork(WorkItem* work_item); |
| 44 void DoneWithItem(WorkItem* work_item); |
| 45 |
| 46 MappedFile* GetMappedFile(Addr address) { |
| 47 return block_files_->GetFile(address); |
| 48 } |
| 49 |
| 50 disk_cache::File* GetBackingFile(Addr address, bool for_write); |
| 51 |
| 52 bool IsValid(); |
| 53 |
| 54 // Timer notification. |
| 55 void OnTimer(); |
| 56 |
| 57 private: |
| 58 friend class base::RefCountedThreadSafe<Worker>; |
| 59 typedef std::map<uint32, scoped_refptr<disk_cache::File>> FilesMap; |
| 60 |
| 61 ~Worker(); |
| 62 void Cleanup(WorkItem* work_item); |
| 63 void CloseFiles(); |
| 64 |
| 65 disk_cache::File* GetExternalFile(Addr address, bool for_write); |
| 66 base::FilePath GetFileName(Addr address) const; |
| 67 |
| 68 bool CreateBackingStore(disk_cache::File* file); |
| 69 bool CreateExtraTable(int extra_len); |
| 70 bool InitBackingStore(bool* file_created); |
| 71 bool LoadIndex(InitResult* init_result); |
| 72 bool CheckIndexFile(MappedFile* file); |
| 73 bool InitStats(IndexHeaderV3* index, InitResult* result); |
| 74 int GrowDone(); |
| 75 |
| 76 base::FilePath path_; |
| 77 scoped_refptr<base::MessageLoopProxy> main_thread_; |
| 78 scoped_refptr<MappedFile> index_header_; |
| 79 scoped_refptr<MappedFile> main_table_; |
| 80 scoped_refptr<MappedFile> extra_table_; |
| 81 scoped_refptr<MappedFile> index_backup_; |
| 82 scoped_ptr<BlockFiles> block_files_; |
| 83 FilesMap files_; |
| 84 WorkItem* cleanup_work_item_; |
| 85 |
| 86 // Valid while growing files: |
| 87 scoped_refptr<MappedFile> big_index_header_; |
| 88 scoped_refptr<MappedFile> big_main_table_; |
| 89 scoped_refptr<MappedFile> big_extra_table_; |
| 90 scoped_refptr<MappedFile> big_extra_temp_table_; |
| 91 scoped_ptr<BlockFiles> big_block_files_; |
| 92 |
| 93 bool init_; |
| 94 bool doubling_index_; // The index is being doubled in size; |
| 95 uint32 user_flags_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(Worker); |
| 98 }; |
| 99 |
| 100 } // namespace disk_cache |
| 101 |
| 102 #endif // NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
OLD | NEW |