| 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/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/platform_thread.h" |
| 10 #include "base/sha2.h" | 12 #include "base/sha2.h" |
| 11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 12 #include "chrome/browser/safe_browsing/bloom_filter.h" | 14 #include "chrome/browser/safe_browsing/bloom_filter.h" |
| 13 #include "chrome/browser/safe_browsing/chunk_range.h" | 15 #include "chrome/browser/safe_browsing/chunk_range.h" |
| 14 #include "chrome/common/sqlite_compiled_statement.h" | 16 #include "chrome/common/sqlite_compiled_statement.h" |
| 15 #include "chrome/common/sqlite_utils.h" | 17 #include "chrome/common/sqlite_utils.h" |
| 16 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 17 | 19 |
| 18 // Database version. If this is different than what's stored on disk, the | 20 // Database version. If this is different than what's stored on disk, the |
| 19 // database is reset. | 21 // database is reset. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 // down. | 33 // down. |
| 32 static const int kOnResumeHoldupMs = 5 * 60 * 1000; // 5 minutes. | 34 static const int kOnResumeHoldupMs = 5 * 60 * 1000; // 5 minutes. |
| 33 | 35 |
| 34 // The maximum staleness for a cached entry. | 36 // The maximum staleness for a cached entry. |
| 35 static const int kMaxStalenessMinutes = 45; | 37 static const int kMaxStalenessMinutes = 45; |
| 36 | 38 |
| 37 // Implementation -------------------------------------------------------------- | 39 // Implementation -------------------------------------------------------------- |
| 38 | 40 |
| 39 SafeBrowsingDatabaseBloom::SafeBrowsingDatabaseBloom() | 41 SafeBrowsingDatabaseBloom::SafeBrowsingDatabaseBloom() |
| 40 : db_(NULL), | 42 : db_(NULL), |
| 43 transaction_count_(0), |
| 41 init_(false), | 44 init_(false), |
| 42 transaction_count_(0), | |
| 43 chunk_inserted_callback_(NULL), | 45 chunk_inserted_callback_(NULL), |
| 44 #pragma warning(suppress: 4355) // can use this | 46 ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)), |
| 45 reset_factory_(this), | 47 ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)), |
| 46 #pragma warning(suppress: 4355) // can use this | |
| 47 resume_factory_(this), | |
| 48 did_resume_(false) { | 48 did_resume_(false) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 SafeBrowsingDatabaseBloom::~SafeBrowsingDatabaseBloom() { | 51 SafeBrowsingDatabaseBloom::~SafeBrowsingDatabaseBloom() { |
| 52 Close(); | 52 Close(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool SafeBrowsingDatabaseBloom::Init(const std::wstring& filename, | 55 bool SafeBrowsingDatabaseBloom::Init(const std::wstring& filename, |
| 56 Callback0::Type* chunk_inserted_callback) { | 56 Callback0::Type* chunk_inserted_callback) { |
| 57 DCHECK(!init_ && filename_.empty()); | 57 DCHECK(!init_ && filename_.empty()); |
| (...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 while (it != hash_cache_.end()) { | 1010 while (it != hash_cache_.end()) { |
| 1011 HashList& entries = it->second; | 1011 HashList& entries = it->second; |
| 1012 HashList::iterator eit = entries.begin(); | 1012 HashList::iterator eit = entries.begin(); |
| 1013 while (eit != entries.end()) { | 1013 while (eit != entries.end()) { |
| 1014 if (eit->list_id == list_id && eit->add_chunk_id == add_chunk_id) | 1014 if (eit->list_id == list_id && eit->add_chunk_id == add_chunk_id) |
| 1015 eit = entries.erase(eit); | 1015 eit = entries.erase(eit); |
| 1016 else | 1016 else |
| 1017 ++eit; | 1017 ++eit; |
| 1018 } | 1018 } |
| 1019 if (entries.empty()) | 1019 if (entries.empty()) |
| 1020 it = hash_cache_.erase(it); | 1020 hash_cache_.erase(it++); |
| 1021 else | 1021 else |
| 1022 ++it; | 1022 ++it; |
| 1023 } | 1023 } |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 void SafeBrowsingDatabaseBloom::HandleCorruptDatabase() { | 1026 void SafeBrowsingDatabaseBloom::HandleCorruptDatabase() { |
| 1027 MessageLoop::current()->PostTask(FROM_HERE, | 1027 MessageLoop::current()->PostTask(FROM_HERE, |
| 1028 reset_factory_.NewRunnableMethod( | 1028 reset_factory_.NewRunnableMethod( |
| 1029 &SafeBrowsingDatabaseBloom::OnHandleCorruptDatabase)); | 1029 &SafeBrowsingDatabaseBloom::OnHandleCorruptDatabase)); |
| 1030 } | 1030 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1042 &SafeBrowsingDatabaseBloom::OnResumeDone), | 1042 &SafeBrowsingDatabaseBloom::OnResumeDone), |
| 1043 kOnResumeHoldupMs); | 1043 kOnResumeHoldupMs); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 void SafeBrowsingDatabaseBloom::OnResumeDone() { | 1046 void SafeBrowsingDatabaseBloom::OnResumeDone() { |
| 1047 did_resume_ = false; | 1047 did_resume_ = false; |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 void SafeBrowsingDatabaseBloom::WaitAfterResume() { | 1050 void SafeBrowsingDatabaseBloom::WaitAfterResume() { |
| 1051 if (did_resume_) { | 1051 if (did_resume_) { |
| 1052 Sleep(kOnResumeHoldupMs); | 1052 PlatformThread::Sleep(kOnResumeHoldupMs); |
| 1053 did_resume_ = false; | 1053 did_resume_ = false; |
| 1054 } | 1054 } |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 // This database is always synchronous since we don't need to worry about | 1057 // This database is always synchronous since we don't need to worry about |
| 1058 // blocking any incoming reads. | 1058 // blocking any incoming reads. |
| 1059 void SafeBrowsingDatabaseBloom::SetSynchronous() { | 1059 void SafeBrowsingDatabaseBloom::SetSynchronous() { |
| 1060 } | 1060 } |
| OLD | NEW |