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