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