Index: chrome/browser/safe_browsing/safe_browsing_database.cc |
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc |
index 7b72de14a37b03cad171cfb0f60d8810e48a62b8..d93185715c854740c881300bd28e3741f40fab96 100644 |
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc |
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc |
@@ -70,6 +70,9 @@ const base::FilePath::CharType kIPBlacklistDBFile[] = |
// Filename suffix for the unwanted software blacklist store. |
const base::FilePath::CharType kUnwantedSoftwareDBFile[] = |
FILE_PATH_LITERAL(" UwS List"); |
+// Filename suffix for the resource blacklist store. |
+const base::FilePath::CharType kResourceBlacklistDBFile[] = |
+ FILE_PATH_LITERAL(" Resource Blacklist"); |
// Filename suffix for browse store. |
// TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. |
@@ -288,7 +291,8 @@ class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
CreateStore(true, db_task_runner), // inclusion_whitelist_store |
CreateStore(enable_extension_blacklist, db_task_runner), |
CreateStore(enable_ip_blacklist, db_task_runner), |
- CreateStore(enable_unwanted_software_list, db_task_runner)); |
+ CreateStore(enable_unwanted_software_list, db_task_runner), |
+ CreateStore(true, db_task_runner)); // resource_blacklist_store |
} |
SafeBrowsingDatabaseFactoryImpl() {} |
@@ -392,6 +396,12 @@ base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( |
} |
// static |
+base::FilePath SafeBrowsingDatabase::ResourceBlacklistDBFilename( |
+ const base::FilePath& db_filename) { |
+ return base::FilePath(db_filename.value() + kResourceBlacklistDBFile); |
+} |
+ |
+// static |
void SafeBrowsingDatabase::GetDownloadUrlPrefixes( |
const std::vector<GURL>& urls, |
std::vector<SBPrefix>* prefixes) { |
@@ -423,6 +433,8 @@ SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) { |
return ip_blacklist_store_.get(); |
} else if (list_id == UNWANTEDURL) { |
return unwanted_software_store_.get(); |
+ } else if (list_id == RESOURCEBLACKLIST) { |
+ return resource_blacklist_store_.get(); |
} |
return NULL; |
} |
@@ -605,7 +617,8 @@ SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
SafeBrowsingStore* inclusion_whitelist_store, |
SafeBrowsingStore* extension_blacklist_store, |
SafeBrowsingStore* ip_blacklist_store, |
- SafeBrowsingStore* unwanted_software_store) |
+ SafeBrowsingStore* unwanted_software_store, |
+ SafeBrowsingStore* resource_blacklist_store) |
: db_task_runner_(db_task_runner), |
state_manager_(db_task_runner_), |
db_state_manager_(db_task_runner_), |
@@ -617,6 +630,7 @@ SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
extension_blacklist_store_(extension_blacklist_store), |
ip_blacklist_store_(ip_blacklist_store), |
unwanted_software_store_(unwanted_software_store), |
+ resource_blacklist_store_(resource_blacklist_store), |
reset_factory_(this) { |
DCHECK(browse_store_.get()); |
} |
@@ -763,6 +777,13 @@ void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { |
LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. |
} |
} |
+ |
+ if (resource_blacklist_store_.get()) { |
+ resource_blacklist_store_->Init( |
+ ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
+ base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
+ base::Unretained(this))); |
+ } |
} |
bool SafeBrowsingDatabaseNew::ResetDatabase() { |
@@ -945,6 +966,18 @@ bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { |
return false; |
} |
+bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes( |
+ const std::vector<SBPrefix>& prefixes, |
+ std::vector<SBPrefix>* prefix_hits) { |
+ DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
+ |
+ if (!resource_blacklist_store_) |
+ return false; |
+ |
+ return MatchAddPrefixes(resource_blacklist_store_.get(), |
+ RESOURCEBLACKLIST % 2, prefixes, prefix_hits); |
+} |
+ |
bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( |
const std::string& str) { |
std::vector<SBFullHash> hashes; |
@@ -1175,6 +1208,12 @@ bool SafeBrowsingDatabaseNew::UpdateStarted( |
return false; |
} |
+ if (resource_blacklist_store_ && !resource_blacklist_store_->BeginUpdate()) { |
+ RecordFailure(FAILURE_RESOURCE_BLACKLIST_UPDATE_BEGIN); |
+ HandleCorruptDatabase(); |
+ return false; |
+ } |
+ |
// Cached fullhash results must be cleared on every database update (whether |
// successful or not). |
state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
@@ -1204,6 +1243,9 @@ bool SafeBrowsingDatabaseNew::UpdateStarted( |
UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
lists); |
+ UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist, |
+ lists); |
+ |
db_state_manager_.reset_corruption_detected(); |
db_state_manager_.reset_change_detected(); |
return true; |
@@ -1251,6 +1293,11 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
!unwanted_software_store_->CheckValidity()) { |
DLOG(ERROR) << "Unwanted software url list database corrupt."; |
} |
+ |
+ if (resource_blacklist_store_ && |
+ !resource_blacklist_store_->CheckValidity()) { |
+ DLOG(ERROR) << "Resources blacklist url list database corrupt."; |
+ } |
} |
if (db_state_manager_.corruption_detected()) |
@@ -1278,6 +1325,8 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
ip_blacklist_store_->CancelUpdate(); |
if (unwanted_software_store_) |
unwanted_software_store_->CancelUpdate(); |
+ if (resource_blacklist_store_) |
+ resource_blacklist_store_->CancelUpdate(); |
return; |
} |
@@ -1319,6 +1368,13 @@ void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); |
} |
+ |
+ if (resource_blacklist_store_) { |
+ UpdateHashPrefixStore( |
+ ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
+ resource_blacklist_store_.get(), |
+ FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH); |
+ } |
} |
void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
@@ -1602,7 +1658,12 @@ bool SafeBrowsingDatabaseNew::Delete() { |
if (!r10) |
RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); |
- return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10; |
+ const bool r11 = base::DeleteFile( |
+ ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false); |
+ if (!r11) |
+ RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE); |
+ |
+ return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; |
} |
void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, |
@@ -1768,6 +1829,9 @@ void SafeBrowsingDatabaseNew::RecordFileSizeHistogram( |
else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, |
base::CompareCase::SENSITIVE)) |
histogram_name.append(".UnwantedSoftware"); |
+ else if (base::EndsWith(filename, kResourceBlacklistDBFile, |
+ base::CompareCase::SENSITIVE)) |
+ histogram_name.append(".ResourceBlacklist"); |
else |
NOTREACHED(); // Add support for new lists above. |