diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 00:28:54 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 00:28:54 +0000 |
commit | 90a3b24080e8432726dde4b4f72821e49416180e (patch) | |
tree | 0fd94921b79a9452b78eef78ceb0e01bb152ca51 /chrome/browser/safe_browsing/safe_browsing_service.h | |
parent | 9eda5b7490cb3463435287b003058d6d486a83b3 (diff) | |
download | chromium_src-90a3b24080e8432726dde4b4f72821e49416180e.zip chromium_src-90a3b24080e8432726dde4b4f72821e49416180e.tar.gz chromium_src-90a3b24080e8432726dde4b4f72821e49416180e.tar.bz2 |
Minor cleanup to safe_browsing_service.*; no code change.
* Eliminate header files that aren't needed
* Eliminate function declarations that are never defined
* Reorder header slightly for Google C++ Style Guide compliance and to make more functions private
* Move above-function comments like "Called on IO thread" from definitions to declarations for added visibility
* Reorder function definitions to match declaration order
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/391039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31863 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/safe_browsing_service.h')
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.h | 155 |
1 files changed, 80 insertions, 75 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h index 09d5792..bd466f6 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.h +++ b/chrome/browser/safe_browsing/safe_browsing_service.h @@ -15,8 +15,6 @@ #include "base/hash_tables.h" #include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "base/thread.h" #include "base/time.h" #include "chrome/browser/safe_browsing/safe_browsing_util.h" #include "googleurl/src/gurl.h" @@ -29,6 +27,10 @@ class SafeBrowsingDatabase; class SafeBrowsingProtocolManager; class URLRequestContextGetter; +namespace base { +class Thread; +} + // Construction needs to happen on the main thread. class SafeBrowsingService : public base::RefCountedThreadSafe<SafeBrowsingService> { @@ -64,40 +66,40 @@ class SafeBrowsingService int render_view_id; }; + // Bundle of SafeBrowsing state for one URL check. + struct SafeBrowsingCheck { + GURL url; + Client* client; + bool need_get_hash; + base::Time start; // Time that check was sent to SB service. + UrlCheckResult result; + std::vector<SBPrefix> prefix_hits; + std::vector<SBFullHashResult> full_hits; + }; + // Creates the safe browsing service. Need to initialize before using. SafeBrowsingService(); - // Initializes the service. + // Called on the UI thread to initialize the service. void Initialize(); - // Called to initialize objects that are used on the io_thread. - void OnIOInitialize(const std::string& client_key, - const std::string& wrapped_key, - URLRequestContextGetter* request_context_getter); - - // Called to initialize objects that are used on the db_thread. - void OnDBInitialize(); - - // Called to shutdown operations on the io_thread. - void OnIOShutdown(); - // Called on the main thread to let us know that the io_thread is going away. void ShutDown(); - // Called on the IO thread. - // Returns true if the url's scheme can be checked. bool CanCheckUrl(const GURL& url) const; - // Checks if the given url is safe or not. If we can synchronously determine - // that the url is safe, CheckUrl returns true. Otherwise it returns false, - // and "client" is called asynchronously with the result when it is ready. + // Called on the IO thread to check if the given url is safe or not. If we + // can synchronously determine that the url is safe, CheckUrl returns true. + // Otherwise it returns false, and "client" is called asynchronously with the + // result when it is ready. bool CheckUrl(const GURL& url, Client* client); - // Cancels a pending check if the result is no longer needed. + // Called on the IO thread to cancel a pending check if the result is no + // longer needed. void CancelCheck(Client* client); - // Displays an interstitial page. + // Called on the IO thread to display an interstitial page. void DisplayBlockingPage(const GURL& url, ResourceType::Type resource_type, UrlCheckResult result, @@ -105,27 +107,18 @@ class SafeBrowsingService int render_process_host_id, int render_view_id); - // Bundle of SafeBrowsing state for one URL check. - struct SafeBrowsingCheck { - GURL url; - Client* client; - bool need_get_hash; - base::Time start; // Time that check was sent to SB service. - UrlCheckResult result; - std::vector<SBPrefix> prefix_hits; - std::vector<SBFullHashResult> full_hits; - }; - - // API used by the SafeBrowsingProtocolManager to interface with the - // SafeBrowsing storage system. + // Called on the IO thread when the SafeBrowsingProtocolManager has received + // the full hash results for prefix hits detected in the database. void HandleGetHashResults( SafeBrowsingCheck* check, const std::vector<SBFullHashResult>& full_hashes, bool can_cache); + + // Called on the IO thread. void HandleChunk(const std::string& list, std::deque<SBChunk>* chunks); void HandleChunkDelete(std::vector<SBChunkDelete>* chunk_deletes); - // Update management. + // Update management. Called on the IO thread. void UpdateStarted(); void UpdateFinished(bool update_succeeded); @@ -133,25 +126,20 @@ class SafeBrowsingService void OnBlockingPageDone(const std::vector<UnsafeResource>& resources, bool proceed); - // Called when the SafeBrowsingProtocolManager has received updated MAC keys. + // Called on the UI thread when the SafeBrowsingProtocolManager has received + // updated MAC keys. void OnNewMacKeys(const std::string& client_key, const std::string& wrapped_key); - // Notification from the advanced options UI. + // Notification on the UI thread from the advanced options UI. void OnEnable(bool enabled); - bool enabled() const { return enabled_; } - - // Called by the database (on the db thread) when a chunk insertion is - // complete. - void ChunkInserted(); - // Notification from the database when it's done loading its bloom filter. - void DatabaseLoadComplete(); + bool enabled() const { return enabled_; } // Preference handling. static void RegisterPrefs(PrefService* prefs); - // The SafeBrowsing system has instructed us to reset our database. + // Called on the IO thread to reset the database. void ResetDatabase(); // Log the user perceived delay caused by SafeBrowsing. This delay is the time @@ -160,41 +148,69 @@ class SafeBrowsingService // the current page is 'safe'. void LogPauseDelay(base::TimeDelta time); - // Report any pages that contain malware sub-resources to the SafeBrowsing - // service. - void ReportMalware(const GURL& malware_url, - const GURL& page_url, - const GURL& referrer_url); - private: + typedef std::set<SafeBrowsingCheck*> CurrentChecks; + typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; + typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; + + // Used for whitelisting a render view when the user ignores our warning. + struct WhiteListedEntry { + int render_process_host_id; + int render_view_id; + std::string domain; + UrlCheckResult result; + }; + + // Clients that we've queued up for checking later once the database is ready. + struct QueuedCheck { + Client* client; + GURL url; + base::Time start; + }; + friend class base::RefCountedThreadSafe<SafeBrowsingService>; ~SafeBrowsingService(); + // Called to initialize objects that are used on the io_thread. + void OnIOInitialize(const std::string& client_key, + const std::string& wrapped_key, + URLRequestContextGetter* request_context_getter); + + // Called to initialize objects that are used on the db_thread. + void OnDBInitialize(); + + // Called to shutdown operations on the io_thread. + void OnIOShutdown(); + // Should only be called on db thread as SafeBrowsingDatabase is not // threadsafe. SafeBrowsingDatabase* GetDatabase(); - // Release the final reference to the database on the db thread. - void ReleaseDatabase(SafeBrowsingDatabase* database); - // Called on the IO thread with the check result. void OnCheckDone(SafeBrowsingCheck* info); // Called on the database thread to retrieve chunks. void GetAllChunksFromDatabase(); - // Called on the IOthread with the results of all chunks. + // Called on the IO thread with the results of all chunks. void OnGetAllChunksFromDatabase(const std::vector<SBListChunkRanges>& lists, bool database_error); + // Called on the db thread when a chunk insertion is complete. + void ChunkInserted(); + // Called on the IO thread after the database reports that it added a chunk. void OnChunkInserted(); + // Notification that the database is done loading its bloom filter. + void DatabaseLoadComplete(); + // Called on the database thread to add/remove chunks and host keys. // Callee will free the data when it's done. void HandleChunkForDatabase(const std::string& list, std::deque<SBChunk>* chunks); + void DeleteChunks(std::vector<SBChunkDelete>* chunk_deletes); static UrlCheckResult GetResultFromListname(const std::string& list_name); @@ -203,8 +219,10 @@ class SafeBrowsingService void DatabaseUpdateFinished(bool update_succeeded); + // Start up SafeBrowsing objects. This can be called at browser start, or when + // the user checks the "Enable SafeBrowsing" option in the Advanced options + // UI. void Start(); - void Stop(); // Runs on the db thread to reset the database. We assume that resetting the // database is a synchronous operation. @@ -227,19 +245,20 @@ class SafeBrowsingService // Invoked on the UI thread to show the blocking page. void DoDisplayBlockingPage(const UnsafeResource& resource); + // Report any pages that contain malware sub-resources to the SafeBrowsing + // service. + void ReportMalware(const GURL& malware_url, + const GURL& page_url, + const GURL& referrer_url); + // During a reset or the initial load we may have to queue checks until the // database is ready. This method is run once the database has loaded (or if // we shut down SafeBrowsing before the database has finished loading). void RunQueuedClients(); - void OnUpdateComplete(bool update_succeeded); - - typedef std::set<SafeBrowsingCheck*> CurrentChecks; CurrentChecks checks_; // Used for issuing only one GetHash request for a given prefix. - typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; - typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; GetHashRequests gethash_requests_; // The sqlite database. We don't use a scoped_ptr because it needs to be @@ -249,14 +268,6 @@ class SafeBrowsingService // Handles interaction with SafeBrowsing servers. SafeBrowsingProtocolManager* protocol_manager_; - // Used for whitelisting a render view when the user ignores our warning. - struct WhiteListedEntry { - int render_process_host_id; - int render_view_id; - std::string domain; - UrlCheckResult result; - }; - std::vector<WhiteListedEntry> white_listed_entries_; // Whether the service is running. 'enabled_' is used by SafeBrowsingService @@ -275,12 +286,6 @@ class SafeBrowsingService // Indicates if we're currently in an update cycle. bool update_in_progress_; - // Clients that we've queued up for checking later once the database is ready. - typedef struct { - Client* client; - GURL url; - base::Time start; - } QueuedCheck; std::deque<QueuedCheck> queued_checks_; DISALLOW_COPY_AND_ASSIGN(SafeBrowsingService); |