OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/safe_browsing/safe_browsing_database.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // The following is to log actual performance to verify this. | 210 // The following is to log actual performance to verify this. |
211 enum PrefixSetEvent { | 211 enum PrefixSetEvent { |
212 PREFIX_SET_EVENT_HIT, | 212 PREFIX_SET_EVENT_HIT, |
213 PREFIX_SET_EVENT_BLOOM_HIT, | 213 PREFIX_SET_EVENT_BLOOM_HIT, |
214 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT, | 214 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT, |
215 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID, | 215 PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID, |
216 PREFIX_SET_GETPREFIXES_BROKEN, | 216 PREFIX_SET_GETPREFIXES_BROKEN, |
217 PREFIX_SET_GETPREFIXES_BROKEN_SIZE, | 217 PREFIX_SET_GETPREFIXES_BROKEN_SIZE, |
218 PREFIX_SET_GETPREFIXES_FIRST_BROKEN, | 218 PREFIX_SET_GETPREFIXES_FIRST_BROKEN, |
219 PREFIX_SET_SBPREFIX_WAS_BROKEN, | 219 PREFIX_SET_SBPREFIX_WAS_BROKEN, |
| 220 PREFIX_SET_GETPREFIXES_BROKEN_SORTING, |
| 221 PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION, |
220 | 222 |
221 // Memory space for histograms is determined by the max. ALWAYS ADD | 223 // Memory space for histograms is determined by the max. ALWAYS ADD |
222 // NEW VALUES BEFORE THIS ONE. | 224 // NEW VALUES BEFORE THIS ONE. |
223 PREFIX_SET_EVENT_MAX | 225 PREFIX_SET_EVENT_MAX |
224 }; | 226 }; |
225 | 227 |
226 void RecordPrefixSetInfo(PrefixSetEvent event_type) { | 228 void RecordPrefixSetInfo(PrefixSetEvent event_type) { |
227 UMA_HISTOGRAM_ENUMERATION("SB2.PrefixSetEvent", event_type, | 229 UMA_HISTOGRAM_ENUMERATION("SB2.PrefixSetEvent", event_type, |
228 PREFIX_SET_EVENT_MAX); | 230 PREFIX_SET_EVENT_MAX); |
229 } | 231 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 if (!logged_broken) { | 274 if (!logged_broken) { |
273 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_FIRST_BROKEN); | 275 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_FIRST_BROKEN); |
274 logged_broken = true; | 276 logged_broken = true; |
275 } | 277 } |
276 | 278 |
277 // This seems so very very unlikely. But if it ever were true, then | 279 // This seems so very very unlikely. But if it ever were true, then |
278 // it could explain why GetPrefixes() seemed broken. | 280 // it could explain why GetPrefixes() seemed broken. |
279 if (sizeof(int) != sizeof(int32)) | 281 if (sizeof(int) != sizeof(int32)) |
280 RecordPrefixSetInfo(PREFIX_SET_SBPREFIX_WAS_BROKEN); | 282 RecordPrefixSetInfo(PREFIX_SET_SBPREFIX_WAS_BROKEN); |
281 | 283 |
| 284 // Check whether |restored| is unsorted, or has duplication. |
| 285 if (restored.size()) { |
| 286 bool unsorted = false; |
| 287 bool duplicates = false; |
| 288 std::vector<SBPrefix>::const_iterator prev = restored.begin(); |
| 289 for (std::vector<SBPrefix>::const_iterator iter = prev + 1; |
| 290 iter != restored.end(); prev = iter, ++iter) { |
| 291 if (*prev > *iter) |
| 292 unsorted = true; |
| 293 if (*prev == *iter) |
| 294 duplicates = true; |
| 295 } |
| 296 |
| 297 // Record findings. |
| 298 if (unsorted) |
| 299 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_SORTING); |
| 300 if (duplicates) |
| 301 RecordPrefixSetInfo(PREFIX_SET_GETPREFIXES_BROKEN_DUPLICATION); |
| 302 |
| 303 // Fix the problems noted. If |restored| was unsorted, then |
| 304 // |duplicates| may give a false negative. |
| 305 if (unsorted) |
| 306 std::sort(restored.begin(), restored.end()); |
| 307 if (unsorted || duplicates) |
| 308 restored.erase(std::unique(restored.begin(), restored.end()), |
| 309 restored.end()); |
| 310 } |
| 311 |
| 312 // NOTE(shess): The following could be done using a single |
| 313 // uber-loop, but it's complicated by needing multiple parallel |
| 314 // iterators. Didn't seem worthwhile for something that will only |
| 315 // live for a short period and only fires for one in a million |
| 316 // updates. |
| 317 |
| 318 // Find elements in |restored| which are not in |prefixes|. |
| 319 std::vector<SBPrefix> difference; |
| 320 std::set_difference(restored.begin(), restored.end(), |
| 321 prefixes.begin(), prefixes.end(), |
| 322 std::back_inserter(difference)); |
| 323 if (difference.size()) |
| 324 UMA_HISTOGRAM_COUNTS_100("SB2.PrefixSetRestoredExcess", difference.size()); |
| 325 |
| 326 // Find elements in |prefixes| which are not in |restored|. |
| 327 difference.clear(); |
| 328 std::set_difference(prefixes.begin(), prefixes.end(), |
| 329 restored.begin(), restored.end(), |
| 330 std::back_inserter(difference)); |
| 331 if (difference.size()) |
| 332 UMA_HISTOGRAM_COUNTS_100("SB2.PrefixSetRestoredShortfall", |
| 333 difference.size()); |
282 return prefix_set.release(); | 334 return prefix_set.release(); |
283 } | 335 } |
284 | 336 |
285 } // namespace | 337 } // namespace |
286 | 338 |
287 // The default SafeBrowsingDatabaseFactory. | 339 // The default SafeBrowsingDatabaseFactory. |
288 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { | 340 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
289 public: | 341 public: |
290 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 342 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
291 bool enable_download_protection, | 343 bool enable_download_protection, |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 if (std::binary_search(new_csd_whitelist.begin(), new_csd_whitelist.end(), | 1249 if (std::binary_search(new_csd_whitelist.begin(), new_csd_whitelist.end(), |
1198 kill_switch)) { | 1250 kill_switch)) { |
1199 // The kill switch is whitelisted hence we whitelist all URLs. | 1251 // The kill switch is whitelisted hence we whitelist all URLs. |
1200 CsdWhitelistAllUrls(); | 1252 CsdWhitelistAllUrls(); |
1201 } else { | 1253 } else { |
1202 base::AutoLock locked(lookup_lock_); | 1254 base::AutoLock locked(lookup_lock_); |
1203 csd_whitelist_all_urls_ = false; | 1255 csd_whitelist_all_urls_ = false; |
1204 csd_whitelist_.swap(new_csd_whitelist); | 1256 csd_whitelist_.swap(new_csd_whitelist); |
1205 } | 1257 } |
1206 } | 1258 } |
OLD | NEW |