Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.h

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 // A class that implements Chrome's interface with the SafeBrowsing protocol. 9 // A class that implements Chrome's interface with the SafeBrowsing protocol.
10 // The SafeBrowsingProtocolManager handles formatting and making requests of, 10 // The SafeBrowsingProtocolManager handles formatting and making requests of,
(...skipping 18 matching lines...) Expand all
29 29
30 namespace net { 30 namespace net {
31 class URLRequestStatus; 31 class URLRequestStatus;
32 } // namespace net 32 } // namespace net
33 33
34 #if defined(COMPILER_GCC) 34 #if defined(COMPILER_GCC)
35 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without 35 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without
36 // specifying this). 36 // specifying this).
37 namespace __gnu_cxx { 37 namespace __gnu_cxx {
38 template<> 38 template<>
39 struct hash<const URLFetcher*> { 39 struct hash<const content::URLFetcher*> {
40 size_t operator()(const URLFetcher* fetcher) const { 40 size_t operator()(const content::URLFetcher* fetcher) const {
41 return reinterpret_cast<size_t>(fetcher); 41 return reinterpret_cast<size_t>(fetcher);
42 } 42 }
43 }; 43 };
44 } 44 }
45 #endif 45 #endif
46 46
47 class SafeBrowsingProtocolManager; 47 class SafeBrowsingProtocolManager;
48 // Interface of a factory to create ProtocolManager. Useful for tests. 48 // Interface of a factory to create ProtocolManager. Useful for tests.
49 class SBProtocolManagerFactory { 49 class SBProtocolManagerFactory {
50 public: 50 public:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 net::URLRequestContextGetter* request_context_getter, 96 net::URLRequestContextGetter* request_context_getter,
97 const std::string& info_url_prefix, 97 const std::string& info_url_prefix,
98 const std::string& mackey_url_prefix, 98 const std::string& mackey_url_prefix,
99 bool disable_auto_update); 99 bool disable_auto_update);
100 100
101 // Sets up the update schedule and internal state for making periodic requests 101 // Sets up the update schedule and internal state for making periodic requests
102 // of the SafeBrowsing service. 102 // of the SafeBrowsing service.
103 virtual void Initialize(); 103 virtual void Initialize();
104 104
105 // content::URLFetcherDelegate interface. 105 // content::URLFetcherDelegate interface.
106 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE; 106 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
107 107
108 // API used by the SafeBrowsingService for issuing queries. When the results 108 // API used by the SafeBrowsingService for issuing queries. When the results
109 // are available, SafeBrowsingService::HandleGetHashResults is called. 109 // are available, SafeBrowsingService::HandleGetHashResults is called.
110 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, 110 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check,
111 const std::vector<SBPrefix>& prefixes); 111 const std::vector<SBPrefix>& prefixes);
112 112
113 // Forces the start of next update after |next_update_msec| in msec. 113 // Forces the start of next update after |next_update_msec| in msec.
114 void ForceScheduleNextUpdate(int next_update_msec); 114 void ForceScheduleNextUpdate(int next_update_msec);
115 115
116 // Scheduled update callback. 116 // Scheduled update callback.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // The factory that controls the creation of SafeBrowsingProtocolManager. 304 // The factory that controls the creation of SafeBrowsingProtocolManager.
305 // This is used by tests. 305 // This is used by tests.
306 static SBProtocolManagerFactory* factory_; 306 static SBProtocolManagerFactory* factory_;
307 307
308 // Main SafeBrowsing interface object. 308 // Main SafeBrowsing interface object.
309 SafeBrowsingService* sb_service_; 309 SafeBrowsingService* sb_service_;
310 310
311 // Current active request (in case we need to cancel) for updates or chunks 311 // Current active request (in case we need to cancel) for updates or chunks
312 // from the SafeBrowsing service. We can only have one of these outstanding 312 // from the SafeBrowsing service. We can only have one of these outstanding
313 // at any given time unlike GetHash requests, which are tracked separately. 313 // at any given time unlike GetHash requests, which are tracked separately.
314 scoped_ptr<URLFetcher> request_; 314 scoped_ptr<content::URLFetcher> request_;
315 315
316 // The kind of request that is currently in progress. 316 // The kind of request that is currently in progress.
317 SafeBrowsingRequestType request_type_; 317 SafeBrowsingRequestType request_type_;
318 318
319 // The number of HTTP response errors, used for request backoff timing. 319 // The number of HTTP response errors, used for request backoff timing.
320 int update_error_count_; 320 int update_error_count_;
321 int gethash_error_count_; 321 int gethash_error_count_;
322 322
323 // Multipliers which double (max == 8) for each error after the second. 323 // Multipliers which double (max == 8) for each error after the second.
324 int update_back_off_mult_; 324 int update_back_off_mult_;
325 int gethash_back_off_mult_; 325 int gethash_back_off_mult_;
326 326
327 // Multiplier between 0 and 1 to spread clients over an interval. 327 // Multiplier between 0 and 1 to spread clients over an interval.
328 float back_off_fuzz_; 328 float back_off_fuzz_;
329 329
330 // The list for which we are make a request. 330 // The list for which we are make a request.
331 std::string list_name_; 331 std::string list_name_;
332 332
333 // For managing the next earliest time to query the SafeBrowsing servers for 333 // For managing the next earliest time to query the SafeBrowsing servers for
334 // updates. 334 // updates.
335 int next_update_sec_; 335 int next_update_sec_;
336 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_; 336 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_;
337 337
338 // All chunk requests that need to be made, along with their MAC. 338 // All chunk requests that need to be made, along with their MAC.
339 std::deque<ChunkUrl> chunk_request_urls_; 339 std::deque<ChunkUrl> chunk_request_urls_;
340 340
341 // Map of GetHash requests. 341 // Map of GetHash requests.
342 typedef base::hash_map<const URLFetcher*, 342 typedef base::hash_map<const content::URLFetcher*,
343 SafeBrowsingService::SafeBrowsingCheck*> HashRequests; 343 SafeBrowsingService::SafeBrowsingCheck*> HashRequests;
344 HashRequests hash_requests_; 344 HashRequests hash_requests_;
345 345
346 // The next scheduled update has special behavior for the first 2 requests. 346 // The next scheduled update has special behavior for the first 2 requests.
347 enum UpdateRequestState { 347 enum UpdateRequestState {
348 FIRST_REQUEST = 0, 348 FIRST_REQUEST = 0,
349 SECOND_REQUEST, 349 SECOND_REQUEST,
350 NORMAL_REQUEST 350 NORMAL_REQUEST
351 }; 351 };
352 UpdateRequestState update_state_; 352 UpdateRequestState update_state_;
(...skipping 21 matching lines...) Expand all
374 std::string version_; 374 std::string version_;
375 375
376 // Used for measuring chunk request latency. 376 // Used for measuring chunk request latency.
377 base::Time chunk_request_start_; 377 base::Time chunk_request_start_;
378 378
379 // Tracks the size of each update (in bytes). 379 // Tracks the size of each update (in bytes).
380 int update_size_; 380 int update_size_;
381 381
382 // Track outstanding SafeBrowsing report fetchers for clean up. 382 // Track outstanding SafeBrowsing report fetchers for clean up.
383 // We add both "hit" and "detail" fetchers in this set. 383 // We add both "hit" and "detail" fetchers in this set.
384 std::set<const URLFetcher*> safebrowsing_reports_; 384 std::set<const content::URLFetcher*> safebrowsing_reports_;
385 385
386 // The safe browsing client name sent in each request. 386 // The safe browsing client name sent in each request.
387 std::string client_name_; 387 std::string client_name_;
388 388
389 // A string that is appended to the end of URLs for download, gethash, 389 // A string that is appended to the end of URLs for download, gethash,
390 // newkey, safebrowsing hits and chunk update requests. 390 // newkey, safebrowsing hits and chunk update requests.
391 std::string additional_query_; 391 std::string additional_query_;
392 392
393 // The context we use to issue network requests. 393 // The context we use to issue network requests.
394 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 394 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
395 395
396 // URL prefix where browser fetches safebrowsing chunk updates, hashes, and 396 // URL prefix where browser fetches safebrowsing chunk updates, hashes, and
397 // reports hits to the safebrowsing list for UMA users. 397 // reports hits to the safebrowsing list for UMA users.
398 std::string http_url_prefix_; 398 std::string http_url_prefix_;
399 399
400 // URL prefix where browser fetches MAC client key, and reports detailed 400 // URL prefix where browser fetches MAC client key, and reports detailed
401 // malware reports for users who opt-in. 401 // malware reports for users who opt-in.
402 std::string https_url_prefix_; 402 std::string https_url_prefix_;
403 403
404 // When true, protocol manager will not start an update unless 404 // When true, protocol manager will not start an update unless
405 // ForceScheduleNextUpdate() is called. This is set for testing purpose. 405 // ForceScheduleNextUpdate() is called. This is set for testing purpose.
406 bool disable_auto_update_; 406 bool disable_auto_update_;
407 407
408 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); 408 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager);
409 }; 409 };
410 410
411 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 411 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details_cache.cc ('k') | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698