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

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

Issue 611603002: Add the goog-unwanted-shavar list to a new SafeBrowsing PrefixSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: browser tests Created 6 years, 1 month 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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 FILE_PATH_LITERAL(" Download Whitelist"); 50 FILE_PATH_LITERAL(" Download Whitelist");
51 // Filename suffix for the extension blacklist store. 51 // Filename suffix for the extension blacklist store.
52 const base::FilePath::CharType kExtensionBlacklistDBFile[] = 52 const base::FilePath::CharType kExtensionBlacklistDBFile[] =
53 FILE_PATH_LITERAL(" Extension Blacklist"); 53 FILE_PATH_LITERAL(" Extension Blacklist");
54 // Filename suffix for the side-effect free whitelist store. 54 // Filename suffix for the side-effect free whitelist store.
55 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = 55 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] =
56 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); 56 FILE_PATH_LITERAL(" Side-Effect Free Whitelist");
57 // Filename suffix for the csd malware IP blacklist store. 57 // Filename suffix for the csd malware IP blacklist store.
58 const base::FilePath::CharType kIPBlacklistDBFile[] = 58 const base::FilePath::CharType kIPBlacklistDBFile[] =
59 FILE_PATH_LITERAL(" IP Blacklist"); 59 FILE_PATH_LITERAL(" IP Blacklist");
60 // Filename suffix for the unwanted software blacklist store.
61 const base::FilePath::CharType kUnwantedSoftwareDBFile[] =
62 FILE_PATH_LITERAL(" UwS List");
60 63
61 // Filename suffix for browse store. 64 // Filename suffix for browse store.
62 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. 65 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win.
63 // Unfortunately, to change the name implies lots of transition code 66 // Unfortunately, to change the name implies lots of transition code
64 // for little benefit. If/when file formats change (say to put all 67 // for little benefit. If/when file formats change (say to put all
65 // the data in one file), that would be a convenient point to rectify 68 // the data in one file), that would be a convenient point to rectify
66 // this. 69 // this.
67 // TODO(shess): This shouldn't be OS-driven <http://crbug.com/394379> 70 // TODO(shess): This shouldn't be OS-driven <http://crbug.com/394379>
68 #if defined(OS_ANDROID) 71 #if defined(OS_ANDROID)
69 // NOTE(shess): This difference is also reflected in the list name in 72 // NOTE(shess): This difference is also reflected in the list name in
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Generate the set of full hashes to check for |url|. If 118 // Generate the set of full hashes to check for |url|. If
116 // |include_whitelist_hashes| is true we will generate additional path-prefixes 119 // |include_whitelist_hashes| is true we will generate additional path-prefixes
117 // to match against the csd whitelist. E.g., if the path-prefix /foo is on the 120 // to match against the csd whitelist. E.g., if the path-prefix /foo is on the
118 // whitelist it should also match /foo/bar which is not the case for all the 121 // whitelist it should also match /foo/bar which is not the case for all the
119 // other lists. We'll also always add a pattern for the empty path. 122 // other lists. We'll also always add a pattern for the empty path.
120 // TODO(shess): This function is almost the same as 123 // TODO(shess): This function is almost the same as
121 // |CompareFullHashes()| in safe_browsing_util.cc, except that code 124 // |CompareFullHashes()| in safe_browsing_util.cc, except that code
122 // does an early exit on match. Since match should be the infrequent 125 // does an early exit on match. Since match should be the infrequent
123 // case (phishing or malware found), consider combining this function 126 // case (phishing or malware found), consider combining this function
124 // with that one. 127 // with that one.
125 void BrowseFullHashesToCheck(const GURL& url, 128 void UrlToFullHashes(const GURL& url,
126 bool include_whitelist_hashes, 129 bool include_whitelist_hashes,
127 std::vector<SBFullHash>* full_hashes) { 130 std::vector<SBFullHash>* full_hashes) {
128 std::vector<std::string> hosts; 131 std::vector<std::string> hosts;
129 if (url.HostIsIPAddress()) { 132 if (url.HostIsIPAddress()) {
130 hosts.push_back(url.host()); 133 hosts.push_back(url.host());
131 } else { 134 } else {
132 safe_browsing_util::GenerateHostsToCheck(url, &hosts); 135 safe_browsing_util::GenerateHostsToCheck(url, &hosts);
133 } 136 }
134 137
135 std::vector<std::string> paths; 138 std::vector<std::string> paths;
136 safe_browsing_util::GeneratePathsToCheck(url, &paths); 139 safe_browsing_util::GeneratePathsToCheck(url, &paths);
137 140
(...skipping 13 matching lines...) Expand all
151 } 154 }
152 } 155 }
153 } 156 }
154 } 157 }
155 158
156 // Get the prefixes matching the download |urls|. 159 // Get the prefixes matching the download |urls|.
157 void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, 160 void GetDownloadUrlPrefixes(const std::vector<GURL>& urls,
158 std::vector<SBPrefix>* prefixes) { 161 std::vector<SBPrefix>* prefixes) {
159 std::vector<SBFullHash> full_hashes; 162 std::vector<SBFullHash> full_hashes;
160 for (size_t i = 0; i < urls.size(); ++i) 163 for (size_t i = 0; i < urls.size(); ++i)
161 BrowseFullHashesToCheck(urls[i], false, &full_hashes); 164 UrlToFullHashes(urls[i], false, &full_hashes);
162 165
163 for (size_t i = 0; i < full_hashes.size(); ++i) 166 for (size_t i = 0; i < full_hashes.size(); ++i)
164 prefixes->push_back(full_hashes[i].prefix); 167 prefixes->push_back(full_hashes[i].prefix);
165 } 168 }
166 169
167 // Helper function to compare addprefixes in |store| with |prefixes|. 170 // Helper function to compare addprefixes in |store| with |prefixes|.
168 // The |list_bit| indicates which list (url or hash) to compare. 171 // The |list_bit| indicates which list (url or hash) to compare.
169 // 172 //
170 // Returns true if there is a match, |*prefix_hits| (if non-NULL) will contain 173 // Returns true if there is a match, |*prefix_hits| (if non-NULL) will contain
171 // the actual matching prefixes. 174 // the actual matching prefixes.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 DCHECK_EQ(safe_browsing_util::GetListId(listname) % 2, 248 DCHECK_EQ(safe_browsing_util::GetListId(listname) % 2,
246 static_cast<int>(i % 2)); 249 static_cast<int>(i % 2));
247 DCHECK_NE(safe_browsing_util::GetListId(listname), 250 DCHECK_NE(safe_browsing_util::GetListId(listname),
248 safe_browsing_util::INVALID); 251 safe_browsing_util::INVALID);
249 lists->push_back(SBListChunkRanges(listname)); 252 lists->push_back(SBListChunkRanges(listname));
250 lists->back().adds.swap(adds[i]); 253 lists->back().adds.swap(adds[i]);
251 lists->back().subs.swap(subs[i]); 254 lists->back().subs.swap(subs[i]);
252 } 255 }
253 } 256 }
254 257
255 void UpdateChunkRangesForLists(SafeBrowsingStore* store, 258 void UpdateChunkRangesForBrowseLists(SafeBrowsingStore* store,
256 const std::string& listname0, 259 const std::string& listname0,
257 const std::string& listname1, 260 const std::string& listname1,
258 std::vector<SBListChunkRanges>* lists) { 261 std::vector<SBListChunkRanges>* lists) {
259 std::vector<std::string> listnames; 262 std::vector<std::string> listnames;
260 listnames.push_back(listname0); 263 listnames.push_back(listname0);
261 listnames.push_back(listname1); 264 listnames.push_back(listname1);
262 UpdateChunkRanges(store, listnames, lists); 265 UpdateChunkRanges(store, listnames, lists);
263 } 266 }
264 267
265 void UpdateChunkRangesForList(SafeBrowsingStore* store, 268 void UpdateChunkRangesForList(SafeBrowsingStore* store,
266 const std::string& listname, 269 const std::string& listname,
267 std::vector<SBListChunkRanges>* lists) { 270 std::vector<SBListChunkRanges>* lists) {
268 UpdateChunkRanges(store, std::vector<std::string>(1, listname), lists); 271 UpdateChunkRanges(store, std::vector<std::string>(1, listname), lists);
269 } 272 }
270 273
271 // This code always checks for non-zero file size. This helper makes 274 // This code always checks for non-zero file size. This helper makes
272 // that less verbose. 275 // that less verbose.
273 int64 GetFileSizeOrZero(const base::FilePath& file_path) { 276 int64 GetFileSizeOrZero(const base::FilePath& file_path) {
274 int64 size_64; 277 int64 size_64;
275 if (!base::GetFileSize(file_path, &size_64)) 278 if (!base::GetFileSize(file_path, &size_64))
276 return 0; 279 return 0;
277 return size_64; 280 return size_64;
278 } 281 }
279 282
280 // Helper for ContainsBrowseUrlHashes(). Returns true if an un-expired match 283 // Helper for PrefixSetContainsUrlHashes(). Returns true if an un-expired match
281 // for |full_hash| is found in |cache|, with any matches appended to |results| 284 // for |full_hash| is found in |cache|, with any matches appended to |results|
282 // (true can be returned with zero matches). |expire_base| is used to check the 285 // (true can be returned with zero matches). |expire_base| is used to check the
283 // cache lifetime of matches, expired matches will be discarded from |cache|. 286 // cache lifetime of matches, expired matches will be discarded from |cache|.
284 bool GetCachedFullHash(std::map<SBPrefix, SBCachedFullHashResult>* cache, 287 bool GetCachedFullHash(std::map<SBPrefix, SBCachedFullHashResult>* cache,
285 const SBFullHash& full_hash, 288 const SBFullHash& full_hash,
286 const base::Time& expire_base, 289 const base::Time& expire_base,
287 std::vector<SBFullHashResult>* results) { 290 std::vector<SBFullHashResult>* results) {
288 // First check if there is a valid cached result for this prefix. 291 // First check if there is a valid cached result for this prefix.
289 std::map<SBPrefix, SBCachedFullHashResult>::iterator 292 std::map<SBPrefix, SBCachedFullHashResult>::iterator
290 citer = cache->find(full_hash.prefix); 293 citer = cache->find(full_hash.prefix);
(...skipping 21 matching lines...) Expand all
312 315
313 // The default SafeBrowsingDatabaseFactory. 316 // The default SafeBrowsingDatabaseFactory.
314 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { 317 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory {
315 public: 318 public:
316 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( 319 SafeBrowsingDatabase* CreateSafeBrowsingDatabase(
317 bool enable_download_protection, 320 bool enable_download_protection,
318 bool enable_client_side_whitelist, 321 bool enable_client_side_whitelist,
319 bool enable_download_whitelist, 322 bool enable_download_whitelist,
320 bool enable_extension_blacklist, 323 bool enable_extension_blacklist,
321 bool enable_side_effect_free_whitelist, 324 bool enable_side_effect_free_whitelist,
322 bool enable_ip_blacklist) override { 325 bool enable_ip_blacklist,
326 bool enable_unwanted_software_list) override {
323 return new SafeBrowsingDatabaseNew( 327 return new SafeBrowsingDatabaseNew(
324 new SafeBrowsingStoreFile, 328 new SafeBrowsingStoreFile,
325 enable_download_protection ? new SafeBrowsingStoreFile : NULL, 329 enable_download_protection ? new SafeBrowsingStoreFile : NULL,
326 enable_client_side_whitelist ? new SafeBrowsingStoreFile : NULL, 330 enable_client_side_whitelist ? new SafeBrowsingStoreFile : NULL,
327 enable_download_whitelist ? new SafeBrowsingStoreFile : NULL, 331 enable_download_whitelist ? new SafeBrowsingStoreFile : NULL,
328 enable_extension_blacklist ? new SafeBrowsingStoreFile : NULL, 332 enable_extension_blacklist ? new SafeBrowsingStoreFile : NULL,
329 enable_side_effect_free_whitelist ? new SafeBrowsingStoreFile : NULL, 333 enable_side_effect_free_whitelist ? new SafeBrowsingStoreFile : NULL,
330 enable_ip_blacklist ? new SafeBrowsingStoreFile : NULL); 334 enable_ip_blacklist ? new SafeBrowsingStoreFile : NULL,
335 enable_unwanted_software_list ? new SafeBrowsingStoreFile : NULL);
331 } 336 }
332 337
333 SafeBrowsingDatabaseFactoryImpl() { } 338 SafeBrowsingDatabaseFactoryImpl() { }
334 339
335 private: 340 private:
336 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); 341 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl);
337 }; 342 };
338 343
339 // static 344 // static
340 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; 345 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL;
341 346
342 // Factory method, non-thread safe. Caller has to make sure this s called 347 // Factory method, non-thread safe. Caller has to make sure this s called
343 // on SafeBrowsing Thread. 348 // on SafeBrowsing Thread.
344 // TODO(shess): There's no need for a factory any longer. Convert 349 // TODO(shess): There's no need for a factory any longer. Convert
345 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() 350 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create()
346 // callers just construct things directly. 351 // callers just construct things directly.
347 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( 352 SafeBrowsingDatabase* SafeBrowsingDatabase::Create(
348 bool enable_download_protection, 353 bool enable_download_protection,
349 bool enable_client_side_whitelist, 354 bool enable_client_side_whitelist,
350 bool enable_download_whitelist, 355 bool enable_download_whitelist,
351 bool enable_extension_blacklist, 356 bool enable_extension_blacklist,
352 bool enable_side_effect_free_whitelist, 357 bool enable_side_effect_free_whitelist,
353 bool enable_ip_blacklist) { 358 bool enable_ip_blacklist,
359 bool enable_unwanted_software_list) {
354 if (!factory_) 360 if (!factory_)
355 factory_ = new SafeBrowsingDatabaseFactoryImpl(); 361 factory_ = new SafeBrowsingDatabaseFactoryImpl();
356 return factory_->CreateSafeBrowsingDatabase( 362 return factory_->CreateSafeBrowsingDatabase(
357 enable_download_protection, 363 enable_download_protection,
358 enable_client_side_whitelist, 364 enable_client_side_whitelist,
359 enable_download_whitelist, 365 enable_download_whitelist,
360 enable_extension_blacklist, 366 enable_extension_blacklist,
361 enable_side_effect_free_whitelist, 367 enable_side_effect_free_whitelist,
362 enable_ip_blacklist); 368 enable_ip_blacklist,
369 enable_unwanted_software_list);
363 } 370 }
364 371
365 SafeBrowsingDatabase::~SafeBrowsingDatabase() { 372 SafeBrowsingDatabase::~SafeBrowsingDatabase() {
366 } 373 }
367 374
368 // static 375 // static
369 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( 376 base::FilePath SafeBrowsingDatabase::BrowseDBFilename(
370 const base::FilePath& db_base_filename) { 377 const base::FilePath& db_base_filename) {
371 return base::FilePath(db_base_filename.value() + kBrowseDBFile); 378 return base::FilePath(db_base_filename.value() + kBrowseDBFile);
372 } 379 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 const base::FilePath& db_filename) { 419 const base::FilePath& db_filename) {
413 return base::FilePath(db_filename.value() + kSideEffectFreeWhitelistDBFile); 420 return base::FilePath(db_filename.value() + kSideEffectFreeWhitelistDBFile);
414 } 421 }
415 422
416 // static 423 // static
417 base::FilePath SafeBrowsingDatabase::IpBlacklistDBFilename( 424 base::FilePath SafeBrowsingDatabase::IpBlacklistDBFilename(
418 const base::FilePath& db_filename) { 425 const base::FilePath& db_filename) {
419 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); 426 return base::FilePath(db_filename.value() + kIPBlacklistDBFile);
420 } 427 }
421 428
429 // static
430 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename(
431 const base::FilePath& db_filename) {
432 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile);
433 }
434
422 SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) { 435 SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) {
423 if (list_id == safe_browsing_util::PHISH || 436 if (list_id == safe_browsing_util::PHISH ||
424 list_id == safe_browsing_util::MALWARE) { 437 list_id == safe_browsing_util::MALWARE) {
425 return browse_store_.get(); 438 return browse_store_.get();
426 } else if (list_id == safe_browsing_util::BINURL) { 439 } else if (list_id == safe_browsing_util::BINURL) {
427 return download_store_.get(); 440 return download_store_.get();
428 } else if (list_id == safe_browsing_util::CSDWHITELIST) { 441 } else if (list_id == safe_browsing_util::CSDWHITELIST) {
429 return csd_whitelist_store_.get(); 442 return csd_whitelist_store_.get();
430 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) { 443 } else if (list_id == safe_browsing_util::DOWNLOADWHITELIST) {
431 return download_whitelist_store_.get(); 444 return download_whitelist_store_.get();
432 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) { 445 } else if (list_id == safe_browsing_util::EXTENSIONBLACKLIST) {
433 return extension_blacklist_store_.get(); 446 return extension_blacklist_store_.get();
434 } else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) { 447 } else if (list_id == safe_browsing_util::SIDEEFFECTFREEWHITELIST) {
435 return side_effect_free_whitelist_store_.get(); 448 return side_effect_free_whitelist_store_.get();
436 } else if (list_id == safe_browsing_util::IPBLACKLIST) { 449 } else if (list_id == safe_browsing_util::IPBLACKLIST) {
437 return ip_blacklist_store_.get(); 450 return ip_blacklist_store_.get();
451 } else if (list_id == safe_browsing_util::UNWANTEDURL) {
452 return unwanted_software_store_.get();
438 } 453 }
439 return NULL; 454 return NULL;
440 } 455 }
441 456
442 // static 457 // static
443 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { 458 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) {
444 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, 459 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type,
445 FAILURE_DATABASE_MAX); 460 FAILURE_DATABASE_MAX);
446 } 461 }
447 462
448 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew() 463 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew()
449 : creation_loop_(base::MessageLoop::current()), 464 : creation_loop_(base::MessageLoop::current()),
450 browse_store_(new SafeBrowsingStoreFile), 465 browse_store_(new SafeBrowsingStoreFile),
451 corruption_detected_(false), 466 corruption_detected_(false),
452 change_detected_(false), 467 change_detected_(false),
453 reset_factory_(this) { 468 reset_factory_(this) {
454 DCHECK(browse_store_.get()); 469 DCHECK(browse_store_.get());
455 DCHECK(!download_store_.get()); 470 DCHECK(!download_store_.get());
456 DCHECK(!csd_whitelist_store_.get()); 471 DCHECK(!csd_whitelist_store_.get());
457 DCHECK(!download_whitelist_store_.get()); 472 DCHECK(!download_whitelist_store_.get());
458 DCHECK(!extension_blacklist_store_.get()); 473 DCHECK(!extension_blacklist_store_.get());
459 DCHECK(!side_effect_free_whitelist_store_.get()); 474 DCHECK(!side_effect_free_whitelist_store_.get());
460 DCHECK(!ip_blacklist_store_.get()); 475 DCHECK(!ip_blacklist_store_.get());
476 DCHECK(!unwanted_software_store_.get());
461 } 477 }
462 478
463 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( 479 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
464 SafeBrowsingStore* browse_store, 480 SafeBrowsingStore* browse_store,
465 SafeBrowsingStore* download_store, 481 SafeBrowsingStore* download_store,
466 SafeBrowsingStore* csd_whitelist_store, 482 SafeBrowsingStore* csd_whitelist_store,
467 SafeBrowsingStore* download_whitelist_store, 483 SafeBrowsingStore* download_whitelist_store,
468 SafeBrowsingStore* extension_blacklist_store, 484 SafeBrowsingStore* extension_blacklist_store,
469 SafeBrowsingStore* side_effect_free_whitelist_store, 485 SafeBrowsingStore* side_effect_free_whitelist_store,
470 SafeBrowsingStore* ip_blacklist_store) 486 SafeBrowsingStore* ip_blacklist_store,
487 SafeBrowsingStore* unwanted_software_store)
471 : creation_loop_(base::MessageLoop::current()), 488 : creation_loop_(base::MessageLoop::current()),
472 browse_store_(browse_store), 489 browse_store_(browse_store),
473 download_store_(download_store), 490 download_store_(download_store),
474 csd_whitelist_store_(csd_whitelist_store), 491 csd_whitelist_store_(csd_whitelist_store),
475 download_whitelist_store_(download_whitelist_store), 492 download_whitelist_store_(download_whitelist_store),
476 extension_blacklist_store_(extension_blacklist_store), 493 extension_blacklist_store_(extension_blacklist_store),
477 side_effect_free_whitelist_store_(side_effect_free_whitelist_store), 494 side_effect_free_whitelist_store_(side_effect_free_whitelist_store),
478 ip_blacklist_store_(ip_blacklist_store), 495 ip_blacklist_store_(ip_blacklist_store),
496 unwanted_software_store_(unwanted_software_store),
479 corruption_detected_(false), 497 corruption_detected_(false),
480 reset_factory_(this) { 498 reset_factory_(this) {
481 DCHECK(browse_store_.get()); 499 DCHECK(browse_store_.get());
482 } 500 }
483 501
484 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { 502 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() {
485 // The DCHECK is disabled due to crbug.com/338486 . 503 // The DCHECK is disabled due to crbug.com/338486 .
486 // DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 504 // DCHECK_EQ(creation_loop_, base::MessageLoop::current());
487 } 505 }
488 506
489 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { 507 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) {
490 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 508 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
491 509
492 // This should not be run multiple times. 510 // This should not be run multiple times.
493 DCHECK(filename_base_.empty()); 511 DCHECK(filename_base_.empty());
494 512
495 filename_base_ = filename_base; 513 filename_base_ = filename_base;
496 514
497 // TODO(shess): The various stores are really only necessary while doing 515 // TODO(shess): The various stores are really only necessary while doing
498 // updates, or when querying a store directly (see |ContainsDownloadUrl()|). 516 // updates (see |UpdateFinished()|) or when querying a store directly (see
517 // |ContainsDownloadUrl()|).
499 // The store variables are also tested to see if a list is enabled. Perhaps 518 // The store variables are also tested to see if a list is enabled. Perhaps
500 // the stores could be refactored into an update object so that they are only 519 // the stores could be refactored into an update object so that they are only
501 // live in memory while being actively used. The sense of enabled probably 520 // live in memory while being actively used. The sense of enabled probably
502 // belongs in protocol_manager or database_manager. 521 // belongs in protocol_manager or database_manager.
503 522
504 browse_store_->Init( 523 browse_store_->Init(
505 BrowseDBFilename(filename_base_), 524 BrowseDBFilename(filename_base_),
506 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 525 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
507 base::Unretained(this))); 526 base::Unretained(this)));
508 527
509 { 528 {
510 // NOTE: There is no need to grab the lock in this function, since 529 // NOTE: There is no need to grab the lock in this function, since
511 // until it returns, there are no pointers to this class on other 530 // until it returns, there are no pointers to this class on other
512 // threads. Then again, that means there is no possibility of 531 // threads. Then again, that means there is no possibility of
513 // contention on the lock... 532 // contention on the lock...
514 base::AutoLock locked(lookup_lock_); 533 base::AutoLock locked(lookup_lock_);
515 browse_gethash_cache_.clear(); 534 prefix_gethash_cache_.clear();
516 LoadPrefixSet(); 535 LoadPrefixSet(BrowseDBFilename(filename_base_), &browse_prefix_set_,
536 FAILURE_BROWSE_PREFIX_SET_READ);
517 } 537 }
518 538
519 if (download_store_.get()) { 539 if (download_store_.get()) {
520 download_store_->Init( 540 download_store_->Init(
521 DownloadDBFilename(filename_base_), 541 DownloadDBFilename(filename_base_),
522 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 542 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
523 base::Unretained(this))); 543 base::Unretained(this)));
524 } 544 }
525 545
526 if (csd_whitelist_store_.get()) { 546 if (csd_whitelist_store_.get()) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 619 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
600 base::Unretained(this))); 620 base::Unretained(this)));
601 621
602 std::vector<SBAddFullHash> full_hashes; 622 std::vector<SBAddFullHash> full_hashes;
603 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { 623 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) {
604 LoadIpBlacklist(full_hashes); 624 LoadIpBlacklist(full_hashes);
605 } else { 625 } else {
606 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. 626 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list.
607 } 627 }
608 } 628 }
629
630 if (unwanted_software_store_.get()) {
631 unwanted_software_store_->Init(
632 UnwantedSoftwareDBFilename(filename_base_),
633 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
634 base::Unretained(this)));
635 LoadPrefixSet(UnwantedSoftwareDBFilename(filename_base_),
636 &unwanted_software_prefix_set_,
637 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_READ);
mattm 2014/11/11 01:29:10 I guess this should be protected by lookup_lock to
gab 2014/11/11 23:39:11 Done (and moved it up to have it contextually clos
638 }
609 } 639 }
610 640
611 bool SafeBrowsingDatabaseNew::ResetDatabase() { 641 bool SafeBrowsingDatabaseNew::ResetDatabase() {
612 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 642 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
613 643
614 // Delete files on disk. 644 // Delete files on disk.
615 // TODO(shess): Hard to see where one might want to delete without a 645 // TODO(shess): Hard to see where one might want to delete without a
616 // reset. Perhaps inline |Delete()|? 646 // reset. Perhaps inline |Delete()|?
617 if (!Delete()) 647 if (!Delete())
618 return false; 648 return false;
619 649
620 // Reset objects in memory. 650 // Reset objects in memory.
621 { 651 {
622 base::AutoLock locked(lookup_lock_); 652 base::AutoLock locked(lookup_lock_);
623 browse_gethash_cache_.clear(); 653 prefix_gethash_cache_.clear();
624 browse_prefix_set_.reset(); 654 browse_prefix_set_.reset();
625 side_effect_free_whitelist_prefix_set_.reset(); 655 side_effect_free_whitelist_prefix_set_.reset();
626 ip_blacklist_.clear(); 656 ip_blacklist_.clear();
657 unwanted_software_prefix_set_.reset();
627 } 658 }
628 // Wants to acquire the lock itself. 659 // Wants to acquire the lock itself.
629 WhitelistEverything(&csd_whitelist_); 660 WhitelistEverything(&csd_whitelist_);
630 WhitelistEverything(&download_whitelist_); 661 WhitelistEverything(&download_whitelist_);
631 return true; 662 return true;
632 } 663 }
633 664
634 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl( 665 bool SafeBrowsingDatabaseNew::ContainsBrowseUrl(
635 const GURL& url, 666 const GURL& url,
636 std::vector<SBPrefix>* prefix_hits, 667 std::vector<SBPrefix>* prefix_hits,
637 std::vector<SBFullHashResult>* cache_hits) { 668 std::vector<SBFullHashResult>* cache_hits) {
669 return PrefixSetContainsUrl(url, browse_prefix_set_.get(), prefix_hits,
mattm 2014/11/11 01:29:10 the browse_prefix_set_.get() and unwanted_software
gab 2014/11/11 23:39:11 Ah I see makes sense now :-)! Tweaked to make it s
670 cache_hits);
671 }
672
673 bool SafeBrowsingDatabaseNew::ContainsUnwantedSoftwareUrl(
674 const GURL& url,
675 std::vector<SBPrefix>* prefix_hits,
676 std::vector<SBFullHashResult>* cache_hits) {
677 return PrefixSetContainsUrl(url, unwanted_software_prefix_set_.get(),
678 prefix_hits, cache_hits);
679 }
680
681 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrl(
682 const GURL& url,
683 safe_browsing::PrefixSet* prefix_set,
684 std::vector<SBPrefix>* prefix_hits,
685 std::vector<SBFullHashResult>* cache_hits) {
638 // Clear the results first. 686 // Clear the results first.
639 prefix_hits->clear(); 687 prefix_hits->clear();
640 cache_hits->clear(); 688 cache_hits->clear();
641 689
690 // |prefix_set| is empty until it is either read from disk, or the first
691 // update populates it. Bail out without a hit if not yet available.
692 if (!prefix_set)
693 return false;
694
642 std::vector<SBFullHash> full_hashes; 695 std::vector<SBFullHash> full_hashes;
643 BrowseFullHashesToCheck(url, false, &full_hashes); 696 UrlToFullHashes(url, false, &full_hashes);
644 if (full_hashes.empty()) 697 if (full_hashes.empty())
645 return false; 698 return false;
646 699
647 return ContainsBrowseUrlHashes(full_hashes, prefix_hits, cache_hits); 700 return PrefixSetContainsUrlHashes(full_hashes, prefix_set, prefix_hits,
701 cache_hits);
648 } 702 }
649 703
650 bool SafeBrowsingDatabaseNew::ContainsBrowseUrlHashes( 704 bool SafeBrowsingDatabaseNew::ContainsBrowseUrlHashesForTesting(
651 const std::vector<SBFullHash>& full_hashes, 705 const std::vector<SBFullHash>& full_hashes,
652 std::vector<SBPrefix>* prefix_hits, 706 std::vector<SBPrefix>* prefix_hits,
653 std::vector<SBFullHashResult>* cache_hits) { 707 std::vector<SBFullHashResult>* cache_hits) {
708 return PrefixSetContainsUrlHashes(full_hashes, browse_prefix_set_.get(),
709 prefix_hits, cache_hits);
710 }
711
712 bool SafeBrowsingDatabaseNew::PrefixSetContainsUrlHashes(
713 const std::vector<SBFullHash>& full_hashes,
714 safe_browsing::PrefixSet* prefix_set,
715 std::vector<SBPrefix>* prefix_hits,
716 std::vector<SBFullHashResult>* cache_hits) {
654 // Used to determine cache expiration. 717 // Used to determine cache expiration.
655 const base::Time now = base::Time::Now(); 718 const base::Time now = base::Time::Now();
656 719
657 // This function is called on the I/O thread, prevent changes to 720 // This function is called on the I/O thread, prevent changes to
658 // filter and caches. 721 // filter and caches.
659 base::AutoLock locked(lookup_lock_); 722 base::AutoLock locked(lookup_lock_);
660 723
661 // |browse_prefix_set_| is empty until it is either read from disk, or the
662 // first update populates it. Bail out without a hit if not yet
663 // available.
664 if (!browse_prefix_set_.get())
665 return false;
666
667 for (size_t i = 0; i < full_hashes.size(); ++i) { 724 for (size_t i = 0; i < full_hashes.size(); ++i) {
668 if (!GetCachedFullHash(&browse_gethash_cache_, 725 if (!GetCachedFullHash(&prefix_gethash_cache_,
669 full_hashes[i], 726 full_hashes[i],
670 now, 727 now,
671 cache_hits)) { 728 cache_hits)) {
672 // No valid cached result, check the database. 729 // No valid cached result, check the database.
673 if (browse_prefix_set_->Exists(full_hashes[i])) 730 if (prefix_set->Exists(full_hashes[i]))
674 prefix_hits->push_back(full_hashes[i].prefix); 731 prefix_hits->push_back(full_hashes[i].prefix);
675 } 732 }
676 } 733 }
677 734
678 // Multiple full hashes could share prefix, remove duplicates. 735 // Multiple full hashes could share prefix, remove duplicates.
679 std::sort(prefix_hits->begin(), prefix_hits->end()); 736 std::sort(prefix_hits->begin(), prefix_hits->end());
680 prefix_hits->erase(std::unique(prefix_hits->begin(), prefix_hits->end()), 737 prefix_hits->erase(std::unique(prefix_hits->begin(), prefix_hits->end()),
681 prefix_hits->end()); 738 prefix_hits->end());
682 739
683 return !prefix_hits->empty() || !cache_hits->empty(); 740 return !prefix_hits->empty() || !cache_hits->empty();
(...skipping 14 matching lines...) Expand all
698 safe_browsing_util::BINURL % 2, 755 safe_browsing_util::BINURL % 2,
699 prefixes, 756 prefixes,
700 prefix_hits); 757 prefix_hits);
701 } 758 }
702 759
703 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) { 760 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) {
704 // This method is theoretically thread-safe but we expect all calls to 761 // This method is theoretically thread-safe but we expect all calls to
705 // originate from the IO thread. 762 // originate from the IO thread.
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
707 std::vector<SBFullHash> full_hashes; 764 std::vector<SBFullHash> full_hashes;
708 BrowseFullHashesToCheck(url, true, &full_hashes); 765 UrlToFullHashes(url, true, &full_hashes);
709 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); 766 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes);
710 } 767 }
711 768
712 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) { 769 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedUrl(const GURL& url) {
713 std::vector<SBFullHash> full_hashes; 770 std::vector<SBFullHash> full_hashes;
714 BrowseFullHashesToCheck(url, true, &full_hashes); 771 UrlToFullHashes(url, true, &full_hashes);
715 return ContainsWhitelistedHashes(download_whitelist_, full_hashes); 772 return ContainsWhitelistedHashes(download_whitelist_, full_hashes);
716 } 773 }
717 774
718 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( 775 bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes(
719 const std::vector<SBPrefix>& prefixes, 776 const std::vector<SBPrefix>& prefixes,
720 std::vector<SBPrefix>* prefix_hits) { 777 std::vector<SBPrefix>* prefix_hits) {
721 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 778 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
722 if (!extension_blacklist_store_) 779 if (!extension_blacklist_store_)
723 return false; 780 return false;
724 781
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 const std::vector<SBPrefix>& prefixes, 1001 const std::vector<SBPrefix>& prefixes,
945 const std::vector<SBFullHashResult>& full_hits, 1002 const std::vector<SBFullHashResult>& full_hits,
946 const base::TimeDelta& cache_lifetime) { 1003 const base::TimeDelta& cache_lifetime) {
947 const base::Time expire_after = base::Time::Now() + cache_lifetime; 1004 const base::Time expire_after = base::Time::Now() + cache_lifetime;
948 1005
949 // This is called on the I/O thread, lock against updates. 1006 // This is called on the I/O thread, lock against updates.
950 base::AutoLock locked(lookup_lock_); 1007 base::AutoLock locked(lookup_lock_);
951 1008
952 // Create or reset all cached results for these prefixes. 1009 // Create or reset all cached results for these prefixes.
953 for (size_t i = 0; i < prefixes.size(); ++i) { 1010 for (size_t i = 0; i < prefixes.size(); ++i) {
954 browse_gethash_cache_[prefixes[i]] = SBCachedFullHashResult(expire_after); 1011 prefix_gethash_cache_[prefixes[i]] = SBCachedFullHashResult(expire_after);
955 } 1012 }
956 1013
957 // Insert any fullhash hits. Note that there may be one, multiple, or no 1014 // Insert any fullhash hits. Note that there may be one, multiple, or no
958 // fullhashes for any given entry in |prefixes|. 1015 // fullhashes for any given entry in |prefixes|.
959 for (size_t i = 0; i < full_hits.size(); ++i) { 1016 for (size_t i = 0; i < full_hits.size(); ++i) {
960 const SBPrefix prefix = full_hits[i].hash.prefix; 1017 const SBPrefix prefix = full_hits[i].hash.prefix;
961 browse_gethash_cache_[prefix].full_hashes.push_back(full_hits[i]); 1018 prefix_gethash_cache_[prefix].full_hashes.push_back(full_hits[i]);
962 } 1019 }
963 } 1020 }
964 1021
965 bool SafeBrowsingDatabaseNew::UpdateStarted( 1022 bool SafeBrowsingDatabaseNew::UpdateStarted(
966 std::vector<SBListChunkRanges>* lists) { 1023 std::vector<SBListChunkRanges>* lists) {
967 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 1024 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
968 DCHECK(lists); 1025 DCHECK(lists);
969 1026
970 // If |BeginUpdate()| fails, reset the database. 1027 // If |BeginUpdate()| fails, reset the database.
971 if (!browse_store_->BeginUpdate()) { 1028 if (!browse_store_->BeginUpdate()) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 HandleCorruptDatabase(); 1063 HandleCorruptDatabase();
1007 return false; 1064 return false;
1008 } 1065 }
1009 1066
1010 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) { 1067 if (ip_blacklist_store_ && !ip_blacklist_store_->BeginUpdate()) {
1011 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN); 1068 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_BEGIN);
1012 HandleCorruptDatabase(); 1069 HandleCorruptDatabase();
1013 return false; 1070 return false;
1014 } 1071 }
1015 1072
1073 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) {
1074 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN);
1075 HandleCorruptDatabase();
1076 return false;
1077 }
1078
1016 { 1079 {
1017 base::AutoLock locked(lookup_lock_); 1080 base::AutoLock locked(lookup_lock_);
1018 // Cached fullhash results must be cleared on every database update (whether 1081 // Cached fullhash results must be cleared on every database update (whether
1019 // successful or not.) 1082 // successful or not.)
1020 browse_gethash_cache_.clear(); 1083 prefix_gethash_cache_.clear();
1021 } 1084 }
1022 1085
1023 UpdateChunkRangesForLists(browse_store_.get(), 1086 UpdateChunkRangesForBrowseLists(browse_store_.get(),
1024 safe_browsing_util::kMalwareList, 1087 safe_browsing_util::kMalwareList,
1025 safe_browsing_util::kPhishingList, 1088 safe_browsing_util::kPhishingList,
1026 lists); 1089 lists);
1027 1090
1028 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been 1091 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been
1029 // deprecated. Code to delete the list from the store shows ~15k hits/day as 1092 // deprecated. Code to delete the list from the store shows ~15k hits/day as
1030 // of Feb 2014, so it has been removed. Everything _should_ be resilient to 1093 // of Feb 2014, so it has been removed. Everything _should_ be resilient to
1031 // extra data of that sort. 1094 // extra data of that sort.
1032 UpdateChunkRangesForList(download_store_.get(), 1095 UpdateChunkRangesForList(download_store_.get(),
1033 safe_browsing_util::kBinUrlList, lists); 1096 safe_browsing_util::kBinUrlList, lists);
1034 1097
1035 UpdateChunkRangesForList(csd_whitelist_store_.get(), 1098 UpdateChunkRangesForList(csd_whitelist_store_.get(),
1036 safe_browsing_util::kCsdWhiteList, lists); 1099 safe_browsing_util::kCsdWhiteList, lists);
1037 1100
1038 UpdateChunkRangesForList(download_whitelist_store_.get(), 1101 UpdateChunkRangesForList(download_whitelist_store_.get(),
1039 safe_browsing_util::kDownloadWhiteList, lists); 1102 safe_browsing_util::kDownloadWhiteList, lists);
1040 1103
1041 UpdateChunkRangesForList(extension_blacklist_store_.get(), 1104 UpdateChunkRangesForList(extension_blacklist_store_.get(),
1042 safe_browsing_util::kExtensionBlacklist, lists); 1105 safe_browsing_util::kExtensionBlacklist, lists);
1043 1106
1044 UpdateChunkRangesForList(side_effect_free_whitelist_store_.get(), 1107 UpdateChunkRangesForList(side_effect_free_whitelist_store_.get(),
1045 safe_browsing_util::kSideEffectFreeWhitelist, lists); 1108 safe_browsing_util::kSideEffectFreeWhitelist, lists);
1046 1109
1047 UpdateChunkRangesForList(ip_blacklist_store_.get(), 1110 UpdateChunkRangesForList(ip_blacklist_store_.get(),
1048 safe_browsing_util::kIPBlacklist, lists); 1111 safe_browsing_util::kIPBlacklist, lists);
1049 1112
1113 UpdateChunkRangesForList(unwanted_software_store_.get(),
1114 safe_browsing_util::kUnwantedUrlList, lists);
1115
1050 corruption_detected_ = false; 1116 corruption_detected_ = false;
1051 change_detected_ = false; 1117 change_detected_ = false;
1052 return true; 1118 return true;
1053 } 1119 }
1054 1120
1055 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { 1121 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
1056 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 1122 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
1057 1123
1058 // The update may have failed due to corrupt storage (for instance, 1124 // The update may have failed due to corrupt storage (for instance,
1059 // an excessive number of invalid add_chunks and sub_chunks). 1125 // an excessive number of invalid add_chunks and sub_chunks).
(...skipping 23 matching lines...) Expand all
1083 1149
1084 if (side_effect_free_whitelist_store_ && 1150 if (side_effect_free_whitelist_store_ &&
1085 !side_effect_free_whitelist_store_->CheckValidity()) { 1151 !side_effect_free_whitelist_store_->CheckValidity()) {
1086 DLOG(ERROR) << "Safe-browsing side-effect free whitelist database " 1152 DLOG(ERROR) << "Safe-browsing side-effect free whitelist database "
1087 << "corrupt."; 1153 << "corrupt.";
1088 } 1154 }
1089 1155
1090 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { 1156 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) {
1091 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; 1157 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt.";
1092 } 1158 }
1159
1160 if (unwanted_software_store_ &&
1161 !unwanted_software_store_->CheckValidity()) {
1162 DLOG(ERROR) << "Unwanted software url list database corrupt.";
1163 }
1093 } 1164 }
1094 1165
1095 if (corruption_detected_) 1166 if (corruption_detected_)
1096 return; 1167 return;
1097 1168
1098 // Unroll the transaction if there was a protocol error or if the 1169 // Unroll the transaction if there was a protocol error or if the
1099 // transaction was empty. This will leave the prefix set, the 1170 // transaction was empty. This will leave the prefix set, the
1100 // pending hashes, and the prefix miss cache in place. 1171 // pending hashes, and the prefix miss cache in place.
1101 if (!update_succeeded || !change_detected_) { 1172 if (!update_succeeded || !change_detected_) {
1102 // Track empty updates to answer questions at http://crbug.com/72216 . 1173 // Track empty updates to answer questions at http://crbug.com/72216 .
1103 if (update_succeeded && !change_detected_) 1174 if (update_succeeded && !change_detected_)
1104 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); 1175 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0);
1105 browse_store_->CancelUpdate(); 1176 browse_store_->CancelUpdate();
1106 if (download_store_.get()) 1177 if (download_store_.get())
1107 download_store_->CancelUpdate(); 1178 download_store_->CancelUpdate();
1108 if (csd_whitelist_store_.get()) 1179 if (csd_whitelist_store_.get())
1109 csd_whitelist_store_->CancelUpdate(); 1180 csd_whitelist_store_->CancelUpdate();
1110 if (download_whitelist_store_.get()) 1181 if (download_whitelist_store_.get())
1111 download_whitelist_store_->CancelUpdate(); 1182 download_whitelist_store_->CancelUpdate();
1112 if (extension_blacklist_store_) 1183 if (extension_blacklist_store_)
1113 extension_blacklist_store_->CancelUpdate(); 1184 extension_blacklist_store_->CancelUpdate();
1114 if (side_effect_free_whitelist_store_) 1185 if (side_effect_free_whitelist_store_)
1115 side_effect_free_whitelist_store_->CancelUpdate(); 1186 side_effect_free_whitelist_store_->CancelUpdate();
1116 if (ip_blacklist_store_) 1187 if (ip_blacklist_store_)
1117 ip_blacklist_store_->CancelUpdate(); 1188 ip_blacklist_store_->CancelUpdate();
1189 if (unwanted_software_store_)
1190 unwanted_software_store_->CancelUpdate();
1118 return; 1191 return;
1119 } 1192 }
1120 1193
1121 if (download_store_) { 1194 if (download_store_) {
1122 int64 size_bytes = UpdateHashPrefixStore( 1195 int64 size_bytes = UpdateHashPrefixStore(
1123 DownloadDBFilename(filename_base_), 1196 DownloadDBFilename(filename_base_),
1124 download_store_.get(), 1197 download_store_.get(),
1125 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); 1198 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH);
1126 UMA_HISTOGRAM_COUNTS("SB2.DownloadDatabaseKilobytes", 1199 UMA_HISTOGRAM_COUNTS("SB2.DownloadDatabaseKilobytes",
1127 static_cast<int>(size_bytes / 1024)); 1200 static_cast<int>(size_bytes / 1024));
1128 } 1201 }
1129 1202
1130 UpdateBrowseStore(); 1203 UpdatePrefixSetUrlStore(BrowseDBFilename(filename_base_),
1204 browse_store_.get(),
1205 &browse_prefix_set_,
1206 FAILURE_BROWSE_DATABASE_UPDATE_FINISH,
1207 FAILURE_BROWSE_PREFIX_SET_WRITE);
1208
1131 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_), 1209 UpdateWhitelistStore(CsdWhitelistDBFilename(filename_base_),
1132 csd_whitelist_store_.get(), 1210 csd_whitelist_store_.get(),
1133 &csd_whitelist_); 1211 &csd_whitelist_);
1134 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_), 1212 UpdateWhitelistStore(DownloadWhitelistDBFilename(filename_base_),
1135 download_whitelist_store_.get(), 1213 download_whitelist_store_.get(),
1136 &download_whitelist_); 1214 &download_whitelist_);
1137 1215
1138 if (extension_blacklist_store_) { 1216 if (extension_blacklist_store_) {
1139 int64 size_bytes = UpdateHashPrefixStore( 1217 int64 size_bytes = UpdateHashPrefixStore(
1140 ExtensionBlacklistDBFilename(filename_base_), 1218 ExtensionBlacklistDBFilename(filename_base_),
1141 extension_blacklist_store_.get(), 1219 extension_blacklist_store_.get(),
1142 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH); 1220 FAILURE_EXTENSION_BLACKLIST_UPDATE_FINISH);
1143 UMA_HISTOGRAM_COUNTS("SB2.ExtensionBlacklistKilobytes", 1221 UMA_HISTOGRAM_COUNTS("SB2.ExtensionBlacklistKilobytes",
1144 static_cast<int>(size_bytes / 1024)); 1222 static_cast<int>(size_bytes / 1024));
1145 } 1223 }
1146 1224
1147 if (side_effect_free_whitelist_store_) 1225 if (side_effect_free_whitelist_store_)
1148 UpdateSideEffectFreeWhitelistStore(); 1226 UpdateSideEffectFreeWhitelistStore();
1149 1227
1150 if (ip_blacklist_store_) 1228 if (ip_blacklist_store_)
1151 UpdateIpBlacklistStore(); 1229 UpdateIpBlacklistStore();
1230
1231 if (unwanted_software_store_) {
1232 UpdatePrefixSetUrlStore(UnwantedSoftwareDBFilename(filename_base_),
1233 unwanted_software_store_.get(),
1234 &unwanted_software_prefix_set_,
1235 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH,
1236 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE);
1237 }
1152 } 1238 }
1153 1239
1154 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( 1240 void SafeBrowsingDatabaseNew::UpdateWhitelistStore(
1155 const base::FilePath& store_filename, 1241 const base::FilePath& store_filename,
1156 SafeBrowsingStore* store, 1242 SafeBrowsingStore* store,
1157 SBWhitelist* whitelist) { 1243 SBWhitelist* whitelist) {
1158 if (!store) 1244 if (!store)
1159 return; 1245 return;
1160 1246
1161 // Note: |builder| will not be empty. The current data store implementation 1247 // Note: |builder| will not be empty. The current data store implementation
(...skipping 25 matching lines...) Expand all
1187 if (!store->FinishUpdate(&builder, &add_full_hashes_result)) 1273 if (!store->FinishUpdate(&builder, &add_full_hashes_result))
1188 RecordFailure(failure_type); 1274 RecordFailure(failure_type);
1189 1275
1190 #if defined(OS_MACOSX) 1276 #if defined(OS_MACOSX)
1191 base::mac::SetFileBackupExclusion(store_filename); 1277 base::mac::SetFileBackupExclusion(store_filename);
1192 #endif 1278 #endif
1193 1279
1194 return GetFileSizeOrZero(store_filename); 1280 return GetFileSizeOrZero(store_filename);
1195 } 1281 }
1196 1282
1197 void SafeBrowsingDatabaseNew::UpdateBrowseStore() { 1283 void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore(
1284 const base::FilePath& db_filename,
1285 SafeBrowsingStore* url_store,
1286 scoped_ptr<safe_browsing::PrefixSet>* prefix_set,
1287 FailureType finish_failure_type,
1288 FailureType write_failure_type) {
1198 // Measure the amount of IO during the filter build. 1289 // Measure the amount of IO during the filter build.
1199 base::IoCounters io_before, io_after; 1290 base::IoCounters io_before, io_after;
1200 base::ProcessHandle handle = base::GetCurrentProcessHandle(); 1291 base::ProcessHandle handle = base::GetCurrentProcessHandle();
1201 scoped_ptr<base::ProcessMetrics> metric( 1292 scoped_ptr<base::ProcessMetrics> metric(
1202 #if !defined(OS_MACOSX) 1293 #if !defined(OS_MACOSX)
1203 base::ProcessMetrics::CreateProcessMetrics(handle) 1294 base::ProcessMetrics::CreateProcessMetrics(handle)
1204 #else 1295 #else
1205 // Getting stats only for the current process is enough, so NULL is fine. 1296 // Getting stats only for the current process is enough, so NULL is fine.
1206 base::ProcessMetrics::CreateProcessMetrics(handle, NULL) 1297 base::ProcessMetrics::CreateProcessMetrics(handle, NULL)
1207 #endif 1298 #endif
1208 ); 1299 );
1209 1300
1210 // IoCounters are currently not supported on Mac, and may not be 1301 // IoCounters are currently not supported on Mac, and may not be
1211 // available for Linux, so we check the result and only show IO 1302 // available for Linux, so we check the result and only show IO
1212 // stats if they are available. 1303 // stats if they are available.
1213 const bool got_counters = metric->GetIOCounters(&io_before); 1304 const bool got_counters = metric->GetIOCounters(&io_before);
1214 1305
1215 const base::TimeTicks before = base::TimeTicks::Now(); 1306 const base::TimeTicks before = base::TimeTicks::Now();
1216 1307
1217 // TODO(shess): Perhaps refactor to let builder accumulate full hashes on the 1308 // TODO(shess): Perhaps refactor to let builder accumulate full hashes on the
1218 // fly? Other clients use the SBAddFullHash vector, but AFAICT they only use 1309 // fly? Other clients use the SBAddFullHash vector, but AFAICT they only use
1219 // the SBFullHash portion. It would need an accessor on PrefixSet. 1310 // the SBFullHash portion. It would need an accessor on PrefixSet.
1220 safe_browsing::PrefixSetBuilder builder; 1311 safe_browsing::PrefixSetBuilder builder;
1221 std::vector<SBAddFullHash> add_full_hashes; 1312 std::vector<SBAddFullHash> add_full_hashes;
1222 if (!browse_store_->FinishUpdate(&builder, &add_full_hashes)) { 1313 if (!url_store->FinishUpdate(&builder, &add_full_hashes)) {
1223 RecordFailure(FAILURE_BROWSE_DATABASE_UPDATE_FINISH); 1314 RecordFailure(finish_failure_type);
1224 return; 1315 return;
1225 } 1316 }
1226 1317
1227 std::vector<SBFullHash> full_hash_results; 1318 std::vector<SBFullHash> full_hash_results;
1228 for (size_t i = 0; i < add_full_hashes.size(); ++i) { 1319 for (size_t i = 0; i < add_full_hashes.size(); ++i) {
1229 full_hash_results.push_back(add_full_hashes[i].full_hash); 1320 full_hash_results.push_back(add_full_hashes[i].full_hash);
1230 } 1321 }
1231 1322
1232 scoped_ptr<safe_browsing::PrefixSet> 1323 scoped_ptr<safe_browsing::PrefixSet> new_prefix_set(
1233 prefix_set(builder.GetPrefixSet(full_hash_results)); 1324 builder.GetPrefixSet(full_hash_results));
1234 1325
1235 // Swap in the newly built filter. 1326 // Swap in the newly built filter.
1236 { 1327 {
1237 base::AutoLock locked(lookup_lock_); 1328 base::AutoLock locked(lookup_lock_);
1238 browse_prefix_set_.swap(prefix_set); 1329 prefix_set->swap(new_prefix_set);
1239 } 1330 }
1240 1331
1241 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before); 1332 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before);
1242 1333
1243 // Persist the prefix set to disk. Since only this thread changes 1334 // Persist the prefix set to disk. Since only this thread changes
1244 // |browse_prefix_set_|, there is no need to lock. 1335 // |prefix_set|, there is no need to lock.
mattm 2014/11/11 01:29:10 Comment is (even more) confusing now that prefix_s
gab 2014/11/11 23:39:11 Agreed, re-worded comment. I also think we can ma
mattm 2014/11/12 03:24:30 Sounds reasonable, though I don't think it complet
1245 WritePrefixSet(); 1336 WritePrefixSet(db_filename, prefix_set->get(), write_failure_type);
1246 1337
1247 // Gather statistics. 1338 // Gather statistics.
1248 if (got_counters && metric->GetIOCounters(&io_after)) { 1339 if (got_counters && metric->GetIOCounters(&io_after)) {
1249 UMA_HISTOGRAM_COUNTS("SB2.BuildReadKilobytes", 1340 UMA_HISTOGRAM_COUNTS("SB2.BuildReadKilobytes",
1250 static_cast<int>(io_after.ReadTransferCount - 1341 static_cast<int>(io_after.ReadTransferCount -
1251 io_before.ReadTransferCount) / 1024); 1342 io_before.ReadTransferCount) / 1024);
1252 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteKilobytes", 1343 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteKilobytes",
1253 static_cast<int>(io_after.WriteTransferCount - 1344 static_cast<int>(io_after.WriteTransferCount -
1254 io_before.WriteTransferCount) / 1024); 1345 io_before.WriteTransferCount) / 1024);
1255 UMA_HISTOGRAM_COUNTS("SB2.BuildReadOperations", 1346 UMA_HISTOGRAM_COUNTS("SB2.BuildReadOperations",
1256 static_cast<int>(io_after.ReadOperationCount - 1347 static_cast<int>(io_after.ReadOperationCount -
1257 io_before.ReadOperationCount)); 1348 io_before.ReadOperationCount));
1258 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteOperations", 1349 UMA_HISTOGRAM_COUNTS("SB2.BuildWriteOperations",
1259 static_cast<int>(io_after.WriteOperationCount - 1350 static_cast<int>(io_after.WriteOperationCount -
1260 io_before.WriteOperationCount)); 1351 io_before.WriteOperationCount));
1261 } 1352 }
1262 1353
1263 const base::FilePath browse_filename = BrowseDBFilename(filename_base_); 1354 const int64 file_size = GetFileSizeOrZero(db_filename);
1264 const int64 file_size = GetFileSizeOrZero(browse_filename);
1265 UMA_HISTOGRAM_COUNTS("SB2.BrowseDatabaseKilobytes", 1355 UMA_HISTOGRAM_COUNTS("SB2.BrowseDatabaseKilobytes",
1266 static_cast<int>(file_size / 1024)); 1356 static_cast<int>(file_size / 1024));
1267 1357
1268 #if defined(OS_MACOSX) 1358 #if defined(OS_MACOSX)
1269 base::mac::SetFileBackupExclusion(browse_filename); 1359 base::mac::SetFileBackupExclusion(db_filename);
1270 #endif 1360 #endif
1271 } 1361 }
1272 1362
1273 void SafeBrowsingDatabaseNew::UpdateSideEffectFreeWhitelistStore() { 1363 void SafeBrowsingDatabaseNew::UpdateSideEffectFreeWhitelistStore() {
1274 safe_browsing::PrefixSetBuilder builder; 1364 safe_browsing::PrefixSetBuilder builder;
1275 std::vector<SBAddFullHash> add_full_hashes_result; 1365 std::vector<SBAddFullHash> add_full_hashes_result;
1276 1366
1277 if (!side_effect_free_whitelist_store_->FinishUpdate( 1367 if (!side_effect_free_whitelist_store_->FinishUpdate(
1278 &builder, &add_full_hashes_result)) { 1368 &builder, &add_full_hashes_result)) {
1279 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH); 1369 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_UPDATE_FINISH);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 1443
1354 // NOTE(shess): ResetDatabase() should remove the corruption, so this should 1444 // NOTE(shess): ResetDatabase() should remove the corruption, so this should
1355 // only happen once. If you are here because you are hitting this after a 1445 // only happen once. If you are here because you are hitting this after a
1356 // restart, then I would be very interested in working with you to figure out 1446 // restart, then I would be very interested in working with you to figure out
1357 // what is happening, since it may affect real users. 1447 // what is happening, since it may affect real users.
1358 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset"; 1448 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset";
1359 } 1449 }
1360 1450
1361 // TODO(shess): I'm not clear why this code doesn't have any 1451 // TODO(shess): I'm not clear why this code doesn't have any
1362 // real error-handling. 1452 // real error-handling.
1363 void SafeBrowsingDatabaseNew::LoadPrefixSet() { 1453 void SafeBrowsingDatabaseNew::LoadPrefixSet(
1454 const base::FilePath& db_filename,
1455 scoped_ptr<safe_browsing::PrefixSet>* prefix_set,
1456 FailureType read_failure_type) {
1457 if (!prefix_set)
1458 return;
1459
1364 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 1460 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
1365 DCHECK(!filename_base_.empty()); 1461 DCHECK(!filename_base_.empty());
1366 1462
1367 const base::FilePath browse_filename = BrowseDBFilename(filename_base_); 1463 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename);
1368 const base::FilePath browse_prefix_set_filename =
1369 PrefixSetForFilename(browse_filename);
1370 1464
1371 // Only use the prefix set if database is present and non-empty. 1465 // Only use the prefix set if database is present and non-empty.
1372 if (!GetFileSizeOrZero(browse_filename)) 1466 if (!GetFileSizeOrZero(db_filename))
1373 return; 1467 return;
1374 1468
1375 // Cleanup any stale bloom filter (no longer used). 1469 // Cleanup any stale bloom filter (no longer used).
1376 // TODO(shess): Track existence to drive removal of this code? 1470 // TODO(shess): Track existence to drive removal of this code?
1377 const base::FilePath bloom_filter_filename = 1471 const base::FilePath bloom_filter_filename =
1378 BloomFilterForFilename(browse_filename); 1472 BloomFilterForFilename(db_filename);
1379 base::DeleteFile(bloom_filter_filename, false); 1473 base::DeleteFile(bloom_filter_filename, false);
1380 1474
1381 const base::TimeTicks before = base::TimeTicks::Now(); 1475 const base::TimeTicks before = base::TimeTicks::Now();
1382 browse_prefix_set_ = safe_browsing::PrefixSet::LoadFile( 1476 *prefix_set = safe_browsing::PrefixSet::LoadFile(prefix_set_filename);
1383 browse_prefix_set_filename);
1384 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before); 1477 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before);
1385 1478
1386 if (!browse_prefix_set_.get()) 1479 if (!prefix_set->get())
1387 RecordFailure(FAILURE_BROWSE_PREFIX_SET_READ); 1480 RecordFailure(read_failure_type);
1388 } 1481 }
1389 1482
1390 bool SafeBrowsingDatabaseNew::Delete() { 1483 bool SafeBrowsingDatabaseNew::Delete() {
1391 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 1484 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
1392 DCHECK(!filename_base_.empty()); 1485 DCHECK(!filename_base_.empty());
1393 1486
1394 // TODO(shess): This is a mess. SafeBrowsingFileStore::Delete() closes the 1487 // TODO(shess): This is a mess. SafeBrowsingFileStore::Delete() closes the
1395 // store before calling DeleteStore(). DeleteStore() deletes transient files 1488 // store before calling DeleteStore(). DeleteStore() deletes transient files
1396 // in addition to the main file. Probably all of these should be converted to 1489 // in addition to the main file. Probably all of these should be converted to
1397 // a helper which calls Delete() if the store exists, else DeleteStore() on 1490 // a helper which calls Delete() if the store exists, else DeleteStore() on
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 side_effect_free_whitelist_prefix_set_filename, 1545 side_effect_free_whitelist_prefix_set_filename,
1453 false); 1546 false);
1454 if (!r9) 1547 if (!r9)
1455 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE); 1548 RecordFailure(FAILURE_SIDE_EFFECT_FREE_WHITELIST_PREFIX_SET_DELETE);
1456 1549
1457 const bool r10 = base::DeleteFile(IpBlacklistDBFilename(filename_base_), 1550 const bool r10 = base::DeleteFile(IpBlacklistDBFilename(filename_base_),
1458 false); 1551 false);
1459 if (!r10) 1552 if (!r10)
1460 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); 1553 RecordFailure(FAILURE_IP_BLACKLIST_DELETE);
1461 1554
1462 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10; 1555 const bool r11 =
1556 base::DeleteFile(UnwantedSoftwareDBFilename(filename_base_), false);
1557 if (!r11)
1558 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE);
1559
1560 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11;
1463 } 1561 }
1464 1562
1465 void SafeBrowsingDatabaseNew::WritePrefixSet() { 1563 void SafeBrowsingDatabaseNew::WritePrefixSet(
1564 const base::FilePath& db_filename,
1565 safe_browsing::PrefixSet* prefix_set,
1566 FailureType write_failure_type) {
1466 DCHECK_EQ(creation_loop_, base::MessageLoop::current()); 1567 DCHECK_EQ(creation_loop_, base::MessageLoop::current());
1467 1568
1468 if (!browse_prefix_set_.get()) 1569 if (!prefix_set)
1469 return; 1570 return;
1470 1571
1471 const base::FilePath browse_filename = BrowseDBFilename(filename_base_); 1572 const base::FilePath prefix_set_filename = PrefixSetForFilename(db_filename);
1472 const base::FilePath browse_prefix_set_filename =
1473 PrefixSetForFilename(browse_filename);
1474 1573
1475 const base::TimeTicks before = base::TimeTicks::Now(); 1574 const base::TimeTicks before = base::TimeTicks::Now();
1476 const bool write_ok = browse_prefix_set_->WriteFile( 1575 const bool write_ok = prefix_set->WriteFile(prefix_set_filename);
1477 browse_prefix_set_filename);
1478 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before); 1576 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before);
1479 1577
1480 const int64 file_size = GetFileSizeOrZero(browse_prefix_set_filename); 1578 const int64 file_size = GetFileSizeOrZero(prefix_set_filename);
1481 UMA_HISTOGRAM_COUNTS("SB2.PrefixSetKilobytes", 1579 UMA_HISTOGRAM_COUNTS("SB2.PrefixSetKilobytes",
1482 static_cast<int>(file_size / 1024)); 1580 static_cast<int>(file_size / 1024));
1483 1581
1484 if (!write_ok) 1582 if (!write_ok)
1485 RecordFailure(FAILURE_BROWSE_PREFIX_SET_WRITE); 1583 RecordFailure(write_failure_type);
1486 1584
1487 #if defined(OS_MACOSX) 1585 #if defined(OS_MACOSX)
1488 base::mac::SetFileBackupExclusion(browse_prefix_set_filename); 1586 base::mac::SetFileBackupExclusion(prefix_set_filename);
1489 #endif 1587 #endif
1490 } 1588 }
1491 1589
1492 void SafeBrowsingDatabaseNew::WhitelistEverything(SBWhitelist* whitelist) { 1590 void SafeBrowsingDatabaseNew::WhitelistEverything(SBWhitelist* whitelist) {
1493 base::AutoLock locked(lookup_lock_); 1591 base::AutoLock locked(lookup_lock_);
1494 whitelist->second = true; 1592 whitelist->second = true;
1495 whitelist->first.clear(); 1593 whitelist->first.clear();
1496 } 1594 }
1497 1595
1498 void SafeBrowsingDatabaseNew::LoadWhitelist( 1596 void SafeBrowsingDatabaseNew::LoadWhitelist(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() { 1665 bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() {
1568 SBFullHash malware_kill_switch = SBFullHashForString(kMalwareIPKillSwitchUrl); 1666 SBFullHash malware_kill_switch = SBFullHashForString(kMalwareIPKillSwitchUrl);
1569 std::vector<SBFullHash> full_hashes; 1667 std::vector<SBFullHash> full_hashes;
1570 full_hashes.push_back(malware_kill_switch); 1668 full_hashes.push_back(malware_kill_switch);
1571 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); 1669 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes);
1572 } 1670 }
1573 1671
1574 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() { 1672 bool SafeBrowsingDatabaseNew::IsCsdWhitelistKillSwitchOn() {
1575 return csd_whitelist_.second; 1673 return csd_whitelist_.second;
1576 } 1674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698