OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from | 130 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from |
131 // safe_browsing_store.h orders on both chunk-id and prefix. | 131 // safe_browsing_store.h orders on both chunk-id and prefix. |
132 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) { | 132 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) { |
133 return a.full_hash.prefix < b.full_hash.prefix; | 133 return a.full_hash.prefix < b.full_hash.prefix; |
134 } | 134 } |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 | 137 |
138 // Factory method. | 138 // The default SafeBrowsingDatabaseFactory. |
| 139 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
| 140 public: |
| 141 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase() { |
| 142 return new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile); |
| 143 } |
| 144 |
| 145 SafeBrowsingDatabaseFactoryImpl() { } |
| 146 |
| 147 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
| 149 }; |
| 150 |
| 151 // static |
| 152 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; |
| 153 |
| 154 // Factory method, non-thread safe. Caller has to make sure this s called |
| 155 // on SafeBrowsing Thread. |
139 // TODO(shess): Milestone-7 is converting from SQLite-based | 156 // TODO(shess): Milestone-7 is converting from SQLite-based |
140 // SafeBrowsingDatabaseBloom to the new file format with | 157 // SafeBrowsingDatabaseBloom to the new file format with |
141 // SafeBrowsingDatabaseNew. Once that conversion is too far along to | 158 // SafeBrowsingDatabaseNew. Once that conversion is too far along to |
142 // consider reversing, circle back and lift SafeBrowsingDatabaseNew up | 159 // consider reversing, circle back and lift SafeBrowsingDatabaseNew up |
143 // to SafeBrowsingDatabase and get rid of the abstract class. | 160 // to SafeBrowsingDatabase and get rid of the abstract class. |
144 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { | 161 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { |
145 return new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile); | 162 if (!factory_) |
| 163 factory_ = new SafeBrowsingDatabaseFactoryImpl(); |
| 164 return factory_->CreateSafeBrowsingDatabase(); |
146 } | 165 } |
147 | 166 |
148 SafeBrowsingDatabase::~SafeBrowsingDatabase() { | 167 SafeBrowsingDatabase::~SafeBrowsingDatabase() { |
149 } | 168 } |
150 | 169 |
151 // static | 170 // static |
152 FilePath SafeBrowsingDatabase::BloomFilterForFilename( | 171 FilePath SafeBrowsingDatabase::BloomFilterForFilename( |
153 const FilePath& db_filename) { | 172 const FilePath& db_filename) { |
154 return FilePath(db_filename.value() + kBloomFilterFile); | 173 return FilePath(db_filename.value() + kBloomFilterFile); |
155 } | 174 } |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 const base::TimeTicks before = base::TimeTicks::Now(); | 706 const base::TimeTicks before = base::TimeTicks::Now(); |
688 const bool write_ok = bloom_filter_->WriteFile(bloom_filter_filename_); | 707 const bool write_ok = bloom_filter_->WriteFile(bloom_filter_filename_); |
689 VLOG(1) << "SafeBrowsingDatabaseNew wrote bloom filter in " | 708 VLOG(1) << "SafeBrowsingDatabaseNew wrote bloom filter in " |
690 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; | 709 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; |
691 | 710 |
692 if (!write_ok) { | 711 if (!write_ok) { |
693 UMA_HISTOGRAM_COUNTS("SB2.FilterWriteFail", 1); | 712 UMA_HISTOGRAM_COUNTS("SB2.FilterWriteFail", 1); |
694 RecordFailure(FAILURE_DATABASE_FILTER_WRITE); | 713 RecordFailure(FAILURE_DATABASE_FILTER_WRITE); |
695 } | 714 } |
696 } | 715 } |
OLD | NEW |