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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Get all add hash prefixes and full-length hashes, respectively, from | 136 // Get all add hash prefixes and full-length hashes, respectively, from |
137 // the store. | 137 // the store. |
138 virtual bool GetAddPrefixes(SBAddPrefixes* add_prefixes) OVERRIDE; | 138 virtual bool GetAddPrefixes(SBAddPrefixes* add_prefixes) OVERRIDE; |
139 virtual bool GetAddFullHashes( | 139 virtual bool GetAddFullHashes( |
140 std::vector<SBAddFullHash>* add_full_hashes) OVERRIDE; | 140 std::vector<SBAddFullHash>* add_full_hashes) OVERRIDE; |
141 | 141 |
142 virtual bool BeginChunk() OVERRIDE; | 142 virtual bool BeginChunk() OVERRIDE; |
143 | 143 |
144 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) OVERRIDE; | 144 virtual bool WriteAddPrefix(int32 chunk_id, SBPrefix prefix) OVERRIDE; |
145 virtual bool WriteAddHash(int32 chunk_id, | 145 virtual bool WriteAddHash(int32 chunk_id, |
146 base::Time receive_time, | |
147 const SBFullHash& full_hash) OVERRIDE; | 146 const SBFullHash& full_hash) OVERRIDE; |
148 virtual bool WriteSubPrefix(int32 chunk_id, | 147 virtual bool WriteSubPrefix(int32 chunk_id, |
149 int32 add_chunk_id, SBPrefix prefix) OVERRIDE; | 148 int32 add_chunk_id, SBPrefix prefix) OVERRIDE; |
150 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, | 149 virtual bool WriteSubHash(int32 chunk_id, int32 add_chunk_id, |
151 const SBFullHash& full_hash) OVERRIDE; | 150 const SBFullHash& full_hash) OVERRIDE; |
152 virtual bool FinishChunk() OVERRIDE; | 151 virtual bool FinishChunk() OVERRIDE; |
153 | 152 |
154 virtual bool BeginUpdate() OVERRIDE; | 153 virtual bool BeginUpdate() OVERRIDE; |
155 // Store updates with pending add full hashes in file store and | 154 // Store updates in file store. Kept prefixes will be added to |builder| and |
156 // return |add_prefixes_result| and |add_full_hashes_result|. | 155 // kept full hashes to |add_full_hashes_result|. |
157 virtual bool FinishUpdate( | 156 virtual bool FinishUpdate( |
158 const std::vector<SBAddFullHash>& pending_adds, | |
159 safe_browsing::PrefixSetBuilder* builder, | 157 safe_browsing::PrefixSetBuilder* builder, |
160 std::vector<SBAddFullHash>* add_full_hashes_result) OVERRIDE; | 158 std::vector<SBAddFullHash>* add_full_hashes_result) OVERRIDE; |
161 virtual bool CancelUpdate() OVERRIDE; | 159 virtual bool CancelUpdate() OVERRIDE; |
162 | 160 |
163 virtual void SetAddChunk(int32 chunk_id) OVERRIDE; | 161 virtual void SetAddChunk(int32 chunk_id) OVERRIDE; |
164 virtual bool CheckAddChunk(int32 chunk_id) OVERRIDE; | 162 virtual bool CheckAddChunk(int32 chunk_id) OVERRIDE; |
165 virtual void GetAddChunks(std::vector<int32>* out) OVERRIDE; | 163 virtual void GetAddChunks(std::vector<int32>* out) OVERRIDE; |
166 virtual void SetSubChunk(int32 chunk_id) OVERRIDE; | 164 virtual void SetSubChunk(int32 chunk_id) OVERRIDE; |
167 virtual bool CheckSubChunk(int32 chunk_id) OVERRIDE; | 165 virtual bool CheckSubChunk(int32 chunk_id) OVERRIDE; |
168 virtual void GetSubChunks(std::vector<int32>* out) OVERRIDE; | 166 virtual void GetSubChunks(std::vector<int32>* out) OVERRIDE; |
169 | 167 |
170 virtual void DeleteAddChunk(int32 chunk_id) OVERRIDE; | 168 virtual void DeleteAddChunk(int32 chunk_id) OVERRIDE; |
171 virtual void DeleteSubChunk(int32 chunk_id) OVERRIDE; | 169 virtual void DeleteSubChunk(int32 chunk_id) OVERRIDE; |
172 | 170 |
173 // Verify |file_|'s checksum, calling the corruption callback if it | 171 // Verify |file_|'s checksum, calling the corruption callback if it |
174 // does not check out. Empty input is considered valid. | 172 // does not check out. Empty input is considered valid. |
175 virtual bool CheckValidity() OVERRIDE; | 173 virtual bool CheckValidity() OVERRIDE; |
176 | 174 |
177 // Returns the name of the temporary file used to buffer data for | 175 // Returns the name of the temporary file used to buffer data for |
178 // |filename|. Exported for unit tests. | 176 // |filename|. Exported for unit tests. |
179 static const base::FilePath TemporaryFileForFilename( | 177 static const base::FilePath TemporaryFileForFilename( |
180 const base::FilePath& filename) { | 178 const base::FilePath& filename) { |
181 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); | 179 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); |
182 } | 180 } |
183 | 181 |
184 // Delete any on-disk files, including the permanent storage. | 182 // Delete any on-disk files, including the permanent storage. |
185 static bool DeleteStore(const base::FilePath& basename); | 183 static bool DeleteStore(const base::FilePath& basename); |
186 | 184 |
187 private: | 185 private: |
188 // Update store file with pending full hashes. | 186 // Update store file and return |add_full_hashes_result|. |
189 virtual bool DoUpdate(const std::vector<SBAddFullHash>& pending_adds, | 187 virtual bool DoUpdate(safe_browsing::PrefixSetBuilder* builder, |
190 safe_browsing::PrefixSetBuilder* builder, | |
191 std::vector<SBAddFullHash>* add_full_hashes_result); | 188 std::vector<SBAddFullHash>* add_full_hashes_result); |
192 | 189 |
193 // Some very lucky users have an original-format file still in their | 190 // Some very lucky users have an original-format file still in their |
194 // profile. Check for it and delete, recording a histogram for the | 191 // profile. Check for it and delete, recording a histogram for the |
195 // result (no histogram for not-found). Logically this | 192 // result (no histogram for not-found). Logically this |
196 // would make more sense at the SafeBrowsingDatabase level, but | 193 // would make more sense at the SafeBrowsingDatabase level, but |
197 // practically speaking that code doesn't touch files directly. | 194 // practically speaking that code doesn't touch files directly. |
198 static void CheckForOriginalAndDelete(const base::FilePath& filename); | 195 static void CheckForOriginalAndDelete(const base::FilePath& filename); |
199 | 196 |
200 // Close all files and clear all buffers. | 197 // Close all files and clear all buffers. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 264 |
268 // Tracks whether corruption has already been seen in the current | 265 // Tracks whether corruption has already been seen in the current |
269 // update, so that only one instance is recorded in the stats. | 266 // update, so that only one instance is recorded in the stats. |
270 // TODO(shess): Remove with format-migration support. | 267 // TODO(shess): Remove with format-migration support. |
271 bool corruption_seen_; | 268 bool corruption_seen_; |
272 | 269 |
273 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); | 270 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); |
274 }; | 271 }; |
275 | 272 |
276 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ | 273 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ |
OLD | NEW |