| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // When we awake from a low power state, we try to avoid doing expensive disk | 36 // When we awake from a low power state, we try to avoid doing expensive disk |
| 37 // operations for a few minutes to let the system page itself in and settle | 37 // operations for a few minutes to let the system page itself in and settle |
| 38 // down. | 38 // down. |
| 39 static const int kOnResumeHoldupMs = 5 * 60 * 1000; // 5 minutes. | 39 static const int kOnResumeHoldupMs = 5 * 60 * 1000; // 5 minutes. |
| 40 | 40 |
| 41 // The maximum staleness for a cached entry. | 41 // The maximum staleness for a cached entry. |
| 42 static const int kMaxStalenessMinutes = 45; | 42 static const int kMaxStalenessMinutes = 45; |
| 43 | 43 |
| 44 // The bloom filter based file name suffix. | 44 // The bloom filter based file name suffix. |
| 45 static const wchar_t kBloomFilterFileSuffix[] = L" Bloom"; | 45 static const FilePath::CharType kBloomFilterFileSuffix[] = |
| 46 FILE_PATH_LITERAL(" Bloom"); |
| 46 | 47 |
| 47 | 48 |
| 48 // Implementation -------------------------------------------------------------- | 49 // Implementation -------------------------------------------------------------- |
| 49 | 50 |
| 50 SafeBrowsingDatabaseBloom::SafeBrowsingDatabaseBloom() | 51 SafeBrowsingDatabaseBloom::SafeBrowsingDatabaseBloom() |
| 51 : db_(NULL), | 52 : db_(NULL), |
| 52 init_(false), | 53 init_(false), |
| 53 ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)), | 54 ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)), |
| 54 ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)), | 55 ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)), |
| 55 add_count_(0), | 56 add_count_(0), |
| 56 did_resume_(false) { | 57 did_resume_(false) { |
| 57 } | 58 } |
| 58 | 59 |
| 59 SafeBrowsingDatabaseBloom::~SafeBrowsingDatabaseBloom() { | 60 SafeBrowsingDatabaseBloom::~SafeBrowsingDatabaseBloom() { |
| 60 Close(); | 61 Close(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool SafeBrowsingDatabaseBloom::Init(const std::wstring& filename, | 64 bool SafeBrowsingDatabaseBloom::Init(const FilePath& filename, |
| 64 Callback0::Type* chunk_inserted_callback) { | 65 Callback0::Type* chunk_inserted_callback) { |
| 65 DCHECK(!init_ && filename_.empty()); | 66 DCHECK(!init_ && filename_.empty()); |
| 66 | 67 |
| 67 filename_ = filename + kBloomFilterFileSuffix; | 68 filename_ = FilePath(filename.value() + kBloomFilterFileSuffix); |
| 68 bloom_filter_filename_ = BloomFilterFilename(filename_); | 69 bloom_filter_filename_ = BloomFilterFilename(filename_); |
| 69 | 70 |
| 70 hash_cache_.reset(new HashCache); | 71 hash_cache_.reset(new HashCache); |
| 71 | 72 |
| 72 LoadBloomFilter(); | 73 LoadBloomFilter(); |
| 73 | 74 |
| 74 init_ = true; | 75 init_ = true; |
| 75 chunk_inserted_callback_.reset(chunk_inserted_callback); | 76 chunk_inserted_callback_.reset(chunk_inserted_callback); |
| 76 | 77 |
| 77 return true; | 78 return true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 SB_DLOG(INFO) << "SafeBrowsingDatabase read bloom filter in " | 105 SB_DLOG(INFO) << "SafeBrowsingDatabase read bloom filter in " |
| 105 << (Time::Now() - before).InMilliseconds() << " ms"; | 106 << (Time::Now() - before).InMilliseconds() << " ms"; |
| 106 | 107 |
| 107 bloom_filter_ = new BloomFilter(data, size); | 108 bloom_filter_ = new BloomFilter(data, size); |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool SafeBrowsingDatabaseBloom::Open() { | 111 bool SafeBrowsingDatabaseBloom::Open() { |
| 111 if (db_) | 112 if (db_) |
| 112 return true; | 113 return true; |
| 113 | 114 |
| 114 if (sqlite3_open(WideToUTF8(filename_).c_str(), &db_) != SQLITE_OK) { | 115 if (OpenSqliteDb(filename_, &db_) != SQLITE_OK) { |
| 115 sqlite3_close(db_); | 116 sqlite3_close(db_); |
| 116 db_ = NULL; | 117 db_ = NULL; |
| 117 return false; | 118 return false; |
| 118 } | 119 } |
| 119 | 120 |
| 120 // Run the database in exclusive mode. Nobody else should be accessing the | 121 // Run the database in exclusive mode. Nobody else should be accessing the |
| 121 // database while we're running, and this will give somewhat improved perf. | 122 // database while we're running, and this will give somewhat improved perf. |
| 122 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); | 123 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); |
| 123 | 124 |
| 124 statement_cache_.reset(new SqliteStatementCache(db_)); | 125 statement_cache_.reset(new SqliteStatementCache(db_)); |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 if (did_resume_) { | 1487 if (did_resume_) { |
| 1487 PlatformThread::Sleep(kOnResumeHoldupMs); | 1488 PlatformThread::Sleep(kOnResumeHoldupMs); |
| 1488 did_resume_ = false; | 1489 did_resume_ = false; |
| 1489 } | 1490 } |
| 1490 } | 1491 } |
| 1491 | 1492 |
| 1492 // This database is always synchronous since we don't need to worry about | 1493 // This database is always synchronous since we don't need to worry about |
| 1493 // blocking any incoming reads. | 1494 // blocking any incoming reads. |
| 1494 void SafeBrowsingDatabaseBloom::SetSynchronous() { | 1495 void SafeBrowsingDatabaseBloom::SetSynchronous() { |
| 1495 } | 1496 } |
| OLD | NEW |