 Chromium Code Reviews
 Chromium Code Reviews Issue 13839011:
  Asynchronous initialization in Simple Index.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 13839011:
  Asynchronous initialization in Simple Index.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: net/disk_cache/simple/simple_index.h | 
| diff --git a/net/disk_cache/simple/simple_index.h b/net/disk_cache/simple/simple_index.h | 
| index f07476d2409d41988bbeba0dd91b1bc27f540ec6..154bdde6d4e5d0c7588aa7975eb94b0666ed7589 100644 | 
| --- a/net/disk_cache/simple/simple_index.h | 
| +++ b/net/disk_cache/simple/simple_index.h | 
| @@ -29,12 +29,12 @@ class SimpleIndex | 
| public: | 
| SimpleIndex( | 
| const scoped_refptr<base::TaskRunner>& cache_thread, | 
| + const scoped_refptr<base::TaskRunner>& io_thread, | 
| const base::FilePath& path); | 
| virtual ~SimpleIndex(); | 
| - // Should be called on CacheThread. | 
| - bool Initialize(); | 
| + void Initialize(); | 
| void Insert(const std::string& key); | 
| void Remove(const std::string& key); | 
| @@ -45,7 +45,7 @@ class SimpleIndex | 
| // iff the entry exist in the index. | 
| bool UseIfExists(const std::string& key); | 
| - void Cleanup(); | 
| + void WriteToDisk(); | 
| bool UpdateEntrySize(const std::string& key, uint64 entry_size); | 
| @@ -56,10 +56,18 @@ class SimpleIndex | 
| // EntryMetadata itself. | 
| typedef base::hash_map<std::string, SimpleIndexFile::EntryMetadata> EntrySet; | 
| - void InsertInternal(const SimpleIndexFile::EntryMetadata& entry_metadata); | 
| + static void InsertInternal( | 
| + EntrySet* entry_set, | 
| + const SimpleIndexFile::EntryMetadata& entry_metadata); | 
| + | 
| + // Load index file from disk, if file is corrupted it calls RestoreFromDisk(). | 
| 
gavinp
2013/04/10 11:45:44
Suggestion: // Load index from disk. If it is corr
 
felipeg
2013/04/10 14:21:45
Done.
 | 
| + void LoadFromDisk(); | 
| // Enumerates all entries' files on disk and regenerates the index. | 
| - bool RestoreFromDisk(); | 
| + void RestoreFromDisk(); | 
| + | 
| + // Must run on IO Thread. | 
| + void MergeInitializingSet(); | 
| // |out_buffer| needs to be pre-allocated. The serialized index is stored in | 
| // |out_buffer|. | 
| @@ -77,13 +85,22 @@ class SimpleIndex | 
| EntrySet entries_set_; | 
| uint64 cache_size_; // Total cache storage size in bytes. | 
| + // These sets are only used during initialization phase. | 
| + // They are merged back in the entries_set_ once it finishes. | 
| + EntrySet initializing_set_; | 
| + // This stores all the hash_key of entries that are removed during | 
| + // initialization. | 
| + base::hash_set<std::string> removals_set_; | 
| + bool initialized_; | 
| + | 
| base::FilePath index_filename_; | 
| base::PlatformFile index_file_; | 
| // We keep the thread from where Initialize() method has been called so that | 
| - // we run the Cleanup method in the same thread. Usually that should be the | 
| - // CacheThread. | 
| + // we run the WriteToDisk method in the same thread. Usually that should be | 
| + // the Cache Thread. | 
| scoped_refptr<base::TaskRunner> cache_thread_; | 
| + scoped_refptr<base::TaskRunner> io_thread_; | 
| }; | 
| } // namespace disk_cache |