Index: net/disk_cache/v3/backend_worker.h |
=================================================================== |
--- net/disk_cache/v3/backend_worker.h (revision 232523) |
+++ net/disk_cache/v3/backend_worker.h (working copy) |
@@ -2,59 +2,104 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// See net/disk_cache/disk_cache.h for the public interface of the cache. |
+#ifndef NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
+#define NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |
-#ifndef NET_DISK_CACHE_BACKEND_IMPL_H_ |
-#define NET_DISK_CACHE_BACKEND_IMPL_H_ |
- |
-#include "base/containers/hash_tables.h" |
+#include "base/basictypes.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "base/files/file_path.h" |
-#include "base/timer/timer.h" |
+#include "net/disk_cache/Addr.h" |
#include "net/disk_cache/block_files.h" |
-#include "net/disk_cache/disk_cache.h" |
-#include "net/disk_cache/eviction.h" |
-#include "net/disk_cache/in_flight_backend_io.h" |
-#include "net/disk_cache/rankings.h" |
-#include "net/disk_cache/stats.h" |
-#include "net/disk_cache/stress_support.h" |
-#include "net/disk_cache/trace.h" |
+#include "net/disk_cache/v3/backend_impl_v3.h" |
+#include <map> |
+ |
+namespace base { |
+class MessageLoopProxy; |
+} |
+ |
namespace disk_cache { |
-// This class implements the Backend interface. An object of this |
-// class handles the operations of the cache for a particular profile. |
-class NET_EXPORT_PRIVATE BackendImpl : public Backend { |
- friend class Eviction; |
+class File; |
+struct InitResult; |
+class MappedFile; |
+ |
+class BackendImplV3::Worker : public base::RefCountedThreadSafe<Worker> { |
public: |
- BackendImpl(const base::FilePath& path, base::MessageLoopProxy* cache_thread, |
- net::NetLog* net_log); |
+ Worker(const base::FilePath& path, base::MessageLoopProxy* main_thread); |
- // Performs general initialization for this current instance of the cache. |
- int Init(const CompletionCallback& callback); |
+ // Construction and destruction helpers. |
+ int Init(uint32 flags, scoped_ptr<InitResult>* result); |
+ int Restart(uint32 flags, scoped_ptr<InitResult>* result); |
+ int GrowIndex(uint32 flags, scoped_ptr<InitResult>* result); |
+ int GrowFiles(uint32 flags, scoped_ptr<InitResult>* result); |
+ |
+ int Delete(Addr address); |
+ int Close(Addr address); |
+ |
+ void OnDoWork(WorkItem* work_item); |
+ void DoneWithItem(WorkItem* work_item); |
+ |
+ MappedFile* GetMappedFile(Addr address) { |
+ return block_files_->GetFile(address); |
+ } |
+ |
+ disk_cache::File* GetBackingFile(Addr address, bool for_write); |
+ |
+ disk_cache::File* GetBackupIndexFile(); |
+ void CloseBackupIndexFile(); |
+ |
+ bool IsValid(); |
+ |
+ // Timer notification. |
+ void OnTimer(); |
+ |
private: |
- void CleanupCache(); |
+ friend class base::RefCountedThreadSafe<Worker>; |
+ typedef std::map<uint32, scoped_refptr<disk_cache::File>> FilesMap; |
- // Returns the full name for an external storage file. |
+ ~Worker(); |
+ void Cleanup(WorkItem* work_item); |
+ void CloseFiles(); |
+ |
+ disk_cache::File* GetExternalFile(Addr address, bool for_write); |
base::FilePath GetFileName(Addr address) const; |
- // Creates a new backing file for the cache index. |
bool CreateBackingStore(disk_cache::File* file); |
+ bool CreateExtraTable(int extra_len); |
bool InitBackingStore(bool* file_created); |
+ bool LoadIndex(InitResult* init_result); |
+ bool CheckIndexFile(MappedFile* file); |
+ bool InitStats(IndexHeaderV3* index, InitResult* result); |
+ int GrowDone(); |
- // Reports an uncommon, recoverable error. |
- void ReportError(int error); |
+ base::FilePath path_; |
+ scoped_refptr<base::MessageLoopProxy> main_thread_; |
+ scoped_refptr<MappedFile> index_header_; |
+ scoped_refptr<MappedFile> main_table_; |
+ scoped_refptr<MappedFile> extra_table_; |
+ scoped_refptr<MappedFile> index_backup_; |
+ scoped_ptr<BlockFiles> block_files_; |
+ FilesMap files_; |
+ WorkItem* cleanup_work_item_; |
- // Performs basic checks on the index file. Returns false on failure. |
- bool CheckIndex(); |
+ // Valid while growing files: |
+ scoped_refptr<MappedFile> big_index_header_; |
+ scoped_refptr<MappedFile> big_main_table_; |
+ scoped_refptr<MappedFile> big_extra_table_; |
+ scoped_refptr<MappedFile> big_extra_temp_table_; |
+ scoped_ptr<BlockFiles> big_block_files_; |
- base::FilePath path_; // Path to the folder used as backing storage. |
- BlockFiles block_files_; // Set of files used to store all data. |
- bool init_; // controls the initialization of the system. |
+ bool init_; |
+ bool doubling_index_; // The index is being doubled in size; |
+ uint32 user_flags_; |
- DISALLOW_COPY_AND_ASSIGN(BackendImpl); |
+ DISALLOW_COPY_AND_ASSIGN(Worker); |
}; |
} // namespace disk_cache |
-#endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
+#endif // NET_DISK_CACHE_V3_BACKEND_WORKER_H_ |