| 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_impl.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_database_impl.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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 ALLOW_THIS_IN_INITIALIZER_LIST(bloom_write_factory_(this)), | 69 ALLOW_THIS_IN_INITIALIZER_LIST(bloom_write_factory_(this)), |
| 70 ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)), | 70 ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)), |
| 71 ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)), | 71 ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)), |
| 72 disk_delay_(kMaxThreadHoldupMs) { | 72 disk_delay_(kMaxThreadHoldupMs) { |
| 73 } | 73 } |
| 74 | 74 |
| 75 SafeBrowsingDatabaseImpl::~SafeBrowsingDatabaseImpl() { | 75 SafeBrowsingDatabaseImpl::~SafeBrowsingDatabaseImpl() { |
| 76 Close(); | 76 Close(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool SafeBrowsingDatabaseImpl::Init(const std::wstring& filename, | 79 bool SafeBrowsingDatabaseImpl::Init(const FilePath& filename, |
| 80 Callback0::Type* chunk_inserted_callback) { | 80 Callback0::Type* chunk_inserted_callback) { |
| 81 DCHECK(!init_ && filename_.empty()); | 81 DCHECK(!init_ && filename_.empty()); |
| 82 | 82 |
| 83 filename_ = filename; | 83 filename_ = filename; |
| 84 if (!Open()) | 84 if (!Open()) |
| 85 return false; | 85 return false; |
| 86 | 86 |
| 87 bool load_filter = false; | 87 bool load_filter = false; |
| 88 if (!DoesSqliteTableExist(db_, "hosts")) { | 88 if (!DoesSqliteTableExist(db_, "hosts")) { |
| 89 if (!CreateTables()) { | 89 if (!CreateTables()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 107 new BloomFilter(kBloomFilterMinSize * kBloomFilterSizeRatio); | 107 new BloomFilter(kBloomFilterMinSize * kBloomFilterSizeRatio); |
| 108 } | 108 } |
| 109 | 109 |
| 110 init_ = true; | 110 init_ = true; |
| 111 chunk_inserted_callback_.reset(chunk_inserted_callback); | 111 chunk_inserted_callback_.reset(chunk_inserted_callback); |
| 112 | 112 |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool SafeBrowsingDatabaseImpl::Open() { | 116 bool SafeBrowsingDatabaseImpl::Open() { |
| 117 if (sqlite3_open(WideToUTF8(filename_).c_str(), &db_) != SQLITE_OK) | 117 if (OpenSqliteDb(filename_, &db_) != SQLITE_OK) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 // Run the database in exclusive mode. Nobody else should be accessing the | 120 // 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. | 121 // database while we're running, and this will give somewhat improved perf. |
| 122 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); | 122 sqlite3_exec(db_, "PRAGMA locking_mode=EXCLUSIVE", NULL, NULL, NULL); |
| 123 | 123 |
| 124 statement_cache_.reset(new SqliteStatementCache(db_)); | 124 statement_cache_.reset(new SqliteStatementCache(db_)); |
| 125 bloom_filter_read_count_= 0; | 125 bloom_filter_read_count_= 0; |
| 126 bloom_filter_fp_count_ = 0; | 126 bloom_filter_fp_count_ = 0; |
| 127 bloom_filter_building_ = false; | 127 bloom_filter_building_ = false; |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 kOnResumeHoldupMs); | 1216 kOnResumeHoldupMs); |
| 1217 } | 1217 } |
| 1218 | 1218 |
| 1219 void SafeBrowsingDatabaseImpl::OnResumeDone() { | 1219 void SafeBrowsingDatabaseImpl::OnResumeDone() { |
| 1220 disk_delay_ = kMaxThreadHoldupMs; | 1220 disk_delay_ = kMaxThreadHoldupMs; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 void SafeBrowsingDatabaseImpl::SetSynchronous() { | 1223 void SafeBrowsingDatabaseImpl::SetSynchronous() { |
| 1224 asynchronous_ = false; | 1224 asynchronous_ = false; |
| 1225 } | 1225 } |
| OLD | NEW |