OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/lock.h" | 13 #include "base/lock.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/task.h" | 15 #include "base/task.h" |
16 #include "chrome/browser/safe_browsing/safe_browsing_store.h" | 16 #include "chrome/browser/safe_browsing/safe_browsing_store.h" |
17 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
18 #include "testing/gtest/include/gtest/gtest_prod.h" | 18 #include "testing/gtest/include/gtest/gtest_prod.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class Time; | 21 class Time; |
22 } | 22 } |
23 | 23 |
24 class BloomFilter; | 24 class BloomFilter; |
25 class GURL; | 25 class GURL; |
26 class MessageLoop; | 26 class MessageLoop; |
27 class SafeBrowsingDatabase; | |
28 | |
29 // Factory for creating SafeBrowsingDatabase. Tests implement this factory | |
30 // to create fake Databases for testing. | |
31 class SafeBrowsingDatabaseFactory { | |
32 public: | |
33 SafeBrowsingDatabaseFactory() { } | |
34 virtual ~SafeBrowsingDatabaseFactory() { } | |
35 virtual SafeBrowsingDatabase* CreateSafeBrowsingDatabase() = 0; | |
36 private: | |
37 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactory); | |
38 }; | |
27 | 39 |
28 // Encapsulates the database that stores information about phishing | 40 // Encapsulates the database that stores information about phishing |
29 // and malware sites. There is one on-disk database for all profiles, | 41 // and malware sites. There is one on-disk database for all profiles, |
30 // as it doesn't contain user-specific data. This object is not | 42 // as it doesn't contain user-specific data. This object is not |
31 // thread-safe, i.e. all its methods should be used on the same thread | 43 // thread-safe, i.e. all its methods should be used on the same thread |
32 // that it was created on. | 44 // that it was created on. |
33 | 45 |
34 class SafeBrowsingDatabase { | 46 class SafeBrowsingDatabase { |
35 public: | 47 public: |
36 // Factory method for obtaining a SafeBrowsingDatabase implementation. | 48 // Factory method for obtaining a SafeBrowsingDatabase implementation. |
37 static SafeBrowsingDatabase* Create(); | 49 static SafeBrowsingDatabase* Create(); |
50 | |
51 // Makes the passed |factory| the factory used to instanciate | |
Scott Hess - ex-Googler
2010/12/07 21:22:57
"instantiate".
| |
52 // a SafeBrowsingDatabase. This is used for tests. | |
53 static void RegisterFactory(SafeBrowsingDatabaseFactory* factory) { | |
54 factory_ = factory; | |
55 } | |
56 | |
38 virtual ~SafeBrowsingDatabase(); | 57 virtual ~SafeBrowsingDatabase(); |
39 | 58 |
40 // Initializes the database with the given filename. | 59 // Initializes the database with the given filename. |
41 virtual void Init(const FilePath& filename) = 0; | 60 virtual void Init(const FilePath& filename) = 0; |
42 | 61 |
43 // Deletes the current database and creates a new one. | 62 // Deletes the current database and creates a new one. |
44 virtual bool ResetDatabase() = 0; | 63 virtual bool ResetDatabase() = 0; |
45 | 64 |
46 // Returns false if |url| is not in the database. If it returns | 65 // Returns false if |url| is not in the database. If it returns |
47 // true, then either |matching_list| is the name of the matching | 66 // true, then either |matching_list| is the name of the matching |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 FAILURE_DATABASE_FILTER_DELETE, | 124 FAILURE_DATABASE_FILTER_DELETE, |
106 FAILURE_DATABASE_STORE_MISSING, | 125 FAILURE_DATABASE_STORE_MISSING, |
107 FAILURE_DATABASE_STORE_DELETE, | 126 FAILURE_DATABASE_STORE_DELETE, |
108 | 127 |
109 // Memory space for histograms is determined by the max. ALWAYS | 128 // Memory space for histograms is determined by the max. ALWAYS |
110 // ADD NEW VALUES BEFORE THIS ONE. | 129 // ADD NEW VALUES BEFORE THIS ONE. |
111 FAILURE_DATABASE_MAX | 130 FAILURE_DATABASE_MAX |
112 }; | 131 }; |
113 | 132 |
114 static void RecordFailure(FailureType failure_type); | 133 static void RecordFailure(FailureType failure_type); |
134 private: | |
Scott Hess - ex-Googler
2010/12/07 21:22:57
Newline between RecordFailure() and private:.
| |
135 // The factory used to instanciate a SafeBrowsingDatabase object. | |
Scott Hess - ex-Googler
2010/12/07 21:22:57
"instantiate".
| |
136 // Useful for tests, so they can provide their own implementation of | |
137 // SafeBrowsingDatabase. | |
138 static SafeBrowsingDatabaseFactory* factory_; | |
139 | |
115 }; | 140 }; |
116 | 141 |
117 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { | 142 class SafeBrowsingDatabaseNew : public SafeBrowsingDatabase { |
118 public: | 143 public: |
119 // Create a database on the given store. Takes ownership of | 144 // Create a database on the given store. Takes ownership of |
120 // |store|. This method is temporary for | 145 // |store|. This method is temporary for |
121 // SafeBrowsingDatabase::Create(), do not use it otherwise. | 146 // SafeBrowsingDatabase::Create(), do not use it otherwise. |
122 explicit SafeBrowsingDatabaseNew(SafeBrowsingStore* store); | 147 explicit SafeBrowsingDatabaseNew(SafeBrowsingStore* store); |
123 | 148 |
124 // Create a database with a default store. | 149 // Create a database with a default store. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // Used to schedule resetting the database because of corruption. | 228 // Used to schedule resetting the database because of corruption. |
204 ScopedRunnableMethodFactory<SafeBrowsingDatabaseNew> reset_factory_; | 229 ScopedRunnableMethodFactory<SafeBrowsingDatabaseNew> reset_factory_; |
205 | 230 |
206 // Set if corruption is detected during the course of an update. | 231 // Set if corruption is detected during the course of an update. |
207 // Causes the update functions to fail with no side effects, until | 232 // Causes the update functions to fail with no side effects, until |
208 // the next call to |UpdateStarted()|. | 233 // the next call to |UpdateStarted()|. |
209 bool corruption_detected_; | 234 bool corruption_detected_; |
210 }; | 235 }; |
211 | 236 |
212 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ | 237 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_DATABASE_H_ |
OLD | NEW |