| 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 // The SafeBrowsingProtocolManager handles formatting and making requests of, | 9 // The SafeBrowsingProtocolManager handles formatting and making requests of, |
| 10 // and handling responses from, Google's SafeBrowsing servers. This class uses | 10 // and handling responses from, Google's SafeBrowsing servers. This class uses |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 virtual void Initialize(); | 82 virtual void Initialize(); |
| 83 | 83 |
| 84 // net::URLFetcherDelegate interface. | 84 // net::URLFetcherDelegate interface. |
| 85 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 85 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 86 | 86 |
| 87 // API used by the SafeBrowsingService for issuing queries. When the results | 87 // API used by the SafeBrowsingService for issuing queries. When the results |
| 88 // are available, SafeBrowsingService::HandleGetHashResults is called. | 88 // are available, SafeBrowsingService::HandleGetHashResults is called. |
| 89 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, | 89 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, |
| 90 const std::vector<SBPrefix>& prefixes); | 90 const std::vector<SBPrefix>& prefixes); |
| 91 | 91 |
| 92 // Forces the start of next update after |next_update_msec| in msec. | 92 // Forces the start of next update after |interval| time. |
| 93 void ForceScheduleNextUpdate(int next_update_msec); | 93 void ForceScheduleNextUpdate(base::TimeDelta interval); |
| 94 | 94 |
| 95 // Scheduled update callback. | 95 // Scheduled update callback. |
| 96 void GetNextUpdate(); | 96 void GetNextUpdate(); |
| 97 | 97 |
| 98 // Called by the SafeBrowsingService when our request for a list of all chunks | 98 // Called by the SafeBrowsingService when our request for a list of all chunks |
| 99 // for each list is done. If database_error is true, that means the protocol | 99 // for each list is done. If database_error is true, that means the protocol |
| 100 // manager shouldn't fetch updates since they can't be written to disk. It | 100 // manager shouldn't fetch updates since they can't be written to disk. It |
| 101 // should try again later to open the database. | 101 // should try again later to open the database. |
| 102 void OnGetChunksComplete(const std::vector<SBListChunkRanges>& list, | 102 void OnGetChunksComplete(const std::vector<SBListChunkRanges>& list, |
| 103 bool database_error); | 103 bool database_error); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 GURL SafeBrowsingHitUrl( | 219 GURL SafeBrowsingHitUrl( |
| 220 const GURL& malicious_url, const GURL& page_url, const GURL& referrer_url, | 220 const GURL& malicious_url, const GURL& page_url, const GURL& referrer_url, |
| 221 bool is_subresource, | 221 bool is_subresource, |
| 222 SafeBrowsingService::UrlCheckResult threat_type) const; | 222 SafeBrowsingService::UrlCheckResult threat_type) const; |
| 223 // Generates URL for reporting malware details for users who opt-in. | 223 // Generates URL for reporting malware details for users who opt-in. |
| 224 GURL MalwareDetailsUrl() const; | 224 GURL MalwareDetailsUrl() const; |
| 225 | 225 |
| 226 // Composes a ChunkUrl based on input string. | 226 // Composes a ChunkUrl based on input string. |
| 227 GURL NextChunkUrl(const std::string& input) const; | 227 GURL NextChunkUrl(const std::string& input) const; |
| 228 | 228 |
| 229 // Returns the time (in milliseconds) for the next update request. If | 229 // Returns the time for the next update request. If |back_off| is true, |
| 230 // 'back_off' is true, the time returned will increment an error count and | 230 // the time returned will increment an error count and return the appriate |
| 231 // return the appriate next time (see ScheduleNextUpdate below). | 231 // next time (see ScheduleNextUpdate below). |
| 232 int GetNextUpdateTime(bool back_off); | 232 base::TimeDelta GetNextUpdateInterval(bool back_off); |
| 233 | 233 |
| 234 // Worker function for calculating GetHash and Update backoff times (in | 234 // Worker function for calculating GetHash and Update backoff times (in |
| 235 // seconds). 'Multiplier' is doubled for each consecutive error between the | 235 // seconds). |multiplier| is doubled for each consecutive error between the |
| 236 // 2nd and 5th, and 'error_count' is incremented with each call. | 236 // 2nd and 5th, and |error_count| is incremented with each call. |
| 237 int GetNextBackOffTime(int* error_count, int* multiplier); | 237 base::TimeDelta GetNextBackOffInterval(int* error_count, |
| 238 int* multiplier) const; |
| 238 | 239 |
| 239 // Manages our update with the next allowable update time. If 'back_off_' is | 240 // Manages our update with the next allowable update time. If 'back_off_' is |
| 240 // true, we must decrease the frequency of requests of the SafeBrowsing | 241 // true, we must decrease the frequency of requests of the SafeBrowsing |
| 241 // service according to section 5 of the protocol specification. | 242 // service according to section 5 of the protocol specification. |
| 242 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing. | 243 // When disable_auto_update_ is set, ScheduleNextUpdate will do nothing. |
| 243 // ForceScheduleNextUpdate has to be called to trigger the update. | 244 // ForceScheduleNextUpdate has to be called to trigger the update. |
| 244 void ScheduleNextUpdate(bool back_off); | 245 void ScheduleNextUpdate(bool back_off); |
| 245 | 246 |
| 246 // Sends a request for a list of chunks we should download to the SafeBrowsing | 247 // Sends a request for a list of chunks we should download to the SafeBrowsing |
| 247 // servers. In order to format this request, we need to send all the chunk | 248 // servers. In order to format this request, we need to send all the chunk |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 int gethash_back_off_mult_; | 299 int gethash_back_off_mult_; |
| 299 | 300 |
| 300 // Multiplier between 0 and 1 to spread clients over an interval. | 301 // Multiplier between 0 and 1 to spread clients over an interval. |
| 301 float back_off_fuzz_; | 302 float back_off_fuzz_; |
| 302 | 303 |
| 303 // The list for which we are make a request. | 304 // The list for which we are make a request. |
| 304 std::string list_name_; | 305 std::string list_name_; |
| 305 | 306 |
| 306 // For managing the next earliest time to query the SafeBrowsing servers for | 307 // For managing the next earliest time to query the SafeBrowsing servers for |
| 307 // updates. | 308 // updates. |
| 308 int next_update_sec_; | 309 base::TimeDelta next_update_interval_; |
| 309 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_; | 310 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_; |
| 310 | 311 |
| 311 // All chunk requests that need to be made. | 312 // All chunk requests that need to be made. |
| 312 std::deque<ChunkUrl> chunk_request_urls_; | 313 std::deque<ChunkUrl> chunk_request_urls_; |
| 313 | 314 |
| 314 // Map of GetHash requests. | 315 // Map of GetHash requests. |
| 315 typedef base::hash_map<const net::URLFetcher*, | 316 typedef base::hash_map<const net::URLFetcher*, |
| 316 SafeBrowsingService::SafeBrowsingCheck*> HashRequests; | 317 SafeBrowsingService::SafeBrowsingCheck*> HashRequests; |
| 317 HashRequests hash_requests_; | 318 HashRequests hash_requests_; |
| 318 | 319 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 std::string url_prefix_; | 364 std::string url_prefix_; |
| 364 | 365 |
| 365 // When true, protocol manager will not start an update unless | 366 // When true, protocol manager will not start an update unless |
| 366 // ForceScheduleNextUpdate() is called. This is set for testing purpose. | 367 // ForceScheduleNextUpdate() is called. This is set for testing purpose. |
| 367 bool disable_auto_update_; | 368 bool disable_auto_update_; |
| 368 | 369 |
| 369 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); | 370 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); |
| 370 }; | 371 }; |
| 371 | 372 |
| 372 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 373 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| OLD | NEW |