| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // Safe Browsing Database Manager implementation that manages a local | 5 // Safe Browsing Database Manager implementation that manages a local |
| 6 // database. This is used by Desktop Chromium. | 6 // database. This is used by Desktop Chromium. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/containers/hash_tables.h" | 18 #include "base/containers/hash_tables.h" |
| 19 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
| 23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "chrome/browser/safe_browsing/database_manager.h" | 25 #include "chrome/browser/safe_browsing/database_manager.h" |
| 26 #include "chrome/browser/safe_browsing/protocol_manager.h" | 26 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 27 #include "components/safe_browsing_db/util.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 class SafeBrowsingService; | 30 class SafeBrowsingService; |
| 31 class SafeBrowsingDatabase; | 31 class SafeBrowsingDatabase; |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 class URLRequestContext; | 34 class URLRequestContext; |
| 35 class URLRequestContextGetter; | 35 class URLRequestContextGetter; |
| 36 } | 36 } |
| 37 | 37 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 // Bundle of SafeBrowsing state while performing a URL or hash prefix check. | 50 // Bundle of SafeBrowsing state while performing a URL or hash prefix check. |
| 51 struct SafeBrowsingCheck { | 51 struct SafeBrowsingCheck { |
| 52 // |check_type| should correspond to the type of item that is being | 52 // |check_type| should correspond to the type of item that is being |
| 53 // checked, either a URL or a binary hash/URL. We store this for two | 53 // checked, either a URL or a binary hash/URL. We store this for two |
| 54 // purposes: to know which of Client's methods to call when a result is | 54 // purposes: to know which of Client's methods to call when a result is |
| 55 // known, and for logging purposes. It *isn't* used to predict the response | 55 // known, and for logging purposes. It *isn't* used to predict the response |
| 56 // list type, that is information that the server gives us. | 56 // list type, that is information that the server gives us. |
| 57 SafeBrowsingCheck(const std::vector<GURL>& urls, | 57 SafeBrowsingCheck(const std::vector<GURL>& urls, |
| 58 const std::vector<SBFullHash>& full_hashes, | 58 const std::vector<SBFullHash>& full_hashes, |
| 59 Client* client, | 59 Client* client, |
| 60 safe_browsing::ListType check_type, | 60 safe_browsing_util::ListType check_type, |
| 61 const std::vector<SBThreatType>& expected_threats); | 61 const std::vector<SBThreatType>& expected_threats); |
| 62 ~SafeBrowsingCheck(); | 62 ~SafeBrowsingCheck(); |
| 63 | 63 |
| 64 // Either |urls| or |full_hashes| is used to lookup database. |*_results| | 64 // Either |urls| or |full_hashes| is used to lookup database. |*_results| |
| 65 // are parallel vectors containing the results. They are initialized to | 65 // are parallel vectors containing the results. They are initialized to |
| 66 // contain SB_THREAT_TYPE_SAFE. | 66 // contain SB_THREAT_TYPE_SAFE. |
| 67 std::vector<GURL> urls; | 67 std::vector<GURL> urls; |
| 68 std::vector<SBThreatType> url_results; | 68 std::vector<SBThreatType> url_results; |
| 69 std::vector<std::string> url_metadata; | 69 std::vector<std::string> url_metadata; |
| 70 std::vector<SBFullHash> full_hashes; | 70 std::vector<SBFullHash> full_hashes; |
| 71 std::vector<SBThreatType> full_hash_results; | 71 std::vector<SBThreatType> full_hash_results; |
| 72 | 72 |
| 73 SafeBrowsingDatabaseManager::Client* client; | 73 SafeBrowsingDatabaseManager::Client* client; |
| 74 bool is_extended_reporting; | 74 bool is_extended_reporting; |
| 75 bool need_get_hash; | 75 bool need_get_hash; |
| 76 base::TimeTicks start; // When check was sent to SB service. | 76 base::TimeTicks start; // When check was sent to SB service. |
| 77 safe_browsing::ListType check_type; // See comment in constructor. | 77 safe_browsing_util::ListType check_type; // See comment in constructor. |
| 78 std::vector<SBThreatType> expected_threats; | 78 std::vector<SBThreatType> expected_threats; |
| 79 std::vector<SBPrefix> prefix_hits; | 79 std::vector<SBPrefix> prefix_hits; |
| 80 std::vector<SBFullHashResult> cache_hits; | 80 std::vector<SBFullHashResult> cache_hits; |
| 81 | 81 |
| 82 // Invoke one of client's callbacks with these results. | 82 // Invoke one of client's callbacks with these results. |
| 83 void OnSafeBrowsingResult(); | 83 void OnSafeBrowsingResult(); |
| 84 | 84 |
| 85 // Vends weak pointers for async callbacks on the IO thread, such as | 85 // Vends weak pointers for async callbacks on the IO thread, such as |
| 86 // timeout checks and replies from checks performed on the SB task runner. | 86 // timeout checks and replies from checks performed on the SB task runner. |
| 87 // TODO(lzheng): We should consider to use this time out check | 87 // TODO(lzheng): We should consider to use this time out check |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 GetUrlSeverestThreatType); | 147 GetUrlSeverestThreatType); |
| 148 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 148 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 149 ServiceStopWithPendingChecks); | 149 ServiceStopWithPendingChecks); |
| 150 | 150 |
| 151 typedef std::set<SafeBrowsingCheck*> CurrentChecks; | 151 typedef std::set<SafeBrowsingCheck*> CurrentChecks; |
| 152 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; | 152 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; |
| 153 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; | 153 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; |
| 154 | 154 |
| 155 // Clients that we've queued up for checking later once the database is ready. | 155 // Clients that we've queued up for checking later once the database is ready. |
| 156 struct QueuedCheck { | 156 struct QueuedCheck { |
| 157 QueuedCheck(const safe_browsing::ListType check_type, | 157 QueuedCheck(const safe_browsing_util::ListType check_type, |
| 158 Client* client, | 158 Client* client, |
| 159 const GURL& url, | 159 const GURL& url, |
| 160 const std::vector<SBThreatType>& expected_threats, | 160 const std::vector<SBThreatType>& expected_threats, |
| 161 const base::TimeTicks& start); | 161 const base::TimeTicks& start); |
| 162 ~QueuedCheck(); | 162 ~QueuedCheck(); |
| 163 safe_browsing::ListType check_type; | 163 safe_browsing_util::ListType check_type; |
| 164 Client* client; | 164 Client* client; |
| 165 GURL url; | 165 GURL url; |
| 166 std::vector<SBThreatType> expected_threats; | 166 std::vector<SBThreatType> expected_threats; |
| 167 base::TimeTicks start; // When check was queued. | 167 base::TimeTicks start; // When check was queued. |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 // Return the threat type of the severest entry in |full_hashes| which matches | 170 // Return the threat type of the severest entry in |full_hashes| which matches |
| 171 // |hash|, or SAFE if none match. | 171 // |hash|, or SAFE if none match. |
| 172 static SBThreatType GetHashSeverestThreatType( | 172 static SBThreatType GetHashSeverestThreatType( |
| 173 const SBFullHash& hash, | 173 const SBFullHash& hash, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 std::deque<QueuedCheck> queued_checks_; | 357 std::deque<QueuedCheck> queued_checks_; |
| 358 | 358 |
| 359 // Timeout to use for safe browsing checks. | 359 // Timeout to use for safe browsing checks. |
| 360 base::TimeDelta check_timeout_; | 360 base::TimeDelta check_timeout_; |
| 361 | 361 |
| 362 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager); | 362 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager); |
| 363 }; // class LocalSafeBrowsingDatabaseManager | 363 }; // class LocalSafeBrowsingDatabaseManager |
| 364 | 364 |
| 365 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ | 365 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |