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_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/timer.h" | |
19 #include "net/base/net_export.h" | 20 #include "net/base/net_export.h" |
20 | 21 |
21 class Pickle; | 22 class Pickle; |
22 class PickleIterator; | 23 class PickleIterator; |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 class TaskRunner; | 26 class TaskRunner; |
26 } | 27 } |
27 | 28 |
28 namespace disk_cache { | 29 namespace disk_cache { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 | 97 |
97 // TODO(felipeg): This way we are storing the hash_key twice, as the | 98 // TODO(felipeg): This way we are storing the hash_key twice, as the |
98 // hash_map::key and as a member of EntryMetadata. We could save space if we | 99 // hash_map::key and as a member of EntryMetadata. We could save space if we |
99 // use a hash_set. | 100 // use a hash_set. |
100 typedef base::hash_map<uint64, EntryMetadata> EntrySet; | 101 typedef base::hash_map<uint64, EntryMetadata> EntrySet; |
101 | 102 |
102 static void InsertInEntrySet(const EntryMetadata& entry_metadata, | 103 static void InsertInEntrySet(const EntryMetadata& entry_metadata, |
103 EntrySet* entry_set); | 104 EntrySet* entry_set); |
104 | 105 |
105 private: | 106 private: |
106 typedef base::Callback<void(scoped_ptr<EntrySet>)> IndexCompletionCallback; | 107 typedef base::Callback<void(scoped_ptr<EntrySet>, bool must_write_to_disk)> |
gavinp
2013/04/17 07:54:41
Maybe: force_index_flush ?
felipeg
2013/04/17 15:01:48
Done.
| |
108 IndexCompletionCallback; | |
109 | |
110 void PostponeWriteToDisk(); | |
gavinp
2013/04/17 07:54:41
naming: PostponeWritingToDisk ?
felipeg
2013/04/17 15:01:48
Done.
| |
107 | 111 |
108 static void LoadFromDisk( | 112 static void LoadFromDisk( |
109 const base::FilePath& index_filename, | 113 const base::FilePath& index_filename, |
110 const scoped_refptr<base::TaskRunner>& io_thread, | 114 const scoped_refptr<base::TaskRunner>& io_thread, |
111 const IndexCompletionCallback& completion_callback); | 115 const IndexCompletionCallback& completion_callback); |
112 | 116 |
113 // Enumerates all entries' files on disk and regenerates the index. | 117 // Enumerates all entries' files on disk and regenerates the index. |
114 static scoped_ptr<SimpleIndex::EntrySet> RestoreFromDisk( | 118 static scoped_ptr<SimpleIndex::EntrySet> RestoreFromDisk( |
115 const base::FilePath& index_filename); | 119 const base::FilePath& index_filename); |
116 | 120 |
117 static void WriteToDiskInternal(const base::FilePath& index_filename, | 121 static void WriteToDiskInternal(const base::FilePath& index_filename, |
118 scoped_ptr<Pickle> pickle); | 122 scoped_ptr<Pickle> pickle); |
119 | 123 |
120 // Must run on IO Thread. | 124 // Must run on IO Thread. |
121 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries); | 125 void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries, |
126 bool must_write_to_disk); | |
122 | 127 |
123 EntrySet entries_set_; | 128 EntrySet entries_set_; |
124 uint64 cache_size_; // Total cache storage size in bytes. | 129 uint64 cache_size_; // Total cache storage size in bytes. |
125 | 130 |
126 // This stores all the hash_key of entries that are removed during | 131 // This stores all the hash_key of entries that are removed during |
127 // initialization. | 132 // initialization. |
128 base::hash_set<uint64> removed_entries_; | 133 base::hash_set<uint64> removed_entries_; |
129 bool initialized_; | 134 bool initialized_; |
130 | 135 |
131 base::FilePath index_filename_; | 136 base::FilePath index_filename_; |
132 | 137 |
133 scoped_refptr<base::TaskRunner> cache_thread_; | 138 scoped_refptr<base::TaskRunner> cache_thread_; |
134 scoped_refptr<base::TaskRunner> io_thread_; | 139 scoped_refptr<base::TaskRunner> io_thread_; |
135 | 140 |
136 // All nonstatic SimpleEntryImpl methods should always be called on the IO | 141 // All nonstatic SimpleEntryImpl methods should always be called on the IO |
137 // thread, in all cases. |io_thread_checker_| documents and enforces this. | 142 // thread, in all cases. |io_thread_checker_| documents and enforces this. |
138 base::ThreadChecker io_thread_checker_; | 143 base::ThreadChecker io_thread_checker_; |
144 | |
145 base::OneShotTimer<SimpleIndex> write_to_disk_timer_; | |
139 }; | 146 }; |
140 | 147 |
141 } // namespace disk_cache | 148 } // namespace disk_cache |
142 | 149 |
143 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ | 150 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_H_ |
OLD | NEW |