| 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 // 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 COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 8 #ifndef COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
| 9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 9 #define COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
| 10 | 10 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Called to stop or shutdown operations on the io_thread. | 173 // Called to stop or shutdown operations on the io_thread. |
| 174 virtual void StopOnIOThread(bool shutdown); | 174 virtual void StopOnIOThread(bool shutdown); |
| 175 | 175 |
| 176 protected: | 176 protected: |
| 177 // Bundled client info for an API abuse hash prefix check. | 177 // Bundled client info for an API abuse hash prefix check. |
| 178 class SafeBrowsingApiCheck { | 178 class SafeBrowsingApiCheck { |
| 179 public: | 179 public: |
| 180 SafeBrowsingApiCheck(const GURL& url, | 180 SafeBrowsingApiCheck(const GURL& url, |
| 181 const std::vector<SBPrefix>& prefixes, | 181 const std::vector<SBPrefix>& prefixes, |
| 182 const std::vector<SBFullHash>& full_hashes, | 182 const std::vector<SBFullHash>& full_hashes, |
| 183 const std::vector<SBFullHashResult>& cached_results, |
| 183 Client* client); | 184 Client* client); |
| 184 ~SafeBrowsingApiCheck(); | 185 ~SafeBrowsingApiCheck(); |
| 185 | 186 |
| 186 const GURL& url() {return url_;} | 187 const GURL& url() {return url_;} |
| 187 const std::vector<SBPrefix>& prefixes() {return prefixes_;} | 188 const std::vector<SBPrefix>& prefixes() {return prefixes_;} |
| 188 const std::vector<SBFullHash>& full_hashes() {return full_hashes_;} | 189 const std::vector<SBFullHash>& full_hashes() {return full_hashes_;} |
| 190 const std::vector<SBFullHashResult>& cached_results() { |
| 191 return cached_results_; |
| 192 } |
| 189 SafeBrowsingDatabaseManager::Client* client() {return client_;} | 193 SafeBrowsingDatabaseManager::Client* client() {return client_;} |
| 190 | 194 |
| 191 private: | 195 private: |
| 192 GURL url_; | 196 GURL url_; |
| 193 | 197 |
| 194 // Prefixes that were requested in this check. | 198 // Prefixes that were requested in this check. |
| 195 std::vector<SBPrefix> prefixes_; | 199 std::vector<SBPrefix> prefixes_; |
| 196 | 200 |
| 197 // Full hashes for this check. | 201 // Full hashes for this check. |
| 198 std::vector<SBFullHash> full_hashes_; | 202 std::vector<SBFullHash> full_hashes_; |
| 199 | 203 |
| 204 // Cached results for this check. |
| 205 std::vector<SBFullHashResult> cached_results_; |
| 206 |
| 200 // Not owned. | 207 // Not owned. |
| 201 SafeBrowsingDatabaseManager::Client* client_; | 208 SafeBrowsingDatabaseManager::Client* client_; |
| 202 | 209 |
| 203 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck); | 210 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingApiCheck); |
| 204 }; | 211 }; |
| 205 | 212 |
| 206 SafeBrowsingDatabaseManager(); | 213 SafeBrowsingDatabaseManager(); |
| 207 | 214 |
| 208 virtual ~SafeBrowsingDatabaseManager(); | 215 virtual ~SafeBrowsingDatabaseManager(); |
| 209 | 216 |
| 210 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; | 217 friend class base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>; |
| 211 | 218 |
| 212 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 219 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 213 CheckApiBlacklistUrlPrefixes); | 220 CheckApiBlacklistUrlPrefixes); |
| 214 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 221 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 215 HandleGetHashesWithApisResults); | 222 HandleGetHashesWithApisResults); |
| 216 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 223 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 217 HandleGetHashesWithApisResultsNoMatch); | 224 HandleGetHashesWithApisResultsNoMatch); |
| 218 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 225 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 219 HandleGetHashesWithApisResultsMatches); | 226 HandleGetHashesWithApisResultsMatches); |
| 220 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 227 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 221 CancelApiCheck); | 228 CancelApiCheck); |
| 222 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 229 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 223 ResultsAreCached); | 230 ResultsAreCached); |
| 224 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, | 231 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 225 ResultsAreNotCachedOnNull); | 232 ResultsAreNotCachedOnNull); |
| 233 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 234 GetCachedResults); |
| 235 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingDatabaseManagerTest, |
| 236 CachedResultsMerged); |
| 226 | 237 |
| 227 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet; | 238 typedef std::set<SafeBrowsingApiCheck*> ApiCheckSet; |
| 228 typedef std::map<SBPrefix, SBCachedFullHashResult> PrefixToFullHashResultsMap; | 239 typedef std::map<SBPrefix, SBCachedFullHashResult> PrefixToFullHashResultsMap; |
| 240 typedef std::map<SBThreatType, PrefixToFullHashResultsMap> |
| 241 ThreatTypeToResultsMap; |
| 229 | 242 |
| 230 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received | 243 // Called on the IO thread wheh the SafeBrowsingProtocolManager has received |
| 231 // the full hash and api results for prefixes of the |url| argument in | 244 // the full hash and api results for prefixes of the |url| argument in |
| 232 // CheckApiBlacklistUrl. | 245 // CheckApiBlacklistUrl. |
| 233 virtual void HandleGetHashesWithApisResults( | 246 virtual void HandleGetHashesWithApisResults( |
| 234 SafeBrowsingApiCheck* check, | 247 SafeBrowsingApiCheck* check, |
| 235 const std::vector<SBFullHashResult>& full_hash_results, | 248 const std::vector<SBFullHashResult>& full_hash_results, |
| 236 const base::Time& negative_cache_expire); | 249 const base::Time& negative_cache_expire); |
| 237 | 250 |
| 251 // Looks up the cached results for |threat_type|. Fills |prefixes| with the |
| 252 // prefixes that need a request. Fills |cached_results| with the cached |
| 253 // results. |
| 254 void GetFullHashCachedResults(const SBThreatType& threat_type, |
| 255 const std::vector<SBFullHash>& full_hashes, |
| 256 base::Time now, |
| 257 std::vector<SBPrefix>* prefixes, |
| 258 std::vector<SBFullHashResult>* cached_results); |
| 259 |
| 260 // Populates |md| with permission api metadata from all results that have a |
| 261 // match in |full_hashes|. |
| 262 void PopulateApiMetadataResult(const std::vector<SBFullHashResult>& results, |
| 263 const std::vector<SBFullHash>& full_hashes, |
| 264 ThreatMetadata* md); |
| 265 |
| 238 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is | 266 // In-progress checks. This set owns the SafeBrowsingApiCheck pointers and is |
| 239 // responsible for deleting them when removing from the set. | 267 // responsible for deleting them when removing from the set. |
| 240 ApiCheckSet api_checks_; | 268 ApiCheckSet api_checks_; |
| 241 | 269 |
| 242 // A cache of V4 full hash results for api checks. | 270 // A cache of V4 full hash results for api checks. |
| 243 PrefixToFullHashResultsMap api_cache_; | 271 // TODO(kcarattini): Look into moving all caching logic to |
| 272 // V4GetHashProtocolManager. |
| 273 ThreatTypeToResultsMap v4_full_hash_cache_; |
| 244 | 274 |
| 245 // Created and destroyed via StartOnIOThread/StopOnIOThread. | 275 // Created and destroyed via StartOnIOThread/StopOnIOThread. |
| 246 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; | 276 V4GetHashProtocolManager* v4_get_hash_protocol_manager_; |
| 247 | 277 |
| 248 private: | 278 private: |
| 249 // Returns an iterator to the pending API check with the given |client|. | 279 // Returns an iterator to the pending API check with the given |client|. |
| 250 ApiCheckSet::iterator FindClientApiCheck(Client* client); | 280 ApiCheckSet::iterator FindClientApiCheck(Client* client); |
| 251 }; // class SafeBrowsingDatabaseManager | 281 }; // class SafeBrowsingDatabaseManager |
| 252 | 282 |
| 253 } // namespace safe_browsing | 283 } // namespace safe_browsing |
| 254 | 284 |
| 255 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ | 285 #endif // COMPONENTS_SAFE_BROWSING_DB_DATABASE_MANAGER_H_ |
| OLD | NEW |