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

Side by Side Diff: components/safe_browsing_db/v4_database.cc

Issue 2814733002: Add the SocEng as a type for checking in CheckUrlForSubresourceFilter. (Closed)
Patch Set: rebased and changes sync strategy Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include <memory> 5 #include <memory>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() { 198 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() {
199 std::unique_ptr<StoreStateMap> store_state_map = 199 std::unique_ptr<StoreStateMap> store_state_map =
200 base::MakeUnique<StoreStateMap>(); 200 base::MakeUnique<StoreStateMap>();
201 for (const auto& store_map_iter : *store_map_) { 201 for (const auto& store_map_iter : *store_map_) {
202 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state(); 202 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state();
203 } 203 }
204 return store_state_map; 204 return store_state_map;
205 } 205 }
206 206
207 bool V4Database::AreStoresAvailable( 207 bool V4Database::AreStoresAvailable(
Nathan Parker 2017/05/12 17:30:10 I had the following comment on an earlier vers, an
melandory 2017/05/15 14:57:25 Sorry, haven't noticed it earlier. Done.
208 const StoresToCheck& stores_to_check) const { 208 const StoresToCheck& stores_to_check) const {
209 DCHECK_CURRENTLY_ON(BrowserThread::IO); 209 DCHECK_CURRENTLY_ON(BrowserThread::IO);
210 for (const ListIdentifier& identifier : stores_to_check) { 210 for (const ListIdentifier& identifier : stores_to_check) {
211 const auto& store_pair = store_map_->find(identifier); 211 if (IsStoreAvailable(identifier))
212 if (store_pair == store_map_->end()) { 212 return true;
213 return false; // Store not in our list
214 }
215 if (!store_pair->second->HasValidData()) {
216 return false; // Store never properly populated.
217 }
218 } 213 }
219 return true; 214 return false;
220 } 215 }
221 216
222 void V4Database::GetStoresMatchingFullHash( 217 void V4Database::GetStoresMatchingFullHash(
223 const FullHash& full_hash, 218 const FullHash& full_hash,
224 const StoresToCheck& stores_to_check, 219 const StoresToCheck& stores_to_check,
225 StoreAndHashPrefixes* matched_store_and_hash_prefixes) { 220 StoreAndHashPrefixes* matched_store_and_hash_prefixes) {
226 DCHECK_CURRENTLY_ON(BrowserThread::IO); 221 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 matched_store_and_hash_prefixes->clear(); 222 matched_store_and_hash_prefixes->clear();
228 for (const ListIdentifier& identifier : stores_to_check) { 223 for (const ListIdentifier& identifier : stores_to_check) {
224 if (!IsStoreAvailable(identifier))
225 continue;
229 const auto& store_pair = store_map_->find(identifier); 226 const auto& store_pair = store_map_->find(identifier);
230 DCHECK(store_pair != store_map_->end()); 227 DCHECK(store_pair != store_map_->end());
231 const std::unique_ptr<V4Store>& store = store_pair->second; 228 const std::unique_ptr<V4Store>& store = store_pair->second;
232 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash); 229 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash);
233 if (!hash_prefix.empty()) { 230 if (!hash_prefix.empty()) {
234 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix); 231 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix);
235 } 232 }
236 } 233 }
237 } 234 }
238 235
(...skipping 25 matching lines...) Expand all
264 for (const auto& store_map_iter : *store_map_) { 261 for (const auto& store_map_iter : *store_map_) {
265 if (!store_map_iter.second->VerifyChecksum()) { 262 if (!store_map_iter.second->VerifyChecksum()) {
266 stores_to_reset.push_back(store_map_iter.first); 263 stores_to_reset.push_back(store_map_iter.first);
267 } 264 }
268 } 265 }
269 266
270 callback_task_runner->PostTask( 267 callback_task_runner->PostTask(
271 FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset)); 268 FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset));
272 } 269 }
273 270
271 bool V4Database::IsStoreAvailable(const ListIdentifier& identifier) const {
272 const auto& store_pair = store_map_->find(identifier);
273 if (store_pair == store_map_->end()) {
274 // Store not in our list
275 return false;
276 }
277 if (!store_pair->second->HasValidData()) {
278 // Store never properly populated
279 return false;
280 }
281 return true;
282 }
283
274 void V4Database::RecordFileSizeHistograms() { 284 void V4Database::RecordFileSizeHistograms() {
275 int64_t db_size = 0; 285 int64_t db_size = 0;
276 for (const auto& store_map_iter : *store_map_) { 286 for (const auto& store_map_iter : *store_map_) {
277 const int64_t size = 287 const int64_t size =
278 store_map_iter.second->RecordAndReturnFileSize(kV4DatabaseSizeMetric); 288 store_map_iter.second->RecordAndReturnFileSize(kV4DatabaseSizeMetric);
279 db_size += size; 289 db_size += size;
280 } 290 }
281 const int64_t db_size_kilobytes = static_cast<int64_t>(db_size / 1024); 291 const int64_t db_size_kilobytes = static_cast<int64_t>(db_size / 1024);
282 UMA_HISTOGRAM_COUNTS(kV4DatabaseSizeMetric, db_size_kilobytes); 292 UMA_HISTOGRAM_COUNTS(kV4DatabaseSizeMetric, db_size_kilobytes);
283 } 293 }
284 294
285 ListInfo::ListInfo(const bool fetch_updates, 295 ListInfo::ListInfo(const bool fetch_updates,
286 const std::string& filename, 296 const std::string& filename,
287 const ListIdentifier& list_id, 297 const ListIdentifier& list_id,
288 const SBThreatType sb_threat_type) 298 const SBThreatType sb_threat_type)
289 : fetch_updates_(fetch_updates), 299 : fetch_updates_(fetch_updates),
290 filename_(filename), 300 filename_(filename),
291 list_id_(list_id), 301 list_id_(list_id),
292 sb_threat_type_(sb_threat_type) { 302 sb_threat_type_(sb_threat_type) {
293 DCHECK(!fetch_updates_ || !filename_.empty()); 303 DCHECK(!fetch_updates_ || !filename_.empty());
294 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); 304 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_);
295 } 305 }
296 306
297 ListInfo::~ListInfo() {} 307 ListInfo::~ListInfo() {}
298 308
299 } // namespace safe_browsing 309 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_database.h ('k') | components/safe_browsing_db/v4_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698