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

Unified Diff: chrome/browser/safe_browsing/local_database_manager.h

Issue 1110723002: Split to SafeBrowsingDatabaseManager into Local* and Remote*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to review. Tweak comments and list initializer. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/local_database_manager.h
diff --git a/chrome/browser/safe_browsing/database_manager.h b/chrome/browser/safe_browsing/local_database_manager.h
similarity index 69%
copy from chrome/browser/safe_browsing/database_manager.h
copy to chrome/browser/safe_browsing/local_database_manager.h
index 3b0984d7ba9c0d07069ea23ec4caa8db8d4ff236..b55c98ce2c8bd12dd468493bb54750c04b71046b 100644
--- a/chrome/browser/safe_browsing/database_manager.h
+++ b/chrome/browser/safe_browsing/local_database_manager.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
-// The Safe Browsing service is responsible for downloading anti-phishing and
-// anti-malware tables and checking urls against them.
+// Safe Browsing Database Manager implementation that manages a local
+// database. This is used by Desktop Chromium.
-#ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
-#define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
+#ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_
+#define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_
#include <deque>
#include <map>
@@ -18,8 +18,10 @@
#include "base/containers/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
+#include "chrome/browser/safe_browsing/database_manager.h"
#include "chrome/browser/safe_browsing/protocol_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_util.h"
#include "url/gurl.h"
@@ -37,13 +39,13 @@ class ClientSideDetectionService;
class DownloadProtectionService;
}
+// Implemetation that manages a local database on disk.
+//
// Construction needs to happen on the main thread.
-class SafeBrowsingDatabaseManager
- : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>,
+class LocalSafeBrowsingDatabaseManager
+ : public SafeBrowsingDatabaseManager,
public SafeBrowsingProtocolManagerDelegate {
public:
- class Client;
-
// Bundle of SafeBrowsing state while performing a URL or hash prefix check.
struct SafeBrowsingCheck {
// |check_type| should correspond to the type of item that is being
@@ -67,7 +69,7 @@ class SafeBrowsingDatabaseManager
std::vector<SBFullHash> full_hashes;
std::vector<SBThreatType> full_hash_results;
- Client* client;
+ SafeBrowsingDatabaseManager::Client* client;
bool need_get_hash;
base::TimeTicks start; // When check was sent to SB service.
safe_browsing_util::ListType check_type; // See comment in constructor.
@@ -75,133 +77,66 @@ class SafeBrowsingDatabaseManager
std::vector<SBPrefix> prefix_hits;
std::vector<SBFullHashResult> cache_hits;
+ // Invoke one of client's callbacks with these results.
+ void OnSafeBrowsingResult();
+
// Vends weak pointers for async callbacks on the IO thread, such as
// timeout checks and replies from checks performed on the SB task runner.
// TODO(lzheng): We should consider to use this time out check
// for browsing too (instead of implementing in
// safe_browsing_resource_handler.cc).
- scoped_ptr<base::WeakPtrFactory<
- SafeBrowsingDatabaseManager> > weak_ptr_factory_;
+ scoped_ptr<base::WeakPtrFactory<LocalSafeBrowsingDatabaseManager>>
+ weak_ptr_factory_;
private:
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingCheck);
};
- class Client {
- public:
- void OnSafeBrowsingResult(const SafeBrowsingCheck& check);
-
- protected:
- virtual ~Client() {}
-
- // Called when the result of checking a browse URL is known.
- virtual void OnCheckBrowseUrlResult(const GURL& url,
- SBThreatType threat_type,
- const std::string& metadata) {}
-
- // Called when the result of checking a download URL is known.
- virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain,
- SBThreatType threat_type) {}
-
- // Called when the result of checking a set of extensions is known.
- virtual void OnCheckExtensionsResult(
- const std::set<std::string>& threats) {}
- };
-
// Creates the safe browsing service. Need to initialize before using.
- explicit SafeBrowsingDatabaseManager(
+ explicit LocalSafeBrowsingDatabaseManager(
const scoped_refptr<SafeBrowsingService>& service);
- // Returns true if the url's scheme can be checked.
- bool CanCheckUrl(const GURL& url) const;
-
- // Returns whether download protection is enabled.
- bool download_protection_enabled() const {
- return enable_download_protection_;
- }
-
- // 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.
- virtual bool CheckBrowseUrl(const GURL& url, Client* client);
-
- // Check if the prefix for |url| is in safebrowsing download add lists.
- // Result will be passed to callback in |client|.
- virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
- Client* client);
-
- // Check which prefixes in |extension_ids| are in the safebrowsing blacklist.
- // Returns true if not, false if further checks need to be made in which case
- // the result will be passed to |client|.
- virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
- Client* client);
-
- // Check if the |url| matches any of the full-length hashes from the client-
- // side phishing detection whitelist. Returns true if there was a match and
- // false otherwise. To make sure we are conservative we will return true if
- // an error occurs. This method must be called on the IO thread.
- virtual bool MatchCsdWhitelistUrl(const GURL& url);
-
- // Check if the given IP address (either IPv4 or IPv6) matches the malware
- // IP blacklist.
- virtual bool MatchMalwareIP(const std::string& ip_address);
-
- // Check if the |url| matches any of the full-length hashes from the download
- // whitelist. Returns true if there was a match and false otherwise. To make
- // sure we are conservative we will return true if an error occurs. This
- // method must be called on the IO thread.
- virtual bool MatchDownloadWhitelistUrl(const GURL& url);
-
- // Check if |str| matches any of the full-length hashes from the download
- // whitelist. Returns true if there was a match and false otherwise. To make
- // sure we are conservative we will return true if an error occurs. This
- // method must be called on the IO thread.
- virtual bool MatchDownloadWhitelistString(const std::string& str);
-
- // Check if the |url| matches any of the full-length hashes from the off-
- // domain inclusion whitelist. Returns true if there was a match and false
- // otherwise. To make sure we are conservative, we will return true if an
- // error occurs. This method must be called on the IO thread.
- virtual bool MatchInclusionWhitelistUrl(const GURL& url);
-
- // Check if the CSD malware IP matching kill switch is turned on.
- virtual bool IsMalwareKillSwitchOn();
-
- // Check if the CSD whitelist kill switch is turned on.
- virtual bool IsCsdWhitelistKillSwitchOn();
-
- // Called on the IO thread to cancel a pending check if the result is no
- // longer needed.
- void CancelCheck(Client* client);
-
- // 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,
- const base::TimeDelta& cache_lifetime);
-
- // Called to initialize objects that are used on the io_thread. This may be
- // called multiple times during the life of the DatabaseManager. Must be
- // called on IO thread.
- void StartOnIOThread();
+ //
+ // SafeBrowsingDatabaseManager overrides
+ //
- // Called to stop or shutdown operations on the io_thread. This may be called
- // multiple times during the life of the DatabaseManager. Must be called
- // on IO thread. If shutdown is true, the manager is disabled permanently.
- void StopOnIOThread(bool shutdown);
+ bool CanCheckUrl(const GURL& url) const override;
+
+ bool CheckBrowseUrl(const GURL& url, Client* client) override;
+ bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
+ Client* client) override;
+ bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
+ Client* client) override;
+ bool MatchCsdWhitelistUrl(const GURL& url) override;
+ bool MatchMalwareIP(const std::string& ip_address) override;
+ bool MatchDownloadWhitelistUrl(const GURL& url) override;
+ bool MatchDownloadWhitelistString(const std::string& str) override;
+ bool MatchInclusionWhitelistUrl(const GURL& url) override;
+ bool IsMalwareKillSwitchOn() override;
+ bool IsCsdWhitelistKillSwitchOn() override;
+ void CancelCheck(Client* client) override;
+ void StartOnIOThread() override;
+ void StopOnIOThread(bool shutdown) override;
+ bool download_protection_enabled() const override;
protected:
- ~SafeBrowsingDatabaseManager() override;
+ ~LocalSafeBrowsingDatabaseManager() override;
// protected for tests.
void NotifyDatabaseUpdateFinished(bool update_succeeded);
private:
- friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
+ // 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,
+ const base::TimeDelta& cache_lifetime);
+
+ friend class base::RefCountedThreadSafe<LocalSafeBrowsingDatabaseManager>;
friend class SafeBrowsingServerTest;
friend class SafeBrowsingServiceTest;
friend class SafeBrowsingServiceTestHelper;
+ // TODO(nparker): Rename this test to LocalSafeBrowsingDatabaseManagerTest
friend class SafeBrowsingDatabaseManagerTest;
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest,
GetUrlSeverestThreatType);
@@ -402,7 +337,7 @@ class SafeBrowsingDatabaseManager
// Timeout to use for safe browsing checks.
base::TimeDelta check_timeout_;
- DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager);
-};
+ DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager);
+}; // class LocalSafeBrowsingDatabaseManager
-#endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
+#endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698