Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service.h

Issue 7313003: Separate memory purger from safe browsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/memory_purger.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 10 #pragma once
11 11
12 #include <deque> 12 #include <deque>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/hash_tables.h" 17 #include "base/hash_tables.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "base/task.h" 21 #include "base/task.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 23 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
24 #include "content/common/notification_observer.h"
25 #include "content/common/notification_registrar.h"
24 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
25 27
26 class MalwareDetails; 28 class MalwareDetails;
27 class PrefService; 29 class PrefService;
28 class SafeBrowsingDatabase; 30 class SafeBrowsingDatabase;
29 class SafeBrowsingProtocolManager; 31 class SafeBrowsingProtocolManager;
30 class SafeBrowsingServiceFactory; 32 class SafeBrowsingServiceFactory;
31 33
32 namespace base { 34 namespace base {
33 class Thread; 35 class Thread;
34 } 36 }
35 37
36 namespace net { 38 namespace net {
37 class URLRequestContextGetter; 39 class URLRequestContextGetter;
38 } 40 }
39 41
40 // Construction needs to happen on the main thread. 42 // Construction needs to happen on the main thread.
41 class SafeBrowsingService 43 class SafeBrowsingService
42 : public base::RefCountedThreadSafe<SafeBrowsingService> { 44 : public base::RefCountedThreadSafe<SafeBrowsingService>,
45 public NotificationObserver {
43 public: 46 public:
44 class Client; 47 class Client;
45 // Users of this service implement this interface to be notified 48 // Users of this service implement this interface to be notified
46 // asynchronously of the result. 49 // asynchronously of the result.
47 enum UrlCheckResult { 50 enum UrlCheckResult {
48 SAFE, 51 SAFE,
49 URL_PHISHING, 52 URL_PHISHING,
50 URL_MALWARE, 53 URL_MALWARE,
51 BINARY_MALWARE_URL, // Binary url leads to a malware. 54 BINARY_MALWARE_URL, // Binary url leads to a malware.
52 BINARY_MALWARE_HASH, // Binary hash indicates this is a malware. 55 BINARY_MALWARE_HASH, // Binary hash indicates this is a malware.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 232
230 bool enabled() const { return enabled_; } 233 bool enabled() const { return enabled_; }
231 234
232 bool download_protection_enabled() const { 235 bool download_protection_enabled() const {
233 return enabled_ && enable_download_protection_; 236 return enabled_ && enable_download_protection_;
234 } 237 }
235 238
236 // Preference handling. 239 // Preference handling.
237 static void RegisterPrefs(PrefService* prefs); 240 static void RegisterPrefs(PrefService* prefs);
238 241
239 // Called on the IO thread to try to close the database, freeing the memory
240 // associated with it. The database will be automatically reopened as needed.
241 //
242 // NOTE: Actual database closure is asynchronous, and until it happens, the IO
243 // thread is not allowed to access it; may not actually trigger a close if one
244 // is already pending or doing so would cause problems.
245 void CloseDatabase();
246
247 // Called on the IO thread to reset the database. 242 // Called on the IO thread to reset the database.
248 void ResetDatabase(); 243 void ResetDatabase();
249 244
250 // Log the user perceived delay caused by SafeBrowsing. This delay is the time 245 // Log the user perceived delay caused by SafeBrowsing. This delay is the time
251 // delta starting from when we would have started reading data from the 246 // delta starting from when we would have started reading data from the
252 // network, and ending when the SafeBrowsing check completes indicating that 247 // network, and ending when the SafeBrowsing check completes indicating that
253 // the current page is 'safe'. 248 // the current page is 'safe'.
254 void LogPauseDelay(base::TimeDelta time); 249 void LogPauseDelay(base::TimeDelta time);
255 250
256 // Called on the IO thread by the MalwareDetails with the serialized 251 // Called on the IO thread by the MalwareDetails with the serialized
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Returns whether |database_| exists and is accessible. 299 // Returns whether |database_| exists and is accessible.
305 bool DatabaseAvailable() const; 300 bool DatabaseAvailable() const;
306 301
307 // Called on the IO thread. If the database does not exist, queues up a call 302 // Called on the IO thread. If the database does not exist, queues up a call
308 // on the db thread to create it. Returns whether the database is available. 303 // on the db thread to create it. Returns whether the database is available.
309 // 304 //
310 // Note that this is only needed outside the db thread, since functions on the 305 // Note that this is only needed outside the db thread, since functions on the
311 // db thread can call GetDatabase() directly. 306 // db thread can call GetDatabase() directly.
312 bool MakeDatabaseAvailable(); 307 bool MakeDatabaseAvailable();
313 308
309 // Called on the IO thread to try to close the database, freeing the memory
310 // associated with it. The database will be automatically reopened as needed.
311 //
312 // NOTE: Actual database closure is asynchronous, and until it happens, the IO
313 // thread is not allowed to access it; may not actually trigger a close if one
314 // is already pending or doing so would cause problems.
315 void CloseDatabase();
316
314 // Should only be called on db thread as SafeBrowsingDatabase is not 317 // Should only be called on db thread as SafeBrowsingDatabase is not
315 // threadsafe. 318 // threadsafe.
316 SafeBrowsingDatabase* GetDatabase(); 319 SafeBrowsingDatabase* GetDatabase();
317 320
318 // Called on the IO thread with the check result. 321 // Called on the IO thread with the check result.
319 void OnCheckDone(SafeBrowsingCheck* info); 322 void OnCheckDone(SafeBrowsingCheck* info);
320 323
321 // Called on the database thread to retrieve chunks. 324 // Called on the database thread to retrieve chunks.
322 void GetAllChunksFromDatabase(); 325 void GetAllChunksFromDatabase();
323 326
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // browsing check with timeout of |timeout_ms|. |task| will be called upon 406 // browsing check with timeout of |timeout_ms|. |task| will be called upon
404 // success, otherwise TimeoutCallback will be called. 407 // success, otherwise TimeoutCallback will be called.
405 void StartDownloadCheck(SafeBrowsingCheck* check, 408 void StartDownloadCheck(SafeBrowsingCheck* check,
406 Client* client, 409 Client* client,
407 CancelableTask* task, 410 CancelableTask* task,
408 int64 timeout_ms); 411 int64 timeout_ms);
409 412
410 // Adds the given entry to the whitelist. Called on the UI thread. 413 // Adds the given entry to the whitelist. Called on the UI thread.
411 void UpdateWhitelist(const UnsafeResource& resource); 414 void UpdateWhitelist(const UnsafeResource& resource);
412 415
416 // NotificationObserver override
417 virtual void Observe(NotificationType type,
418 const NotificationSource& source,
419 const NotificationDetails& details) OVERRIDE;
420
413 // The factory used to instanciate a SafeBrowsingService object. 421 // The factory used to instanciate a SafeBrowsingService object.
414 // Useful for tests, so they can provide their own implementation of 422 // Useful for tests, so they can provide their own implementation of
415 // SafeBrowsingService. 423 // SafeBrowsingService.
416 static SafeBrowsingServiceFactory* factory_; 424 static SafeBrowsingServiceFactory* factory_;
417 425
418 CurrentChecks checks_; 426 CurrentChecks checks_;
419 427
420 // Used for issuing only one GetHash request for a given prefix. 428 // Used for issuing only one GetHash request for a given prefix.
421 GetHashRequests gethash_requests_; 429 GetHashRequests gethash_requests_;
422 430
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 473
466 std::deque<QueuedCheck> queued_checks_; 474 std::deque<QueuedCheck> queued_checks_;
467 475
468 // When download url check takes this long, client's callback will be called 476 // When download url check takes this long, client's callback will be called
469 // without waiting for the result. 477 // without waiting for the result.
470 int64 download_urlcheck_timeout_ms_; 478 int64 download_urlcheck_timeout_ms_;
471 479
472 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. 480 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks.
473 int64 download_hashcheck_timeout_ms_; 481 int64 download_hashcheck_timeout_ms_;
474 482
483 NotificationRegistrar registrar_;
484
475 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); 485 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService);
476 }; 486 };
477 487
478 // Factory for creating SafeBrowsingService. Useful for tests. 488 // Factory for creating SafeBrowsingService. Useful for tests.
479 class SafeBrowsingServiceFactory { 489 class SafeBrowsingServiceFactory {
480 public: 490 public:
481 SafeBrowsingServiceFactory() { } 491 SafeBrowsingServiceFactory() { }
482 virtual ~SafeBrowsingServiceFactory() { } 492 virtual ~SafeBrowsingServiceFactory() { }
483 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0; 493 virtual SafeBrowsingService* CreateSafeBrowsingService() = 0;
484 private: 494 private:
485 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory); 495 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingServiceFactory);
486 }; 496 };
487 497
488 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_ 498 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/memory_purger.cc ('k') | chrome/browser/safe_browsing/safe_browsing_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698