OLD | NEW |
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 Loading... |
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::AreAnyStoresAvailable( |
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 | 213 } |
214 } | 214 return false; |
215 if (!store_pair->second->HasValidData()) { | 215 } |
216 return false; // Store never properly populated. | 216 |
217 } | 217 bool V4Database::AreAllStoresAvailable( |
| 218 const StoresToCheck& stores_to_check) const { |
| 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 220 for (const ListIdentifier& identifier : stores_to_check) { |
| 221 if (!IsStoreAvailable(identifier)) |
| 222 return false; |
218 } | 223 } |
219 return true; | 224 return true; |
220 } | 225 } |
221 | 226 |
222 void V4Database::GetStoresMatchingFullHash( | 227 void V4Database::GetStoresMatchingFullHash( |
223 const FullHash& full_hash, | 228 const FullHash& full_hash, |
224 const StoresToCheck& stores_to_check, | 229 const StoresToCheck& stores_to_check, |
225 StoreAndHashPrefixes* matched_store_and_hash_prefixes) { | 230 StoreAndHashPrefixes* matched_store_and_hash_prefixes) { |
226 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 231 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
227 matched_store_and_hash_prefixes->clear(); | 232 matched_store_and_hash_prefixes->clear(); |
228 for (const ListIdentifier& identifier : stores_to_check) { | 233 for (const ListIdentifier& identifier : stores_to_check) { |
| 234 if (!IsStoreAvailable(identifier)) |
| 235 continue; |
229 const auto& store_pair = store_map_->find(identifier); | 236 const auto& store_pair = store_map_->find(identifier); |
230 DCHECK(store_pair != store_map_->end()); | 237 DCHECK(store_pair != store_map_->end()); |
231 const std::unique_ptr<V4Store>& store = store_pair->second; | 238 const std::unique_ptr<V4Store>& store = store_pair->second; |
232 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash); | 239 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash); |
233 if (!hash_prefix.empty()) { | 240 if (!hash_prefix.empty()) { |
234 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix); | 241 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix); |
235 } | 242 } |
236 } | 243 } |
237 } | 244 } |
238 | 245 |
(...skipping 25 matching lines...) Expand all Loading... |
264 for (const auto& store_map_iter : *store_map_) { | 271 for (const auto& store_map_iter : *store_map_) { |
265 if (!store_map_iter.second->VerifyChecksum()) { | 272 if (!store_map_iter.second->VerifyChecksum()) { |
266 stores_to_reset.push_back(store_map_iter.first); | 273 stores_to_reset.push_back(store_map_iter.first); |
267 } | 274 } |
268 } | 275 } |
269 | 276 |
270 callback_task_runner->PostTask( | 277 callback_task_runner->PostTask( |
271 FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset)); | 278 FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset)); |
272 } | 279 } |
273 | 280 |
| 281 bool V4Database::IsStoreAvailable(const ListIdentifier& identifier) const { |
| 282 const auto& store_pair = store_map_->find(identifier); |
| 283 if (store_pair == store_map_->end()) { |
| 284 // Store not in our list |
| 285 return false; |
| 286 } |
| 287 if (!store_pair->second->HasValidData()) { |
| 288 // Store never properly populated |
| 289 return false; |
| 290 } |
| 291 return true; |
| 292 } |
| 293 |
274 void V4Database::RecordFileSizeHistograms() { | 294 void V4Database::RecordFileSizeHistograms() { |
275 int64_t db_size = 0; | 295 int64_t db_size = 0; |
276 for (const auto& store_map_iter : *store_map_) { | 296 for (const auto& store_map_iter : *store_map_) { |
277 const int64_t size = | 297 const int64_t size = |
278 store_map_iter.second->RecordAndReturnFileSize(kV4DatabaseSizeMetric); | 298 store_map_iter.second->RecordAndReturnFileSize(kV4DatabaseSizeMetric); |
279 db_size += size; | 299 db_size += size; |
280 } | 300 } |
281 const int64_t db_size_kilobytes = static_cast<int64_t>(db_size / 1024); | 301 const int64_t db_size_kilobytes = static_cast<int64_t>(db_size / 1024); |
282 UMA_HISTOGRAM_COUNTS(kV4DatabaseSizeMetric, db_size_kilobytes); | 302 UMA_HISTOGRAM_COUNTS(kV4DatabaseSizeMetric, db_size_kilobytes); |
283 } | 303 } |
284 | 304 |
285 ListInfo::ListInfo(const bool fetch_updates, | 305 ListInfo::ListInfo(const bool fetch_updates, |
286 const std::string& filename, | 306 const std::string& filename, |
287 const ListIdentifier& list_id, | 307 const ListIdentifier& list_id, |
288 const SBThreatType sb_threat_type) | 308 const SBThreatType sb_threat_type) |
289 : fetch_updates_(fetch_updates), | 309 : fetch_updates_(fetch_updates), |
290 filename_(filename), | 310 filename_(filename), |
291 list_id_(list_id), | 311 list_id_(list_id), |
292 sb_threat_type_(sb_threat_type) { | 312 sb_threat_type_(sb_threat_type) { |
293 DCHECK(!fetch_updates_ || !filename_.empty()); | 313 DCHECK(!fetch_updates_ || !filename_.empty()); |
294 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); | 314 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); |
295 } | 315 } |
296 | 316 |
297 ListInfo::~ListInfo() {} | 317 ListInfo::~ListInfo() {} |
298 | 318 |
299 } // namespace safe_browsing | 319 } // namespace safe_browsing |
OLD | NEW |