| 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_bloom.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool SafeBrowsingDatabaseBloom::Close() { | 140 bool SafeBrowsingDatabaseBloom::Close() { |
| 141 if (!db_) | 141 if (!db_) |
| 142 return true; | 142 return true; |
| 143 | 143 |
| 144 insert_transaction_.reset(); |
| 144 statement_cache_.reset(); // Must free statements before closing DB. | 145 statement_cache_.reset(); // Must free statements before closing DB. |
| 145 bool result = sqlite3_close(db_) == SQLITE_OK; | 146 bool result = sqlite3_close(db_) == SQLITE_OK; |
| 146 db_ = NULL; | 147 db_ = NULL; |
| 147 | 148 |
| 148 return result; | 149 return result; |
| 149 } | 150 } |
| 150 | 151 |
| 151 bool SafeBrowsingDatabaseBloom::CreateTables() { | 152 bool SafeBrowsingDatabaseBloom::CreateTables() { |
| 152 SQLTransaction transaction(db_); | 153 SQLTransaction transaction(db_); |
| 153 transaction.Begin(); | 154 transaction.Begin(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return true; | 231 return true; |
| 231 } | 232 } |
| 232 | 233 |
| 233 // The SafeBrowsing service assumes this operation is run synchronously on the | 234 // The SafeBrowsing service assumes this operation is run synchronously on the |
| 234 // database thread. Any URLs that the service needs to check when this is | 235 // database thread. Any URLs that the service needs to check when this is |
| 235 // running are queued up and run once the reset is done. | 236 // running are queued up and run once the reset is done. |
| 236 bool SafeBrowsingDatabaseBloom::ResetDatabase() { | 237 bool SafeBrowsingDatabaseBloom::ResetDatabase() { |
| 237 hash_cache_->clear(); | 238 hash_cache_->clear(); |
| 238 ClearUpdateCaches(); | 239 ClearUpdateCaches(); |
| 239 | 240 |
| 240 insert_transaction_.reset(); | |
| 241 | |
| 242 bool rv = Close(); | 241 bool rv = Close(); |
| 243 DCHECK(rv); | 242 DCHECK(rv); |
| 244 | 243 |
| 245 if (!file_util::Delete(filename_, false)) { | 244 if (!file_util::Delete(filename_, false)) { |
| 246 NOTREACHED(); | 245 NOTREACHED(); |
| 247 return false; | 246 return false; |
| 248 } | 247 } |
| 249 | 248 |
| 250 bloom_filter_ = | 249 bloom_filter_ = |
| 251 new BloomFilter(kBloomFilterMinSize * kBloomFilterSizeRatio); | 250 new BloomFilter(kBloomFilterMinSize * kBloomFilterSizeRatio); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 412 |
| 414 bool SafeBrowsingDatabaseBloom::UpdateStarted() { | 413 bool SafeBrowsingDatabaseBloom::UpdateStarted() { |
| 415 DCHECK(insert_transaction_.get() == NULL); | 414 DCHECK(insert_transaction_.get() == NULL); |
| 416 | 415 |
| 417 if (!Open()) | 416 if (!Open()) |
| 418 return false; | 417 return false; |
| 419 | 418 |
| 420 insert_transaction_.reset(new SQLTransaction(db_)); | 419 insert_transaction_.reset(new SQLTransaction(db_)); |
| 421 if (insert_transaction_->Begin() != SQLITE_OK) { | 420 if (insert_transaction_->Begin() != SQLITE_OK) { |
| 422 DCHECK(false) << "Safe browsing database couldn't start transaction"; | 421 DCHECK(false) << "Safe browsing database couldn't start transaction"; |
| 423 insert_transaction_.reset(); | |
| 424 Close(); | 422 Close(); |
| 425 return false; | 423 return false; |
| 426 } | 424 } |
| 427 return true; | 425 return true; |
| 428 } | 426 } |
| 429 | 427 |
| 430 void SafeBrowsingDatabaseBloom::UpdateFinished(bool update_succeeded) { | 428 void SafeBrowsingDatabaseBloom::UpdateFinished(bool update_succeeded) { |
| 431 if (update_succeeded) | 429 if (update_succeeded) |
| 432 BuildBloomFilter(); | 430 BuildBloomFilter(); |
| 433 | 431 |
| 434 insert_transaction_.reset(); | |
| 435 Close(); | 432 Close(); |
| 436 | 433 |
| 437 // We won't need the chunk caches until the next update (which will read them | 434 // We won't need the chunk caches until the next update (which will read them |
| 438 // from the database), so free their memory as they may contain thousands of | 435 // from the database), so free their memory as they may contain thousands of |
| 439 // entries. | 436 // entries. |
| 440 ClearUpdateCaches(); | 437 ClearUpdateCaches(); |
| 441 } | 438 } |
| 442 | 439 |
| 443 void SafeBrowsingDatabaseBloom::InsertAdd(SBPrefix host, SBEntry* entry) { | 440 void SafeBrowsingDatabaseBloom::InsertAdd(SBPrefix host, SBEntry* entry) { |
| 444 STATS_COUNTER("SB.HostInsert", 1); | 441 STATS_COUNTER("SB.HostInsert", 1); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 if (did_resume_) { | 1486 if (did_resume_) { |
| 1490 PlatformThread::Sleep(kOnResumeHoldupMs); | 1487 PlatformThread::Sleep(kOnResumeHoldupMs); |
| 1491 did_resume_ = false; | 1488 did_resume_ = false; |
| 1492 } | 1489 } |
| 1493 } | 1490 } |
| 1494 | 1491 |
| 1495 // This database is always synchronous since we don't need to worry about | 1492 // This database is always synchronous since we don't need to worry about |
| 1496 // blocking any incoming reads. | 1493 // blocking any incoming reads. |
| 1497 void SafeBrowsingDatabaseBloom::SetSynchronous() { | 1494 void SafeBrowsingDatabaseBloom::SetSynchronous() { |
| 1498 } | 1495 } |
| OLD | NEW |