| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 5 #ifndef NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
| 6 #define NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
| 6 | 7 |
| 7 #ifndef NET_DISK_CACHE_BACKEND_IMPL_H_ | 8 #include "base/basictypes.h" |
| 8 #define NET_DISK_CACHE_BACKEND_IMPL_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" |
| 9 | 16 |
| 10 #include "base/containers/hash_tables.h" | 17 #include <map> |
| 11 #include "base/files/file_path.h" | 18 |
| 12 #include "base/timer/timer.h" | 19 namespace base { |
| 13 #include "net/disk_cache/block_files.h" | 20 class MessageLoopProxy; |
| 14 #include "net/disk_cache/disk_cache.h" | 21 } |
| 15 #include "net/disk_cache/eviction.h" | |
| 16 #include "net/disk_cache/in_flight_backend_io.h" | |
| 17 #include "net/disk_cache/rankings.h" | |
| 18 #include "net/disk_cache/stats.h" | |
| 19 #include "net/disk_cache/stress_support.h" | |
| 20 #include "net/disk_cache/trace.h" | |
| 21 | 22 |
| 22 namespace disk_cache { | 23 namespace disk_cache { |
| 23 | 24 |
| 24 // This class implements the Backend interface. An object of this | 25 class File; |
| 25 // class handles the operations of the cache for a particular profile. | 26 struct InitResult; |
| 26 class NET_EXPORT_PRIVATE BackendImpl : public Backend { | 27 class MappedFile; |
| 27 friend class Eviction; | 28 |
| 29 class BackendImplV3::Worker : public base::RefCountedThreadSafe<Worker> { |
| 28 public: | 30 public: |
| 29 BackendImpl(const base::FilePath& path, base::MessageLoopProxy* cache_thread, | 31 Worker(const base::FilePath& path, base::MessageLoopProxy* main_thread); |
| 30 net::NetLog* net_log); | |
| 31 | 32 |
| 32 // Performs general initialization for this current instance of the cache. | 33 // Construction and destruction helpers. |
| 33 int Init(const CompletionCallback& callback); | 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 disk_cache::File* GetBackupIndexFile(); |
| 53 void CloseBackupIndexFile(); |
| 54 |
| 55 bool IsValid(); |
| 56 |
| 57 // Timer notification. |
| 58 void OnTimer(); |
| 34 | 59 |
| 35 private: | 60 private: |
| 36 void CleanupCache(); | 61 friend class base::RefCountedThreadSafe<Worker>; |
| 62 typedef std::map<uint32, scoped_refptr<disk_cache::File>> FilesMap; |
| 37 | 63 |
| 38 // Returns the full name for an external storage file. | 64 ~Worker(); |
| 65 void Cleanup(WorkItem* work_item); |
| 66 void CloseFiles(); |
| 67 |
| 68 disk_cache::File* GetExternalFile(Addr address, bool for_write); |
| 39 base::FilePath GetFileName(Addr address) const; | 69 base::FilePath GetFileName(Addr address) const; |
| 40 | 70 |
| 41 // Creates a new backing file for the cache index. | |
| 42 bool CreateBackingStore(disk_cache::File* file); | 71 bool CreateBackingStore(disk_cache::File* file); |
| 72 bool CreateExtraTable(int extra_len); |
| 43 bool InitBackingStore(bool* file_created); | 73 bool InitBackingStore(bool* file_created); |
| 74 bool LoadIndex(InitResult* init_result); |
| 75 bool CheckIndexFile(MappedFile* file); |
| 76 bool InitStats(IndexHeaderV3* index, InitResult* result); |
| 77 int GrowDone(); |
| 44 | 78 |
| 45 // Reports an uncommon, recoverable error. | 79 base::FilePath path_; |
| 46 void ReportError(int error); | 80 scoped_refptr<base::MessageLoopProxy> main_thread_; |
| 81 scoped_refptr<MappedFile> index_header_; |
| 82 scoped_refptr<MappedFile> main_table_; |
| 83 scoped_refptr<MappedFile> extra_table_; |
| 84 scoped_refptr<MappedFile> index_backup_; |
| 85 scoped_ptr<BlockFiles> block_files_; |
| 86 FilesMap files_; |
| 87 WorkItem* cleanup_work_item_; |
| 47 | 88 |
| 48 // Performs basic checks on the index file. Returns false on failure. | 89 // Valid while growing files: |
| 49 bool CheckIndex(); | 90 scoped_refptr<MappedFile> big_index_header_; |
| 91 scoped_refptr<MappedFile> big_main_table_; |
| 92 scoped_refptr<MappedFile> big_extra_table_; |
| 93 scoped_refptr<MappedFile> big_extra_temp_table_; |
| 94 scoped_ptr<BlockFiles> big_block_files_; |
| 50 | 95 |
| 51 base::FilePath path_; // Path to the folder used as backing storage. | 96 bool init_; |
| 52 BlockFiles block_files_; // Set of files used to store all data. | 97 bool doubling_index_; // The index is being doubled in size; |
| 53 bool init_; // controls the initialization of the system. | 98 uint32 user_flags_; |
| 54 | 99 |
| 55 DISALLOW_COPY_AND_ASSIGN(BackendImpl); | 100 DISALLOW_COPY_AND_ASSIGN(Worker); |
| 56 }; | 101 }; |
| 57 | 102 |
| 58 } // namespace disk_cache | 103 } // namespace disk_cache |
| 59 | 104 |
| 60 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 105 #endif // NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
| OLD | NEW |