| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/sha2.h" | 10 #include "base/sha2.h" |
| 11 #include "chrome/browser/safe_browsing/safe_browsing_database_impl.h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_database_impl.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h" | 12 #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 | 15 |
| 16 using base::Time; | 16 using base::Time; |
| 17 | 17 |
| 18 // Filename suffix for the bloom filter. | 18 // Filename suffix for the bloom filter. |
| 19 static const wchar_t kBloomFilterFile[] = L" Filter"; | 19 static const wchar_t kBloomFilterFile[] = L" Filter"; |
| 20 | 20 |
| 21 // Factory method. | 21 // Factory method. |
| 22 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { | 22 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { |
| 23 if (CommandLine().HasSwitch(switches::kUseNewSafeBrowsing)) | 23 if (CommandLine().HasSwitch(switches::kUseOldSafeBrowsing)) |
| 24 return new SafeBrowsingDatabaseBloom; | 24 return new SafeBrowsingDatabaseImpl; |
| 25 return new SafeBrowsingDatabaseImpl; | 25 return new SafeBrowsingDatabaseBloom; |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool SafeBrowsingDatabase::NeedToCheckUrl(const GURL& url) { | 28 bool SafeBrowsingDatabase::NeedToCheckUrl(const GURL& url) { |
| 29 // Keep a reference to the current bloom filter in case the database rebuilds | 29 // Keep a reference to the current bloom filter in case the database rebuilds |
| 30 // it while we're accessing it. | 30 // it while we're accessing it. |
| 31 scoped_refptr<BloomFilter> filter = bloom_filter_; | 31 scoped_refptr<BloomFilter> filter = bloom_filter_; |
| 32 if (!filter.get()) | 32 if (!filter.get()) |
| 33 return true; | 33 return true; |
| 34 | 34 |
| 35 IncrementBloomFilterReadCount(); | 35 IncrementBloomFilterReadCount(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 if (!bloom_filter_.get()) | 93 if (!bloom_filter_.get()) |
| 94 return; | 94 return; |
| 95 | 95 |
| 96 Time before = Time::Now(); | 96 Time before = Time::Now(); |
| 97 file_util::WriteFile(bloom_filter_filename_, | 97 file_util::WriteFile(bloom_filter_filename_, |
| 98 bloom_filter_->data(), | 98 bloom_filter_->data(), |
| 99 bloom_filter_->size()); | 99 bloom_filter_->size()); |
| 100 SB_DLOG(INFO) << "SafeBrowsingDatabase wrote bloom filter in " << | 100 SB_DLOG(INFO) << "SafeBrowsingDatabase wrote bloom filter in " << |
| 101 (Time::Now() - before).InMilliseconds() << " ms"; | 101 (Time::Now() - before).InMilliseconds() << " ms"; |
| 102 } | 102 } |
| OLD | NEW |