No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / safe_browsing / database_manager.h
blob601d4f3c58064e2596fbafa641d27a43a773af56
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // The Safe Browsing service is responsible for downloading anti-phishing and
6 // anti-malware tables and checking urls against them.
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
11 #include <deque>
12 #include <map>
13 #include <set>
14 #include <string>
15 #include <vector>
17 #include "base/memory/ref_counted.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
19 #include "url/gurl.h"
21 // Interface to either the locally-managed or a remotely-managed database.
22 class SafeBrowsingDatabaseManager
23 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager> {
24 public:
25 // Callers requesting a result should derive from this class.
26 // The destructor should call db_manager->CancelCheck(client) if a
27 // request is still pending.
28 class Client {
29 public:
30 virtual ~Client() {}
32 // Called when the result of checking a browse URL is known.
33 virtual void OnCheckBrowseUrlResult(const GURL& url,
34 SBThreatType threat_type,
35 const std::string& metadata) {}
37 // Called when the result of checking a download URL is known.
38 virtual void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain,
39 SBThreatType threat_type) {}
41 // Called when the result of checking a set of extensions is known.
42 virtual void OnCheckExtensionsResult(
43 const std::set<std::string>& threats) {}
46 // Returns true if the url's scheme can be checked.
47 virtual bool CanCheckUrl(const GURL& url) const = 0;
49 // Returns whether download protection is enabled.
50 virtual bool download_protection_enabled() const = 0;
52 // Called on the IO thread to check if the given url is safe or not. If we
53 // can synchronously determine that the url is safe, CheckUrl returns true.
54 // Otherwise it returns false, and "client" is called asynchronously with the
55 // result when it is ready.
56 virtual bool CheckBrowseUrl(const GURL& url, Client* client) = 0;
58 // Check if the prefix for |url| is in safebrowsing download add lists.
59 // Result will be passed to callback in |client|.
60 virtual bool CheckDownloadUrl(const std::vector<GURL>& url_chain,
61 Client* client) = 0;
63 // Check which prefixes in |extension_ids| are in the safebrowsing blacklist.
64 // Returns true if not, false if further checks need to be made in which case
65 // the result will be passed to |client|.
66 virtual bool CheckExtensionIDs(const std::set<std::string>& extension_ids,
67 Client* client) = 0;
69 // Check if the |url| matches any of the full-length hashes from the client-
70 // side phishing detection whitelist. Returns true if there was a match and
71 // false otherwise. To make sure we are conservative we will return true if
72 // an error occurs. This method must be called on the IO thread.
73 virtual bool MatchCsdWhitelistUrl(const GURL& url) = 0;
75 // Check if the given IP address (either IPv4 or IPv6) matches the malware
76 // IP blacklist.
77 virtual bool MatchMalwareIP(const std::string& ip_address) = 0;
79 // Check if the |url| matches any of the full-length hashes from the download
80 // whitelist. Returns true if there was a match and false otherwise. To make
81 // sure we are conservative we will return true if an error occurs. This
82 // method must be called on the IO thread.
83 virtual bool MatchDownloadWhitelistUrl(const GURL& url) = 0;
85 // Check if |str| matches any of the full-length hashes from the download
86 // whitelist. Returns true if there was a match and false otherwise. To make
87 // sure we are conservative we will return true if an error occurs. This
88 // method must be called on the IO thread.
89 virtual bool MatchDownloadWhitelistString(const std::string& str) = 0;
91 // Check if the |url| matches any of the full-length hashes from the off-
92 // domain inclusion whitelist. Returns true if there was a match and false
93 // otherwise. To make sure we are conservative, we will return true if an
94 // error occurs. This method must be called on the IO thread.
95 virtual bool MatchInclusionWhitelistUrl(const GURL& url) = 0;
97 // Check if the CSD malware IP matching kill switch is turned on.
98 virtual bool IsMalwareKillSwitchOn() = 0;
100 // Check if the CSD whitelist kill switch is turned on.
101 virtual bool IsCsdWhitelistKillSwitchOn() = 0;
103 // Called on the IO thread to cancel a pending check if the result is no
104 // longer needed. Also called after the result has been handled.
105 virtual void CancelCheck(Client* client) = 0;
107 // Called to initialize objects that are used on the io_thread. This may be
108 // called multiple times during the life of the DatabaseManager. Must be
109 // called on IO thread.
110 virtual void StartOnIOThread() = 0;
112 // Called to stop or shutdown operations on the io_thread. This may be called
113 // multiple times during the life of the DatabaseManager. Must be called
114 // on IO thread. If shutdown is true, the manager is disabled permanently.
115 virtual void StopOnIOThread(bool shutdown) = 0;
117 protected:
118 virtual ~SafeBrowsingDatabaseManager() {}
120 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>;
121 }; // class SafeBrowsingDatabaseManager
123 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_