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 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
7 | 7 |
8 // A class that implements Chrome's interface with the SafeBrowsing protocol. | 8 // A class that implements Chrome's interface with the SafeBrowsing protocol. |
9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for | 9 // See https://developers.google.com/safe-browsing/developers_guide_v2 for |
10 // protocol details. | 10 // protocol details. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 // synchronously. | 81 // synchronously. |
82 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes, | 82 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes, |
83 FullHashCallback callback, | 83 FullHashCallback callback, |
84 bool is_download, | 84 bool is_download, |
85 bool is_extended_reporting); | 85 bool is_extended_reporting); |
86 | 86 |
87 // Retrieve the full hash for a set of prefixes, and invoke the callback | 87 // Retrieve the full hash for a set of prefixes, and invoke the callback |
88 // argument when the results are retrieved. The callback may be invoked | 88 // argument when the results are retrieved. The callback may be invoked |
89 // synchronously. Uses the V4 Safe Browsing protocol. | 89 // synchronously. Uses the V4 Safe Browsing protocol. |
90 virtual void GetV4FullHashes(const std::vector<SBPrefix>& prefixes, | 90 virtual void GetV4FullHashes(const std::vector<SBPrefix>& prefixes, |
91 const std::vector<PlatformType>& platforms, | |
91 ThreatType threat_type, | 92 ThreatType threat_type, |
awoz
2016/01/05 17:20:10
How about a vector of threat types as well? That w
| |
92 FullHashCallback callback); | 93 FullHashCallback callback); |
93 | 94 |
94 // Retrieve the full hash and API metadata for a set of prefixes, and invoke | 95 // Retrieve the full hash and API metadata for a set of prefixes, and invoke |
95 // the callback argument when the results are retrieved. The callback may be | 96 // the callback argument when the results are retrieved. The callback may be |
96 // invoked synchronously. Uses the V4 Safe Browsing protocol. | 97 // invoked synchronously. Uses the V4 Safe Browsing protocol. |
97 virtual void GetFullHashesWithApis(const std::vector<SBPrefix>& prefixes, | 98 virtual void GetFullHashesWithApis(const std::vector<SBPrefix>& prefixes, |
98 FullHashCallback callback); | 99 FullHashCallback callback); |
99 | 100 |
100 // Forces the start of next update after |interval| time. | 101 // Forces the start of next update after |interval| time. |
101 void ForceScheduleNextUpdate(base::TimeDelta interval); | 102 void ForceScheduleNextUpdate(base::TimeDelta interval); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 197 |
197 private: | 198 private: |
198 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); | 199 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); |
199 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); | 200 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); |
200 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); | 201 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); |
201 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 202 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
202 TestGetV4HashUrl); | 203 TestGetV4HashUrl); |
203 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 204 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
204 TestGetV4HashRequest); | 205 TestGetV4HashRequest); |
205 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | 206 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, |
207 TestParseV4HashResponse); | |
208 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | |
209 TestParseV4HashResponseWrongThreatEntryType); | |
210 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | |
211 TestParseV4HashResponseSocialEngineeringThreatType); | |
212 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | |
213 TestParseV4HashResponseNonPermissionMetadata); | |
214 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, | |
206 TestGetHashBackOffTimes); | 215 TestGetHashBackOffTimes); |
207 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); | 216 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); |
208 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); | 217 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); |
209 friend class SafeBrowsingServerTest; | 218 friend class SafeBrowsingServerTest; |
210 friend class SBProtocolManagerFactoryImpl; | 219 friend class SBProtocolManagerFactoryImpl; |
211 | 220 |
212 // Internal API for fetching information from the SafeBrowsing servers. The | 221 // Internal API for fetching information from the SafeBrowsing servers. The |
213 // GetHash requests are higher priority since they can block user requests | 222 // GetHash requests are higher priority since they can block user requests |
214 // so are handled separately. | 223 // so are handled separately. |
215 enum SafeBrowsingRequestType { | 224 enum SafeBrowsingRequestType { |
(...skipping 20 matching lines...) Expand all Loading... | |
236 | 245 |
237 // Generates GetHash request URL for retrieving full hashes. | 246 // Generates GetHash request URL for retrieving full hashes. |
238 GURL GetHashUrl(bool is_extended_reporting) const; | 247 GURL GetHashUrl(bool is_extended_reporting) const; |
239 // Generates URL for reporting safe browsing hits for UMA users. | 248 // Generates URL for reporting safe browsing hits for UMA users. |
240 | 249 |
241 // Generates GetHashWithApis Pver4 request URL for retrieving full hashes. | 250 // Generates GetHashWithApis Pver4 request URL for retrieving full hashes. |
242 // |request_base64| is the serialized FindFullHashesRequest protocol buffer | 251 // |request_base64| is the serialized FindFullHashesRequest protocol buffer |
243 // encoded in base 64. | 252 // encoded in base 64. |
244 GURL GetV4HashUrl(const std::string& request_base64) const; | 253 GURL GetV4HashUrl(const std::string& request_base64) const; |
245 | 254 |
246 // Fills a FindFullHashesRequest protocol buffer for an API_ABUSE request. | 255 // Fills a FindFullHashesRequest protocol buffer for a V4 request. |
247 // Returns the serialized and base 64 encoded request as a string. | 256 // Returns the serialized and base 64 encoded request as a string. |
248 std::string GetV4HashRequest(const std::vector<SBPrefix>& prefixes, | 257 std::string GetV4HashRequest(const std::vector<SBPrefix>& prefixes, |
258 const std::vector<PlatformType>& platforms, | |
249 ThreatType threat_type); | 259 ThreatType threat_type); |
250 | 260 |
261 // Parses a FindFullHashesResponse protocol buffer and fills the results in | |
262 // |full_hashes| and |negative_cache_duration|. |data| is a serialized | |
263 // FindFullHashes protocol buffer. |negative_cache_duration| is the duration | |
264 // to cache the response for entities that did not match the threat list. | |
265 // Returns true if parsing is successful, false otherwise. | |
266 bool ParseV4HashResponse(const std::string& data_base64, | |
267 std::vector<SBFullHashResult>* full_hashes, | |
268 base::TimeDelta* negative_cache_duration); | |
269 | |
251 // Composes a ChunkUrl based on input string. | 270 // Composes a ChunkUrl based on input string. |
252 GURL NextChunkUrl(const std::string& input) const; | 271 GURL NextChunkUrl(const std::string& input) const; |
253 | 272 |
254 // Returns the time for the next update request. If |back_off| is true, | 273 // Returns the time for the next update request. If |back_off| is true, |
255 // the time returned will increment an error count and return the appriate | 274 // the time returned will increment an error count and return the appriate |
256 // next time (see ScheduleNextUpdate below). | 275 // next time (see ScheduleNextUpdate below). |
257 base::TimeDelta GetNextUpdateInterval(bool back_off); | 276 base::TimeDelta GetNextUpdateInterval(bool back_off); |
258 | 277 |
259 // Worker function for calculating GetHash and Update backoff times (in | 278 // Worker function for calculating GetHash and Update backoff times (in |
260 // seconds). |multiplier| is doubled for each consecutive error between the | 279 // seconds). |multiplier| is doubled for each consecutive error between the |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 AddChunksCallback callback) = 0; | 486 AddChunksCallback callback) = 0; |
468 | 487 |
469 // Delete chunks from the database. | 488 // Delete chunks from the database. |
470 virtual void DeleteChunks( | 489 virtual void DeleteChunks( |
471 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; | 490 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) = 0; |
472 }; | 491 }; |
473 | 492 |
474 } // namespace safe_browsing | 493 } // namespace safe_browsing |
475 | 494 |
476 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 495 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
OLD | NEW |