Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file.h

Issue 910953002: Move SafeBrowsing to the blocking pool via an experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix browsertest. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "chrome/browser/safe_browsing/safe_browsing_store.h" 11 #include "chrome/browser/safe_browsing/safe_browsing_store.h"
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/scoped_file.h" 15 #include "base/files/scoped_file.h"
16 #include "base/threading/non_thread_safe.h" 16 #include "base/sequenced_task_runner.h"
17 17
18 // Implement SafeBrowsingStore in terms of a flat file. The file 18 // Implement SafeBrowsingStore in terms of a flat file. The file
19 // format is pretty literal: 19 // format is pretty literal:
20 // 20 //
21 // int32 magic; // magic number "validating" file 21 // int32 magic; // magic number "validating" file
22 // int32 version; // format version 22 // int32 version; // format version
23 // 23 //
24 // // Counts for the various data which follows the header. 24 // // Counts for the various data which follows the header.
25 // uint32 add_chunk_count; // Chunks seen, including empties. 25 // uint32 add_chunk_count; // Chunks seen, including empties.
26 // uint32 sub_chunk_count; // Ditto. 26 // uint32 sub_chunk_count; // Ditto.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // - When the transaction is finished: 116 // - When the transaction is finished:
117 // - Read the update data from the temp file into memory. 117 // - Read the update data from the temp file into memory.
118 // - Overwrite the temp file with new header data. 118 // - Overwrite the temp file with new header data.
119 // - Until done: 119 // - Until done:
120 // - Read shards of the original file's data into memory. 120 // - Read shards of the original file's data into memory.
121 // - Merge from the update data. 121 // - Merge from the update data.
122 // - Write shards to the temp file. 122 // - Write shards to the temp file.
123 // - Delete original file. 123 // - Delete original file.
124 // - Rename temp file to original filename. 124 // - Rename temp file to original filename.
125 125
126 class SafeBrowsingStoreFile : public SafeBrowsingStore, 126 class SafeBrowsingStoreFile : public SafeBrowsingStore {
127 public base::NonThreadSafe {
128 public: 127 public:
129 SafeBrowsingStoreFile(); 128 explicit SafeBrowsingStoreFile(
129 const scoped_refptr<const base::SequencedTaskRunner>& task_runner);
130 ~SafeBrowsingStoreFile() override; 130 ~SafeBrowsingStoreFile() override;
131 131
132 void Init(const base::FilePath& filename, 132 void Init(const base::FilePath& filename,
133 const base::Closure& corruption_callback) override; 133 const base::Closure& corruption_callback) override;
134 134
135 // Delete any on-disk files, including the permanent storage. 135 // Delete any on-disk files, including the permanent storage.
136 bool Delete() override; 136 bool Delete() override;
137 137
138 // Get all add hash prefixes and full-length hashes, respectively, from 138 // Get all add hash prefixes and full-length hashes, respectively, from
139 // the store. 139 // the store.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // |filename|. Exported for unit tests. 176 // |filename|. Exported for unit tests.
177 static const base::FilePath TemporaryFileForFilename( 177 static const base::FilePath TemporaryFileForFilename(
178 const base::FilePath& filename) { 178 const base::FilePath& filename) {
179 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); 179 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new"));
180 } 180 }
181 181
182 // Delete any on-disk files, including the permanent storage. 182 // Delete any on-disk files, including the permanent storage.
183 static bool DeleteStore(const base::FilePath& basename); 183 static bool DeleteStore(const base::FilePath& basename);
184 184
185 private: 185 private:
186 // Checks whether the current thread is part of the sequenced task runner
187 // this object was initialized with.
188 bool CalledOnValidThread();
189
186 // Does the actual update for FinishUpdate(), so that FinishUpdate() can clean 190 // Does the actual update for FinishUpdate(), so that FinishUpdate() can clean
187 // up correctly in case of error. 191 // up correctly in case of error.
188 virtual bool DoUpdate(safe_browsing::PrefixSetBuilder* builder, 192 virtual bool DoUpdate(safe_browsing::PrefixSetBuilder* builder,
189 std::vector<SBAddFullHash>* add_full_hashes_result); 193 std::vector<SBAddFullHash>* add_full_hashes_result);
190 194
191 // Some very lucky users have an original-format file still in their 195 // Some very lucky users have an original-format file still in their
192 // profile. Check for it and delete, recording a histogram for the 196 // profile. Check for it and delete, recording a histogram for the
193 // result (no histogram for not-found). Logically this 197 // result (no histogram for not-found). Logically this
194 // would make more sense at the SafeBrowsingDatabase level, but 198 // would make more sense at the SafeBrowsingDatabase level, but
195 // practically speaking that code doesn't touch files directly. 199 // practically speaking that code doesn't touch files directly.
(...skipping 26 matching lines...) Expand all
222 // Clear all buffers used during update. 226 // Clear all buffers used during update.
223 void ClearUpdateBuffers() { 227 void ClearUpdateBuffers() {
224 ClearChunkBuffers(); 228 ClearChunkBuffers();
225 chunks_written_ = 0; 229 chunks_written_ = 0;
226 std::set<int32>().swap(add_chunks_cache_); 230 std::set<int32>().swap(add_chunks_cache_);
227 std::set<int32>().swap(sub_chunks_cache_); 231 std::set<int32>().swap(sub_chunks_cache_);
228 base::hash_set<int32>().swap(add_del_cache_); 232 base::hash_set<int32>().swap(add_del_cache_);
229 base::hash_set<int32>().swap(sub_del_cache_); 233 base::hash_set<int32>().swap(sub_del_cache_);
230 } 234 }
231 235
236 // The sequenced task runner for this object, used to verify that its state
237 // is only ever accessed from the runner.
238 scoped_refptr<const base::SequencedTaskRunner> task_runner_;
239
232 // Buffers for collecting data between BeginChunk() and 240 // Buffers for collecting data between BeginChunk() and
233 // FinishChunk(). 241 // FinishChunk().
234 SBAddPrefixes add_prefixes_; 242 SBAddPrefixes add_prefixes_;
235 SBSubPrefixes sub_prefixes_; 243 SBSubPrefixes sub_prefixes_;
236 std::vector<SBAddFullHash> add_hashes_; 244 std::vector<SBAddFullHash> add_hashes_;
237 std::vector<SBSubFullHash> sub_hashes_; 245 std::vector<SBSubFullHash> sub_hashes_;
238 246
239 // Count of chunks collected in |new_file_|. 247 // Count of chunks collected in |new_file_|.
240 int chunks_written_; 248 int chunks_written_;
241 249
(...skipping 23 matching lines...) Expand all
265 273
266 // Tracks whether corruption has already been seen in the current 274 // Tracks whether corruption has already been seen in the current
267 // update, so that only one instance is recorded in the stats. 275 // update, so that only one instance is recorded in the stats.
268 // TODO(shess): Remove with format-migration support. 276 // TODO(shess): Remove with format-migration support.
269 bool corruption_seen_; 277 bool corruption_seen_;
270 278
271 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile); 279 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingStoreFile);
272 }; 280 };
273 281
274 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_ 282 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_STORE_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698