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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 815863002: Suffixed histograms for SB2.DatabaseKilobytes and SB2.PrefixSetKilobytes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@aV_threadSafeStoreManager
Patch Set: fix histogram name in code Created 5 years, 11 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 #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 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/macros.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/metrics/stats_counters.h" 15 #include "base/metrics/stats_counters.h"
15 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
16 #include "base/process/process_metrics.h" 17 #include "base/process/process_metrics.h"
17 #include "base/sha1.h" 18 #include "base/sha1.h"
18 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
21 #include "chrome/browser/safe_browsing/prefix_set.h" 23 #include "chrome/browser/safe_browsing/prefix_set.h"
22 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" 24 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
23 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
24 #include "crypto/sha2.h" 26 #include "crypto/sha2.h"
25 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
26 #include "url/gurl.h" 28 #include "url/gurl.h"
27 29
28 #if defined(OS_MACOSX) 30 #if defined(OS_MACOSX)
29 #include "base/mac/mac_util.h" 31 #include "base/mac/mac_util.h"
30 #endif 32 #endif
31 33
32 using content::BrowserThread; 34 using content::BrowserThread;
33 using safe_browsing::PrefixSet; 35 using safe_browsing::PrefixSet;
34 using safe_browsing::PrefixSetBuilder; 36 using safe_browsing::PrefixSetBuilder;
35 37
36 namespace { 38 namespace {
37 39
38 // Filename suffix for the bloom filter. 40 // Filename suffix for the bloom filter.
39 const base::FilePath::CharType kBloomFilterFile[] = 41 const base::FilePath::CharType kBloomFilterFileSuffix[] =
40 FILE_PATH_LITERAL(" Filter 2"); 42 FILE_PATH_LITERAL(" Filter 2");
41 // Filename suffix for the prefix set. 43 // Filename suffix for the prefix set.
42 const base::FilePath::CharType kPrefixSetFile[] = 44 const base::FilePath::CharType kPrefixSetFileSuffix[] =
43 FILE_PATH_LITERAL(" Prefix Set"); 45 FILE_PATH_LITERAL(" Prefix Set");
44 // Filename suffix for download store. 46 // Filename suffix for download store.
45 const base::FilePath::CharType kDownloadDBFile[] = 47 const base::FilePath::CharType kDownloadDBFile[] =
46 FILE_PATH_LITERAL(" Download"); 48 FILE_PATH_LITERAL(" Download");
47 // Filename suffix for client-side phishing detection whitelist store. 49 // Filename suffix for client-side phishing detection whitelist store.
48 const base::FilePath::CharType kCsdWhitelistDBFile[] = 50 const base::FilePath::CharType kCsdWhitelistDBFile[] =
49 FILE_PATH_LITERAL(" Csd Whitelist"); 51 FILE_PATH_LITERAL(" Csd Whitelist");
50 // Filename suffix for the download whitelist store. 52 // Filename suffix for the download whitelist store.
51 const base::FilePath::CharType kDownloadWhitelistDBFile[] = 53 const base::FilePath::CharType kDownloadWhitelistDBFile[] =
52 FILE_PATH_LITERAL(" Download Whitelist"); 54 FILE_PATH_LITERAL(" Download Whitelist");
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 383
382 // static 384 // static
383 base::FilePath SafeBrowsingDatabase::DownloadDBFilename( 385 base::FilePath SafeBrowsingDatabase::DownloadDBFilename(
384 const base::FilePath& db_base_filename) { 386 const base::FilePath& db_base_filename) {
385 return base::FilePath(db_base_filename.value() + kDownloadDBFile); 387 return base::FilePath(db_base_filename.value() + kDownloadDBFile);
386 } 388 }
387 389
388 // static 390 // static
389 base::FilePath SafeBrowsingDatabase::BloomFilterForFilename( 391 base::FilePath SafeBrowsingDatabase::BloomFilterForFilename(
390 const base::FilePath& db_filename) { 392 const base::FilePath& db_filename) {
391 return base::FilePath(db_filename.value() + kBloomFilterFile); 393 return base::FilePath(db_filename.value() + kBloomFilterFileSuffix);
392 } 394 }
393 395
394 // static 396 // static
395 base::FilePath SafeBrowsingDatabase::PrefixSetForFilename( 397 base::FilePath SafeBrowsingDatabase::PrefixSetForFilename(
396 const base::FilePath& db_filename) { 398 const base::FilePath& db_filename) {
397 return base::FilePath(db_filename.value() + kPrefixSetFile); 399 return base::FilePath(db_filename.value() + kPrefixSetFileSuffix);
398 } 400 }
399 401
400 // static 402 // static
401 base::FilePath SafeBrowsingDatabase::CsdWhitelistDBFilename( 403 base::FilePath SafeBrowsingDatabase::CsdWhitelistDBFilename(
402 const base::FilePath& db_filename) { 404 const base::FilePath& db_filename) {
403 return base::FilePath(db_filename.value() + kCsdWhitelistDBFile); 405 return base::FilePath(db_filename.value() + kCsdWhitelistDBFile);
404 } 406 }
405 407
406 // static 408 // static
407 base::FilePath SafeBrowsingDatabase::DownloadWhitelistDBFilename( 409 base::FilePath SafeBrowsingDatabase::DownloadWhitelistDBFilename(
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 if (side_effect_free_whitelist_store_) 1345 if (side_effect_free_whitelist_store_)
1344 side_effect_free_whitelist_store_->CancelUpdate(); 1346 side_effect_free_whitelist_store_->CancelUpdate();
1345 if (ip_blacklist_store_) 1347 if (ip_blacklist_store_)
1346 ip_blacklist_store_->CancelUpdate(); 1348 ip_blacklist_store_->CancelUpdate();
1347 if (unwanted_software_store_) 1349 if (unwanted_software_store_)
1348 unwanted_software_store_->CancelUpdate(); 1350 unwanted_software_store_->CancelUpdate();
1349 return; 1351 return;
1350 } 1352 }
1351 1353
1352 if (download_store_) { 1354 if (download_store_) {
1353 int64 size_bytes = UpdateHashPrefixStore( 1355 UpdateHashPrefixStore(DownloadDBFilename(filename_base_),
1354 DownloadDBFilename(filename_base_), 1356 download_store_.get(),
1355 download_store_.get(), 1357 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH);
1356 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH);
1357 UMA_HISTOGRAM_COUNTS("SB2.DownloadDatabaseKilobytes",
1358 static_cast<int>(size_bytes / 1024));
1359 } 1358 }
1360 1359
1361 UpdatePrefixSetUrlStore(BrowseDBFilename(filename_base_), 1360 UpdatePrefixSetUrlStore(BrowseDBFilename(filename_base_),
1362 browse_store_.get(), 1361 browse_store_.get(),
1363 PrefixSetId::BROWSE, 1362 PrefixSetId::BROWSE,
1364 FAILURE_BROWSE_DATABASE_UPDATE_FINISH, 1363 FAILURE_BROWSE_DATABASE_UPDATE_FINISH,
1365 FAILURE_BROWSE_PREFIX_SET_WRITE, 1364 FAILURE_BROWSE_PREFIX_SET_WRITE,
1366 true); 1365 true);
1367 1366
1368 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_), 1367 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_),
1369 csd_whitelist_store_.get(), 1368 csd_whitelist_store_.get(),
1370 SBWhitelistId::CSD); 1369 SBWhitelistId::CSD);
1371 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_), 1370 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_),
1372 download_whitelist_store_.get(), 1371 download_whitelist_store_.get(),
1373 SBWhitelistId::DOWNLOAD); 1372 SBWhitelistId::DOWNLOAD);
1374 1373
1375 if (extension_blacklist_store_) { 1374 if (extension_blacklist_store_) {
1376 int64 size_bytes = UpdateHashPrefixStore( 1375 UpdateHashPrefixStore(ExtensionBlacklistDBFilename(filename_base_),
1377 ExtensionBlacklistDBFilename(filename_base_), 1376 extension_blacklist_store_.get(),
1378 extension_blacklist_store_.get(), 1377 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH);
1379 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH);
1380 UMA_HISTOGRAM_COUNTS("SB2.ExtensionBlacklistKilobytes",
1381 static_cast<int>(size_bytes / 1024));
1382 } 1378 }
1383 1379
1384 if (side_effect_free_whitelist_store_) { 1380 if (side_effect_free_whitelist_store_) {
1385 UpdatePrefixSetUrlStore(SideEffectFreeWhitelistDBFilename(filename_base_), 1381 UpdatePrefixSetUrlStore(SideEffectFreeWhitelistDBFilename(filename_base_),
1386 side_effect_free_whitelist_store_.get(), 1382 side_effect_free_whitelist_store_.get(),
1387 PrefixSetId::SIDE_EFFECT_FREE_WHITELIST, 1383 PrefixSetId::SIDE_EFFECT_FREE_WHITELIST,
1388 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH, 1384 FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH,
1389 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_WRITE, 1385 FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_WRITE,
1390 false); 1386 false);
1391 } 1387 }
(...skipping 23 matching lines...) Expand all
1415 // Note: |builder| will not be empty. The current data store implementation 1411 // Note: |builder| will not be empty. The current data store implementation
1416 // stores all full-length hashes as both full and prefix hashes. 1412 // stores all full-length hashes as both full and prefix hashes.
1417 PrefixSetBuilder builder; 1413 PrefixSetBuilder builder;
1418 std::vector<SBAddFullHash> full_hashes; 1414 std::vector<SBAddFullHash> full_hashes;
1419 if (!store->FinishUpdate(&builder, &full_hashes)) { 1415 if (!store->FinishUpdate(&builder, &full_hashes)) {
1420 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_FINISH); 1416 RecordFailure(FAILURE_WHITELIST_DATABASE_UPDATE_FINISH);
1421 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); 1417 state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id);
1422 return; 1418 return;
1423 } 1419 }
1424 1420
1421 RecordFileSizeHistogram(store_filename);
1422
1425 #if defined(OS_MACOSX) 1423 #if defined(OS_MACOSX)
1426 base::mac::SetFileBackupExclusion(store_filename); 1424 base::mac::SetFileBackupExclusion(store_filename);
1427 #endif 1425 #endif
1428 1426
1429 LoadWhitelist(full_hashes, whitelist_id); 1427 LoadWhitelist(full_hashes, whitelist_id);
1430 } 1428 }
1431 1429
1432 int64 SafeBrowsingDatabaseNew::UpdateHashPrefixStore( 1430 void SafeBrowsingDatabaseNew::UpdateHashPrefixStore(
1433 const base::FilePath& store_filename, 1431 const base::FilePath& store_filename,
1434 SafeBrowsingStore* store, 1432 SafeBrowsingStore* store,
1435 FailureType failure_type) { 1433 FailureType failure_type) {
1436 DCHECK(thread_checker_.CalledOnValidThread()); 1434 DCHECK(thread_checker_.CalledOnValidThread());
1437 1435
1438 // These results are not used after this call. Simply ignore the 1436 // These results are not used after this call. Simply ignore the
1439 // returned value after FinishUpdate(...). 1437 // returned value after FinishUpdate(...).
1440 PrefixSetBuilder builder; 1438 PrefixSetBuilder builder;
1441 std::vector<SBAddFullHash> add_full_hashes_result; 1439 std::vector<SBAddFullHash> add_full_hashes_result;
1442 1440
1443 if (!store->FinishUpdate(&builder, &add_full_hashes_result)) 1441 if (!store->FinishUpdate(&builder, &add_full_hashes_result))
1444 RecordFailure(failure_type); 1442 RecordFailure(failure_type);
1445 1443
1444 RecordFileSizeHistogram(store_filename);
1445
1446 #if defined(OS_MACOSX) 1446 #if defined(OS_MACOSX)
1447 base::mac::SetFileBackupExclusion(store_filename); 1447 base::mac::SetFileBackupExclusion(store_filename);
1448 #endif 1448 #endif
1449
1450 return GetFileSizeOrZero(store_filename);
1451 } 1449 }
1452 1450
1453 void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore( 1451 void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore(
1454 const base::FilePath& db_filename, 1452 const base::FilePath& db_filename,
1455 SafeBrowsingStore* url_store, 1453 SafeBrowsingStore* url_store,
1456 PrefixSetId prefix_set_id, 1454 PrefixSetId prefix_set_id,
1457 FailureType finish_failure_type, 1455 FailureType finish_failure_type,
1458 FailureType write_failure_type, 1456 FailureType write_failure_type,
1459 bool store_full_hashes_in_prefix_set) { 1457 bool store_full_hashes_in_prefix_set) {
1460 DCHECK(thread_checker_.CalledOnValidThread()); 1458 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 // here. 1502 // here.
1505 new_prefix_set = builder.GetPrefixSetNoHashes(); 1503 new_prefix_set = builder.GetPrefixSetNoHashes();
1506 } 1504 }
1507 1505
1508 // Swap in the newly built filter. 1506 // Swap in the newly built filter.
1509 state_manager_.BeginWriteTransaction()->SwapPrefixSet(prefix_set_id, 1507 state_manager_.BeginWriteTransaction()->SwapPrefixSet(prefix_set_id,
1510 new_prefix_set.Pass()); 1508 new_prefix_set.Pass());
1511 1509
1512 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before); 1510 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before);
1513 1511
1514 { 1512 WritePrefixSet(db_filename, prefix_set_id, write_failure_type);
1515 // Persist the prefix set to disk. Do not grab the lock to avoid contention
1516 // while writing to disk. This is safe as only this thread can ever modify
1517 // |state_manager_|'s prefix sets anyways.
1518 scoped_ptr<ReadTransaction> txn =
1519 state_manager_.BeginReadTransactionNoLockOnMainThread();
1520 WritePrefixSet(db_filename, txn->GetPrefixSet(prefix_set_id),
1521 write_failure_type);
1522 }
1523 1513
1524 // Gather statistics. 1514 // Gather statistics.
1525 if (got_counters && metric->GetIOCounters(&io_after)) { 1515 if (got_counters && metric->GetIOCounters(&io_after)) {
1526 UMA_HISTOGRAM_COUNTS("SB2.BuildReadKilobytes", 1516 UMA_HISTOGRAM_COUNTS("SB2.BuildReadKilobytes",
1527 static_cast<int>(io_after.ReadTransferCount - 1517 static_cast<int>(io_after.ReadTransferCount -
1528 io_before.ReadTransferCount) / 1024); 1518 io_before.ReadTransferCount) / 1024);
1529 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteKilobytes", 1519 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteKilobytes",
1530 static_cast<int>(io_after.WriteTransferCount - 1520 static_cast<int>(io_after.WriteTransferCount -
1531 io_before.WriteTransferCount) / 1024); 1521 io_before.WriteTransferCount) / 1024);
1532 UMA_HISTOGRAM_COUNTS("SB2.BuildReadOperations", 1522 UMA_HISTOGRAM_COUNTS("SB2.BuildReadOperations",
1533 static_cast<int>(io_after.ReadOperationCount - 1523 static_cast<int>(io_after.ReadOperationCount -
1534 io_before.ReadOperationCount)); 1524 io_before.ReadOperationCount));
1535 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteOperations", 1525 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteOperations",
1536 static_cast<int>(io_after.WriteOperationCount - 1526 static_cast<int>(io_after.WriteOperationCount -
1537 io_before.WriteOperationCount)); 1527 io_before.WriteOperationCount));
1538 } 1528 }
1539 1529
1540 const int64 file_size = GetFileSizeOrZero(db_filename); 1530 RecordFileSizeHistogram(db_filename);
1541 UMA_HISTOGRAM_COUNTS("SB2.DatabaseKilobytes",
1542 static_cast<int>(file_size / 1024));
1543 1531
1544 #if defined(OS_MACOSX) 1532 #if defined(OS_MACOSX)
1545 base::mac::SetFileBackupExclusion(db_filename); 1533 base::mac::SetFileBackupExclusion(db_filename);
1546 #endif 1534 #endif
1547 } 1535 }
1548 1536
1549 void SafeBrowsingDatabaseNew::UpdateIpBlacklistStore() { 1537 void SafeBrowsingDatabaseNew::UpdateIpBlacklistStore() {
1550 DCHECK(thread_checker_.CalledOnValidThread()); 1538 DCHECK(thread_checker_.CalledOnValidThread());
1551 1539
1552 // Note: prefixes will not be empty. The current data store implementation 1540 // Note: prefixes will not be empty. The current data store implementation
1553 // stores all full-length hashes as both full and prefix hashes. 1541 // stores all full-length hashes as both full and prefix hashes.
1554 PrefixSetBuilder builder; 1542 PrefixSetBuilder builder;
1555 std::vector<SBAddFullHash> full_hashes; 1543 std::vector<SBAddFullHash> full_hashes;
1556 if (!ip_blacklist_store_->FinishUpdate(&builder, &full_hashes)) { 1544 if (!ip_blacklist_store_->FinishUpdate(&builder, &full_hashes)) {
1557 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_FINISH); 1545 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_FINISH);
1558 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. 1546 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list.
1559 return; 1547 return;
1560 } 1548 }
1561 1549
1550 const base::FilePath ip_blacklist_filename =
1551 IpBlacklistDBFilename(filename_base_);
1552
1553 RecordFileSizeHistogram(ip_blacklist_filename);
1554
1562 #if defined(OS_MACOSX) 1555 #if defined(OS_MACOSX)
1563 base::mac::SetFileBackupExclusion(IpBlacklistDBFilename(filename_base_)); 1556 base::mac::SetFileBackupExclusion(ip_blacklist_filename);
1564 #endif 1557 #endif
1565 1558
1566 LoadIpBlacklist(full_hashes); 1559 LoadIpBlacklist(full_hashes);
1567 } 1560 }
1568 1561
1569 void SafeBrowsingDatabaseNew::HandleCorruptDatabase() { 1562 void SafeBrowsingDatabaseNew::HandleCorruptDatabase() {
1570 DCHECK(thread_checker_.CalledOnValidThread()); 1563 DCHECK(thread_checker_.CalledOnValidThread());
1571 1564
1572 // Reset the database after the current task has unwound (but only 1565 // Reset the database after the current task has unwound (but only
1573 // reset once within the scope of a given task). 1566 // reset once within the scope of a given task).
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1696 1689
1697 const bool r11 = 1690 const bool r11 =
1698 base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false); 1691 base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false);
1699 if (!r11) 1692 if (!r11)
1700 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); 1693 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE);
1701 1694
1702 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; 1695 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11;
1703 } 1696 }
1704 1697
1705 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, 1698 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,
1706 const PrefixSet* prefix_set, 1699 PrefixSetId prefix_set_id,
1707 FailureType write_failure_type) { 1700 FailureType write_failure_type) {
1708 DCHECK(thread_checker_.CalledOnValidThread()); 1701 DCHECK(thread_checker_.CalledOnValidThread());
1709 1702
1703 // Do not grab the lock to avoid contention while writing to disk. This is
1704 // safe as only this thread can ever modify |state_manager_|'s prefix sets
1705 // anyways.
1706 scoped_ptr<ReadTransaction> txn =
1707 state_manager_.BeginReadTransactionNoLockOnMainThread();
1708 const PrefixSet* prefix_set = txn->GetPrefixSet(prefix_set_id);
1709
1710 if (!prefix_set) 1710 if (!prefix_set)
1711 return; 1711 return;
1712 1712
1713 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename); 1713 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename);
1714 1714
1715 const base::TimeTicks before = base::TimeTicks::Now(); 1715 const base::TimeTicks before = base::TimeTicks::Now();
1716 const bool write_ok = prefix_set->WriteFile(prefix_set_filename); 1716 const bool write_ok = prefix_set->WriteFile(prefix_set_filename);
1717 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before); 1717 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before);
1718 1718
1719 const int64 file_size = GetFileSizeOrZero(prefix_set_filename); 1719 RecordFileSizeHistogram(prefix_set_filename);
1720 UMA_HISTOGRAM_COUNTS("SB2.PrefixSetKilobytes",
1721 static_cast<int>(file_size / 1024));
1722 1720
1723 if (!write_ok) 1721 if (!write_ok)
1724 RecordFailure(write_failure_type); 1722 RecordFailure(write_failure_type);
1725 1723
1726 #if defined(OS_MACOSX) 1724 #if defined(OS_MACOSX)
1727 base::mac::SetFileBackupExclusion(prefix_set_filename); 1725 base::mac::SetFileBackupExclusion(prefix_set_filename);
1728 #endif 1726 #endif
1729 } 1727 }
1730 1728
1731 void SafeBrowsingDatabaseNew::LoadWhitelist( 1729 void SafeBrowsingDatabaseNew::LoadWhitelist(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() { 1805 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() {
1808 return state_manager_.BeginReadTransaction() 1806 return state_manager_.BeginReadTransaction()
1809 ->GetSBWhitelist(SBWhitelistId::CSD) 1807 ->GetSBWhitelist(SBWhitelistId::CSD)
1810 ->second; 1808 ->second;
1811 } 1809 }
1812 1810
1813 SafeBrowsingDatabaseNew::PrefixGetHashCache* 1811 SafeBrowsingDatabaseNew::PrefixGetHashCache*
1814 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() { 1812 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() {
1815 return state_manager_.BeginReadTransaction()->prefix_gethash_cache(); 1813 return state_manager_.BeginReadTransaction()->prefix_gethash_cache();
1816 } 1814 }
1815
1816 void SafeBrowsingDatabaseNew::RecordFileSizeHistogram(
1817 const base::FilePath& file_path) {
1818 const int64 file_size = GetFileSizeOrZero(file_path);
1819 const int file_size_kilobytes = static_cast<int>(file_size / 1024);
1820
1821 base::FilePath::StringType filename = file_path.BaseName().value();
1822
1823 // Default to logging DB sizes unless |file_path| points at PrefixSet storage.
1824 std::string histogram_name("SB2.DatabaseSizeKilobytes");
1825 if (EndsWith(filename, kPrefixSetFileSuffix, true)) {
1826 histogram_name = "SB2.PrefixSetKilobytes";
1827 // Clear the PrefixSet suffix to have the histogram suffix selector below
1828 // work the same for PrefixSet-based storage as it does for simple safe
1829 // browsing stores.
1830 // The size of the kPrefixSetFileSuffix is the size of its array minus 1 as
1831 // the array includes the terminating '\0'.
1832 const size_t kPrefixSetSuffixSize = arraysize(kPrefixSetFileSuffix) - 1;
1833 filename.erase(filename.size() - kPrefixSetSuffixSize);
1834 }
1835
1836 // Changes to histogram suffixes below need to be mirrored in the
1837 // SafeBrowsingLists suffix enum in histograms.xml.
1838 if (EndsWith(filename, kBrowseDBFile, true))
1839 histogram_name.append(".Browse");
1840 else if (EndsWith(filename, kDownloadDBFile, true))
1841 histogram_name.append(".Download");
1842 else if (EndsWith(filename, kCsdWhitelistDBFile, true))
1843 histogram_name.append(".CsdWhitelist");
1844 else if (EndsWith(filename, kDownloadWhitelistDBFile, true))
1845 histogram_name.append(".DownloadWhitelist");
1846 else if (EndsWith(filename, kExtensionBlacklistDBFile, true))
1847 histogram_name.append(".ExtensionBlacklist");
1848 else if (EndsWith(filename, kSideEffectFreeWhitelistDBFile, true))
1849 histogram_name.append(".SideEffectFreeWhitelist");
1850 else if (EndsWith(filename, kIPBlacklistDBFile, true))
1851 histogram_name.append(".IPBlacklist");
1852 else if (EndsWith(filename, kUnwantedSoftwareDBFile, true))
1853 histogram_name.append(".UnwantedSoftware");
1854 else
1855 NOTREACHED(); // Add support for new lists above.
1856
1857 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1858 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1859 histogram_name, 1, 1000000, 50,
1860 base::HistogramBase::kUmaTargetedHistogramFlag);
1861
1862 histogram_pointer->Add(file_size_kilobytes);
1863 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698