OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/thread.h" | 19 #include "base/thread.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 21 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
23 #include "webkit/glue/resource_type.h" | 23 #include "webkit/glue/resource_type.h" |
24 | 24 |
25 class BloomFilter; | 25 class BloomFilter; |
26 class MessageLoop; | |
27 class PrefService; | 26 class PrefService; |
28 class SafeBrowsingBlockingPage; | 27 class SafeBrowsingBlockingPage; |
29 class SafeBrowsingDatabase; | 28 class SafeBrowsingDatabase; |
30 class SafeBrowsingProtocolManager; | 29 class SafeBrowsingProtocolManager; |
31 | 30 |
32 // Construction needs to happen on the main thread. | 31 // Construction needs to happen on the main thread. |
33 class SafeBrowsingService | 32 class SafeBrowsingService |
34 : public base::RefCountedThreadSafe<SafeBrowsingService> { | 33 : public base::RefCountedThreadSafe<SafeBrowsingService> { |
35 public: | 34 public: |
36 // Users of this service implement this interface to be notified | 35 // Users of this service implement this interface to be notified |
(...skipping 24 matching lines...) Expand all Loading... |
61 UrlCheckResult threat_type; | 60 UrlCheckResult threat_type; |
62 Client* client; | 61 Client* client; |
63 int render_process_host_id; | 62 int render_process_host_id; |
64 int render_view_id; | 63 int render_view_id; |
65 }; | 64 }; |
66 | 65 |
67 // Creates the safe browsing service. Need to initialize before using. | 66 // Creates the safe browsing service. Need to initialize before using. |
68 SafeBrowsingService(); | 67 SafeBrowsingService(); |
69 ~SafeBrowsingService(); | 68 ~SafeBrowsingService(); |
70 | 69 |
71 // Initializes the service. io_loop is the message loop that the | 70 // Initializes the service. |
72 // caller of this service (ResourceDispatcherHost) wants to be notified on | 71 void Initialize(); |
73 // for check results. | |
74 void Initialize(MessageLoop* io_loop); | |
75 | 72 |
76 // Called to initialize objects that are used on the io_thread. | 73 // Called to initialize objects that are used on the io_thread. |
77 void OnIOInitialize(MessageLoop* notify_loop, | 74 void OnIOInitialize(const std::string& client_key, |
78 const std::string& client_key, | |
79 const std::string& wrapped_key); | 75 const std::string& wrapped_key); |
80 | 76 |
81 // Called to initialize objects that are used on the db_thread. | 77 // Called to initialize objects that are used on the db_thread. |
82 void OnDBInitialize(); | 78 void OnDBInitialize(); |
83 | 79 |
84 // Called to shutdown operations on the io_thread. | 80 // Called to shutdown operations on the io_thread. |
85 void OnIOShutdown(); | 81 void OnIOShutdown(); |
86 | 82 |
87 // Called on the main thread to let us know that the io_thread is going away. | 83 // Called on the main thread to let us know that the io_thread is going away. |
88 void ShutDown(); | 84 void ShutDown(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // Invoked on the UI thread to show the blocking page. | 223 // Invoked on the UI thread to show the blocking page. |
228 void DoDisplayBlockingPage(const UnsafeResource& resource); | 224 void DoDisplayBlockingPage(const UnsafeResource& resource); |
229 | 225 |
230 // During a reset or the initial load we may have to queue checks until the | 226 // During a reset or the initial load we may have to queue checks until the |
231 // database is ready. This method is run once the database has loaded (or if | 227 // database is ready. This method is run once the database has loaded (or if |
232 // we shut down SafeBrowsing before the database has finished loading). | 228 // we shut down SafeBrowsing before the database has finished loading). |
233 void RunQueuedClients(); | 229 void RunQueuedClients(); |
234 | 230 |
235 void OnUpdateComplete(bool update_succeeded); | 231 void OnUpdateComplete(bool update_succeeded); |
236 | 232 |
237 MessageLoop* io_loop_; | |
238 | |
239 typedef std::set<SafeBrowsingCheck*> CurrentChecks; | 233 typedef std::set<SafeBrowsingCheck*> CurrentChecks; |
240 CurrentChecks checks_; | 234 CurrentChecks checks_; |
241 | 235 |
242 // Used for issuing only one GetHash request for a given prefix. | 236 // Used for issuing only one GetHash request for a given prefix. |
243 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; | 237 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; |
244 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; | 238 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; |
245 GetHashRequests gethash_requests_; | 239 GetHashRequests gethash_requests_; |
246 | 240 |
247 // The sqlite database. We don't use a scoped_ptr because it needs to be | 241 // The sqlite database. We don't use a scoped_ptr because it needs to be |
248 // destructed on a different thread than this object. | 242 // destructed on a different thread than this object. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 Client* client; | 276 Client* client; |
283 GURL url; | 277 GURL url; |
284 base::Time start; | 278 base::Time start; |
285 } QueuedCheck; | 279 } QueuedCheck; |
286 std::deque<QueuedCheck> queued_checks_; | 280 std::deque<QueuedCheck> queued_checks_; |
287 | 281 |
288 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); | 282 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |
289 }; | 283 }; |
290 | 284 |
291 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ | 285 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ |
OLD | NEW |