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 // The Safe Browsing service is responsible for downloading anti-phishing and | 5 // The Safe Browsing service is responsible for downloading anti-phishing and |
6 // anti-malware tables and checking urls against them. | 6 // anti-malware tables and checking urls against them. |
7 | 7 |
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
10 | 10 |
11 #include <deque> | 11 #include <deque> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/hash_tables.h" | 16 #include "base/hash_tables.h" |
17 #include "base/ref_counted.h" | 17 #include "base/ref_counted.h" |
18 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
19 #include "base/system_monitor.h" | |
20 #include "base/thread.h" | 19 #include "base/thread.h" |
21 #include "base/time.h" | 20 #include "base/time.h" |
22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
23 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
24 #include "webkit/glue/resource_type.h" | 23 #include "webkit/glue/resource_type.h" |
25 | 24 |
26 class BloomFilter; | 25 class BloomFilter; |
27 class MessageLoop; | 26 class MessageLoop; |
28 class PrefService; | 27 class PrefService; |
29 class SafeBrowsingBlockingPage; | 28 class SafeBrowsingBlockingPage; |
30 class SafeBrowsingDatabase; | 29 class SafeBrowsingDatabase; |
31 class SafeBrowsingProtocolManager; | 30 class SafeBrowsingProtocolManager; |
32 | 31 |
33 // Construction needs to happen on the main thread. | 32 // Construction needs to happen on the main thread. |
34 class SafeBrowsingService | 33 class SafeBrowsingService |
35 : public base::RefCountedThreadSafe<SafeBrowsingService>, | 34 : public base::RefCountedThreadSafe<SafeBrowsingService> { |
36 public base::SystemMonitor::PowerObserver { | |
37 public: | 35 public: |
38 // Users of this service implement this interface to be notified | 36 // Users of this service implement this interface to be notified |
39 // asynchronously of the result. | 37 // asynchronously of the result. |
40 enum UrlCheckResult { | 38 enum UrlCheckResult { |
41 URL_SAFE, | 39 URL_SAFE, |
42 URL_PHISHING, | 40 URL_PHISHING, |
43 URL_MALWARE, | 41 URL_MALWARE, |
44 }; | 42 }; |
45 | 43 |
46 class Client { | 44 class Client { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 162 |
165 // The SafeBrowsing system has instructed us to reset our database. | 163 // The SafeBrowsing system has instructed us to reset our database. |
166 void ResetDatabase(); | 164 void ResetDatabase(); |
167 | 165 |
168 // Log the user perceived delay caused by SafeBrowsing. This delay is the time | 166 // Log the user perceived delay caused by SafeBrowsing. This delay is the time |
169 // delta starting from when we would have started reading data from the | 167 // delta starting from when we would have started reading data from the |
170 // network, and ending when the SafeBrowsing check completes indicating that | 168 // network, and ending when the SafeBrowsing check completes indicating that |
171 // the current page is 'safe'. | 169 // the current page is 'safe'. |
172 void LogPauseDelay(base::TimeDelta time); | 170 void LogPauseDelay(base::TimeDelta time); |
173 | 171 |
174 // PowerObserver notifications | |
175 // We defer SafeBrowsing work for a short duration when the computer comes | 172 // We defer SafeBrowsing work for a short duration when the computer comes |
176 // out of a suspend state to avoid thrashing the disk. | 173 // out of a suspend state to avoid thrashing the disk. |
177 void OnPowerStateChange(base::SystemMonitor*) {}; | 174 void OnSuspend(); |
178 void OnSuspend(base::SystemMonitor*); | 175 void OnResume(); |
179 void OnResume(base::SystemMonitor*); | |
180 | 176 |
181 bool new_safe_browsing() const { return new_safe_browsing_; } | 177 bool new_safe_browsing() const { return new_safe_browsing_; } |
182 | 178 |
183 private: | 179 private: |
184 // Should only be called on db thread as SafeBrowsingDatabase is not | 180 // Should only be called on db thread as SafeBrowsingDatabase is not |
185 // threadsafe. | 181 // threadsafe. |
186 SafeBrowsingDatabase* GetDatabase(); | 182 SafeBrowsingDatabase* GetDatabase(); |
187 | 183 |
188 // Release the final reference to the database on the db thread. | 184 // Release the final reference to the database on the db thread. |
189 void ReleaseDatabase(SafeBrowsingDatabase* database); | 185 void ReleaseDatabase(SafeBrowsingDatabase* database); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 Client* client; | 295 Client* client; |
300 GURL url; | 296 GURL url; |
301 base::Time start; | 297 base::Time start; |
302 } QueuedCheck; | 298 } QueuedCheck; |
303 std::deque<QueuedCheck> queued_checks_; | 299 std::deque<QueuedCheck> queued_checks_; |
304 | 300 |
305 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 301 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
306 }; | 302 }; |
307 | 303 |
308 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 304 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
OLD | NEW |