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 // 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 | |
138 // Factory method. | 154 // Factory method. |
139 // TODO(shess): Milestone-7 is converting from SQLite-based | 155 // TODO(shess): Milestone-7 is converting from SQLite-based |
140 // SafeBrowsingDatabaseBloom to the new file format with | 156 // SafeBrowsingDatabaseBloom to the new file format with |
141 // SafeBrowsingDatabaseNew. Once that conversion is too far along to | 157 // SafeBrowsingDatabaseNew. Once that conversion is too far along to |
142 // consider reversing, circle back and lift SafeBrowsingDatabaseNew up | 158 // consider reversing, circle back and lift SafeBrowsingDatabaseNew up |
143 // to SafeBrowsingDatabase and get rid of the abstract class. | 159 // to SafeBrowsingDatabase and get rid of the abstract class. |
144 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { | 160 SafeBrowsingDatabase* SafeBrowsingDatabase::Create() { |
145 return new SafeBrowsingDatabaseNew(new SafeBrowsingStoreFile); | 161 if (!factory_) |
162 factory_ = new SafeBrowsingDatabaseFactoryImpl(); | |
Scott Hess - ex-Googler
2010/12/07 21:22:57
Again, if thread-safe make assertions that it is h
lzheng
2010/12/08 01:57:32
This is not thread safe. Caller has to call this f
| |
163 return factory_->CreateSafeBrowsingDatabase(); | |
146 } | 164 } |
147 | 165 |
148 SafeBrowsingDatabase::~SafeBrowsingDatabase() { | 166 SafeBrowsingDatabase::~SafeBrowsingDatabase() { |
149 } | 167 } |
150 | 168 |
151 // static | 169 // static |
152 FilePath SafeBrowsingDatabase::BloomFilterForFilename( | 170 FilePath SafeBrowsingDatabase::BloomFilterForFilename( |
153 const FilePath& db_filename) { | 171 const FilePath& db_filename) { |
154 return FilePath(db_filename.value() + kBloomFilterFile); | 172 return FilePath(db_filename.value() + kBloomFilterFile); |
155 } | 173 } |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 const base::TimeTicks before = base::TimeTicks::Now(); | 705 const base::TimeTicks before = base::TimeTicks::Now(); |
688 const bool write_ok = bloom_filter_->WriteFile(bloom_filter_filename_); | 706 const bool write_ok = bloom_filter_->WriteFile(bloom_filter_filename_); |
689 VLOG(1) << "SafeBrowsingDatabaseNew wrote bloom filter in " | 707 VLOG(1) << "SafeBrowsingDatabaseNew wrote bloom filter in " |
690 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; | 708 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; |
691 | 709 |
692 if (!write_ok) { | 710 if (!write_ok) { |
693 UMA_HISTOGRAM_COUNTS("SB2.FilterWriteFail", 1); | 711 UMA_HISTOGRAM_COUNTS("SB2.FilterWriteFail", 1); |
694 RecordFailure(FAILURE_DATABASE_FILTER_WRITE); | 712 RecordFailure(FAILURE_DATABASE_FILTER_WRITE); |
695 } | 713 } |
696 } | 714 } |
OLD | NEW |