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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <list> | 9 #include <list> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/file_path.h" |
13 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
14 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
15 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
16 #include "base/task.h" | 17 #include "base/task.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "chrome/browser/safe_browsing/bloom_filter.h" | 19 #include "chrome/browser/safe_browsing/bloom_filter.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
20 #include "testing/gtest/include/gtest/gtest_prod.h" | 21 #include "testing/gtest/include/gtest/gtest_prod.h" |
21 | 22 |
22 class GURL; | 23 class GURL; |
23 | 24 |
24 // Encapsulates the database that stores information about phishing and malware | 25 // Encapsulates the database that stores information about phishing and malware |
25 // sites. There is one on-disk database for all profiles, as it doesn't | 26 // sites. There is one on-disk database for all profiles, as it doesn't |
26 // contain user-specific data. This object is not thread-safe, i.e. all its | 27 // contain user-specific data. This object is not thread-safe, i.e. all its |
27 // methods should be used on the same thread that it was created on, with the | 28 // methods should be used on the same thread that it was created on, with the |
28 // exception of NeedToCheckUrl. | 29 // exception of NeedToCheckUrl. |
29 class SafeBrowsingDatabase { | 30 class SafeBrowsingDatabase { |
30 public: | 31 public: |
31 // Factory method for obtaining a SafeBrowsingDatabase implementation. | 32 // Factory method for obtaining a SafeBrowsingDatabase implementation. |
32 static SafeBrowsingDatabase* Create(); | 33 static SafeBrowsingDatabase* Create(); |
33 | 34 |
34 virtual ~SafeBrowsingDatabase() {} | 35 virtual ~SafeBrowsingDatabase() {} |
35 | 36 |
36 // Initializes the database with the given filename. The callback is | 37 // Initializes the database with the given filename. The callback is |
37 // executed after finishing a chunk. | 38 // executed after finishing a chunk. |
38 virtual bool Init(const std::wstring& filename, | 39 virtual bool Init(const FilePath& filename, |
39 Callback0::Type* chunk_inserted_callback) = 0; | 40 Callback0::Type* chunk_inserted_callback) = 0; |
40 | 41 |
41 // Deletes the current database and creates a new one. | 42 // Deletes the current database and creates a new one. |
42 virtual bool ResetDatabase() = 0; | 43 virtual bool ResetDatabase() = 0; |
43 | 44 |
44 // This function can be called on any thread to check if the given url may be | 45 // This function can be called on any thread to check if the given url may be |
45 // in the database. If this function returns false, it is definitely not in | 46 // in the database. If this function returns false, it is definitely not in |
46 // the database and ContainsUrl doesn't need to be called. If it returns | 47 // the database and ContainsUrl doesn't need to be called. If it returns |
47 // true, then the url might be in the database and ContainsUrl needs to be | 48 // true, then the url might be in the database and ContainsUrl needs to be |
48 // called. This function can only be called after Init succeeded. | 49 // called. This function can only be called after Init succeeded. |
(...skipping 30 matching lines...) Expand all Loading... |
79 virtual void CacheHashResults( | 80 virtual void CacheHashResults( |
80 const std::vector<SBPrefix>& prefixes, | 81 const std::vector<SBPrefix>& prefixes, |
81 const std::vector<SBFullHashResult>& full_hits) = 0; | 82 const std::vector<SBFullHashResult>& full_hits) = 0; |
82 | 83 |
83 // Called when the user's machine has resumed from a lower power state. | 84 // Called when the user's machine has resumed from a lower power state. |
84 virtual void HandleResume() = 0; | 85 virtual void HandleResume() = 0; |
85 | 86 |
86 virtual bool UpdateStarted() { return true; } | 87 virtual bool UpdateStarted() { return true; } |
87 virtual void UpdateFinished(bool update_succeeded) {} | 88 virtual void UpdateFinished(bool update_succeeded) {} |
88 | 89 |
89 virtual std::wstring filename() const { return filename_; } | 90 virtual FilePath filename() const { return filename_; } |
90 | 91 |
91 protected: | 92 protected: |
92 friend class SafeBrowsingDatabaseTest; | 93 friend class SafeBrowsingDatabaseTest; |
93 FRIEND_TEST(SafeBrowsingDatabase, HashCaching); | 94 FRIEND_TEST(SafeBrowsingDatabase, HashCaching); |
94 | 95 |
95 static std::wstring BloomFilterFilename(const std::wstring& db_filename); | 96 static FilePath BloomFilterFilename(const FilePath& db_filename); |
96 | 97 |
97 // Load the bloom filter off disk, or generates one if it doesn't exist. | 98 // Load the bloom filter off disk, or generates one if it doesn't exist. |
98 virtual void LoadBloomFilter(); | 99 virtual void LoadBloomFilter(); |
99 | 100 |
100 // Deletes the on-disk bloom filter, i.e. because it's stale. | 101 // Deletes the on-disk bloom filter, i.e. because it's stale. |
101 virtual void DeleteBloomFilter(); | 102 virtual void DeleteBloomFilter(); |
102 | 103 |
103 // Writes the current bloom filter to disk. | 104 // Writes the current bloom filter to disk. |
104 virtual void WriteBloomFilter(); | 105 virtual void WriteBloomFilter(); |
105 | 106 |
(...skipping 15 matching lines...) Expand all Loading... |
121 typedef base::hash_map<SBPrefix, HashList> HashCache; | 122 typedef base::hash_map<SBPrefix, HashList> HashCache; |
122 | 123 |
123 scoped_ptr<HashCache> hash_cache_; | 124 scoped_ptr<HashCache> hash_cache_; |
124 HashCache* hash_cache() { return hash_cache_.get(); } | 125 HashCache* hash_cache() { return hash_cache_.get(); } |
125 | 126 |
126 // Cache of prefixes that returned empty results (no full hash match). | 127 // Cache of prefixes that returned empty results (no full hash match). |
127 typedef std::set<SBPrefix> PrefixCache; | 128 typedef std::set<SBPrefix> PrefixCache; |
128 PrefixCache prefix_miss_cache_; | 129 PrefixCache prefix_miss_cache_; |
129 PrefixCache* prefix_miss_cache() { return &prefix_miss_cache_; } | 130 PrefixCache* prefix_miss_cache() { return &prefix_miss_cache_; } |
130 | 131 |
131 std::wstring filename_; | 132 FilePath filename_; |
132 std::wstring bloom_filter_filename_; | 133 FilePath bloom_filter_filename_; |
133 scoped_refptr<BloomFilter> bloom_filter_; | 134 scoped_refptr<BloomFilter> bloom_filter_; |
134 }; | 135 }; |
135 | 136 |
136 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 137 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
OLD | NEW |