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