OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 bool app_on_background); | 90 bool app_on_background); |
91 | 91 |
92 // Doom the entries specified in |entry_hashes|, calling |reply_callback| | 92 // Doom the entries specified in |entry_hashes|, calling |reply_callback| |
93 // with the result on the current thread when done. | 93 // with the result on the current thread when done. |
94 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes, | 94 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes, |
95 const base::Callback<void(int)>& reply_callback); | 95 const base::Callback<void(int)>& reply_callback); |
96 | 96 |
97 private: | 97 private: |
98 friend class WrappedSimpleIndexFile; | 98 friend class WrappedSimpleIndexFile; |
99 | 99 |
100 // Used for cache directory traversal. | |
101 typedef base::Callback<void (const base::FilePath&)> EntryFileCallback; | |
102 | |
100 // When loading the entries from disk, add this many extra hash buckets to | 103 // When loading the entries from disk, add this many extra hash buckets to |
101 // prevent reallocation on the IO thread when merging in new live entries. | 104 // prevent reallocation on the IO thread when merging in new live entries. |
102 static const int kExtraSizeForMerge = 512; | 105 static const int kExtraSizeForMerge = 512; |
103 | 106 |
104 // Synchronous (IO performing) implementation of LoadIndexEntries. | 107 // Synchronous (IO performing) implementation of LoadIndexEntries. |
105 static void SyncLoadIndexEntries(base::Time cache_last_modified, | 108 static void SyncLoadIndexEntries(base::Time cache_last_modified, |
106 const base::FilePath& cache_directory, | 109 const base::FilePath& cache_directory, |
107 const base::FilePath& index_file_path, | 110 const base::FilePath& index_file_path, |
108 SimpleIndexLoadResult* out_result); | 111 SimpleIndexLoadResult* out_result); |
109 | 112 |
110 // Load the index file from disk returning an EntrySet. Upon failure, returns | 113 // Load the index file from disk returning an EntrySet. Upon failure, returns |
111 // NULL. | 114 // NULL. |
112 static void SyncLoadFromDisk(const base::FilePath& index_filename, | 115 static void SyncLoadFromDisk(const base::FilePath& index_filename, |
113 SimpleIndexLoadResult* out_result); | 116 SimpleIndexLoadResult* out_result); |
114 | 117 |
115 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized | 118 // Returns a scoped_ptr for a newly allocated Pickle containing the serialized |
116 // data to be written to a file. | 119 // data to be written to a file. |
117 static scoped_ptr<Pickle> Serialize( | 120 static scoped_ptr<Pickle> Serialize( |
118 const SimpleIndexFile::IndexMetadata& index_metadata, | 121 const SimpleIndexFile::IndexMetadata& index_metadata, |
119 const SimpleIndex::EntrySet& entries); | 122 const SimpleIndex::EntrySet& entries); |
120 | 123 |
121 // Given the contents of an index file |data| of length |data_len|, returns | 124 // Given the contents of an index file |data| of length |data_len|, returns |
122 // the corresponding EntrySet. Returns NULL on error. | 125 // the corresponding EntrySet. Returns NULL on error. |
123 static void Deserialize(const char* data, int data_len, | 126 static void Deserialize(const char* data, |
127 int data_len, | |
gavinp
2013/08/21 15:31:58
Nit: don't do this change. It's acceptable for clo
Philippe
2013/08/21 15:37:50
Done.
| |
124 SimpleIndexLoadResult* out_result); | 128 SimpleIndexLoadResult* out_result); |
125 | 129 |
130 // Implemented either in simple_index_file_posix.cc or | |
131 // simple_index_file_win.cc. base::FileEnumerator turned out to be very | |
132 // expensive in terms of memory usage therefore it's used only on non-POSIX | |
133 // environments for convenience (for now). Returns whether the traversal | |
134 // succeeded. | |
135 static bool TraverseCacheDirectory( | |
136 const base::FilePath& cache_path, | |
137 const EntryFileCallback& entry_file_callback); | |
138 | |
126 // Scan the index directory for entries, returning an EntrySet of all entries | 139 // Scan the index directory for entries, returning an EntrySet of all entries |
127 // found. | 140 // found. |
128 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, | 141 static void SyncRestoreFromDisk(const base::FilePath& cache_directory, |
129 const base::FilePath& index_file_path, | 142 const base::FilePath& index_file_path, |
130 SimpleIndexLoadResult* out_result); | 143 SimpleIndexLoadResult* out_result); |
131 | 144 |
132 // Determines if an index file is stale relative to the time of last | 145 // Determines if an index file is stale relative to the time of last |
133 // modification of the cache directory. | 146 // modification of the cache directory. |
134 static bool IsIndexFileStale(base::Time cache_last_modified, | 147 static bool IsIndexFileStale(base::Time cache_last_modified, |
135 const base::FilePath& index_file_path); | 148 const base::FilePath& index_file_path); |
136 | 149 |
137 struct PickleHeader : public Pickle::Header { | 150 struct PickleHeader : public Pickle::Header { |
138 uint32 crc; | 151 uint32 crc; |
139 }; | 152 }; |
140 | 153 |
141 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 154 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
142 const scoped_refptr<base::TaskRunner> worker_pool_; | 155 const scoped_refptr<base::TaskRunner> worker_pool_; |
143 const base::FilePath cache_directory_; | 156 const base::FilePath cache_directory_; |
144 const base::FilePath index_file_; | 157 const base::FilePath index_file_; |
145 const base::FilePath temp_index_file_; | 158 const base::FilePath temp_index_file_; |
146 | 159 |
147 static const char kIndexFileName[]; | |
148 static const char kTempIndexFileName[]; | |
149 | |
150 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); | 160 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); |
151 }; | 161 }; |
152 | 162 |
153 | 163 |
154 } // namespace disk_cache | 164 } // namespace disk_cache |
155 | 165 |
156 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ | 166 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ |
OLD | NEW |