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

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

Issue 10392192: Remove content::URLFetcherDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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) 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 #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,
11 // and handling responses from, Google's SafeBrowsing servers. This class uses 11 // and handling responses from, Google's SafeBrowsing servers. This class uses
12 // The SafeBrowsingProtocolParser class to do the actual parsing. 12 // The SafeBrowsingProtocolParser class to do the actual parsing.
13 13
14 #include <deque> 14 #include <deque>
15 #include <set> 15 #include <set>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/gtest_prod_util.h" 19 #include "base/gtest_prod_util.h"
20 #include "base/hash_tables.h" 20 #include "base/hash_tables.h"
21 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "base/timer.h" 23 #include "base/timer.h"
24 #include "chrome/browser/safe_browsing/chunk_range.h" 24 #include "chrome/browser/safe_browsing/chunk_range.h"
25 #include "chrome/browser/safe_browsing/protocol_parser.h" 25 #include "chrome/browser/safe_browsing/protocol_parser.h"
26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 27 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
28 #include "content/public/common/url_fetcher_delegate.h" 28 #include "net/url_request/url_fetcher_delegate.h"
29 29
30 #if defined(COMPILER_GCC) 30 #if defined(COMPILER_GCC)
31 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without 31 // Allows us to use URLFetchers in a hash_map with gcc (MSVC is okay without
32 // specifying this). 32 // specifying this).
33 namespace __gnu_cxx { 33 namespace __gnu_cxx {
34 template<> 34 template<>
35 struct hash<const net::URLFetcher*> { 35 struct hash<const net::URLFetcher*> {
36 size_t operator()(const net::URLFetcher* fetcher) const { 36 size_t operator()(const net::URLFetcher* fetcher) const {
37 return reinterpret_cast<size_t>(fetcher); 37 return reinterpret_cast<size_t>(fetcher);
38 } 38 }
39 }; 39 };
40 } 40 }
41 #endif 41 #endif
42 42
43 namespace net {
44 class URLFetcher;
45 } // namespace net
wtc 2012/05/22 17:26:38 Move this up, because net::URLFetcher is already u
akalin 2012/05/22 21:07:05 Done.
46
43 class SafeBrowsingProtocolManager; 47 class SafeBrowsingProtocolManager;
44 // Interface of a factory to create ProtocolManager. Useful for tests. 48 // Interface of a factory to create ProtocolManager. Useful for tests.
45 class SBProtocolManagerFactory { 49 class SBProtocolManagerFactory {
46 public: 50 public:
47 SBProtocolManagerFactory() {} 51 SBProtocolManagerFactory() {}
48 virtual ~SBProtocolManagerFactory() {} 52 virtual ~SBProtocolManagerFactory() {}
49 virtual SafeBrowsingProtocolManager* CreateProtocolManager( 53 virtual SafeBrowsingProtocolManager* CreateProtocolManager(
50 SafeBrowsingService* sb_service, 54 SafeBrowsingService* sb_service,
51 const std::string& client_name, 55 const std::string& client_name,
52 net::URLRequestContextGetter* request_context_getter, 56 net::URLRequestContextGetter* request_context_getter,
53 const std::string& url_prefix, 57 const std::string& url_prefix,
54 bool disable_auto_update) = 0; 58 bool disable_auto_update) = 0;
55 private: 59 private:
56 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory); 60 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory);
57 }; 61 };
58 62
59 class SafeBrowsingProtocolManager : public content::URLFetcherDelegate { 63 class SafeBrowsingProtocolManager : public net::URLFetcherDelegate {
60 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes); 64 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestBackOffTimes);
61 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings); 65 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestChunkStrings);
62 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl); 66 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestGetHashUrl);
63 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 67 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
64 TestGetHashBackOffTimes); 68 TestGetHashBackOffTimes);
65 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 69 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
66 TestSafeBrowsingHitUrl); 70 TestSafeBrowsingHitUrl);
67 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, 71 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest,
68 TestMalwareDetailsUrl); 72 TestMalwareDetailsUrl);
69 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl); 73 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestNextChunkUrl);
(...skipping 14 matching lines...) Expand all
84 SafeBrowsingService* sb_service, 88 SafeBrowsingService* sb_service,
85 const std::string& client_name, 89 const std::string& client_name,
86 net::URLRequestContextGetter* request_context_getter, 90 net::URLRequestContextGetter* request_context_getter,
87 const std::string& url_prefix, 91 const std::string& url_prefix,
88 bool disable_auto_update); 92 bool disable_auto_update);
89 93
90 // Sets up the update schedule and internal state for making periodic requests 94 // Sets up the update schedule and internal state for making periodic requests
91 // of the SafeBrowsing service. 95 // of the SafeBrowsing service.
92 virtual void Initialize(); 96 virtual void Initialize();
93 97
94 // content::URLFetcherDelegate interface. 98 // net::URLFetcherDelegate interface.
95 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 99 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
96 100
97 // API used by the SafeBrowsingService for issuing queries. When the results 101 // API used by the SafeBrowsingService for issuing queries. When the results
98 // are available, SafeBrowsingService::HandleGetHashResults is called. 102 // are available, SafeBrowsingService::HandleGetHashResults is called.
99 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, 103 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check,
100 const std::vector<SBPrefix>& prefixes); 104 const std::vector<SBPrefix>& prefixes);
101 105
102 // Forces the start of next update after |next_update_msec| in msec. 106 // Forces the start of next update after |next_update_msec| in msec.
103 void ForceScheduleNextUpdate(int next_update_msec); 107 void ForceScheduleNextUpdate(int next_update_msec);
104 108
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // The factory that controls the creation of SafeBrowsingProtocolManager. 279 // The factory that controls the creation of SafeBrowsingProtocolManager.
276 // This is used by tests. 280 // This is used by tests.
277 static SBProtocolManagerFactory* factory_; 281 static SBProtocolManagerFactory* factory_;
278 282
279 // Main SafeBrowsing interface object. 283 // Main SafeBrowsing interface object.
280 SafeBrowsingService* sb_service_; 284 SafeBrowsingService* sb_service_;
281 285
282 // Current active request (in case we need to cancel) for updates or chunks 286 // Current active request (in case we need to cancel) for updates or chunks
283 // from the SafeBrowsing service. We can only have one of these outstanding 287 // from the SafeBrowsing service. We can only have one of these outstanding
284 // at any given time unlike GetHash requests, which are tracked separately. 288 // at any given time unlike GetHash requests, which are tracked separately.
285 scoped_ptr<content::URLFetcher> request_; 289 scoped_ptr<net::URLFetcher> request_;
286 290
287 // The kind of request that is currently in progress. 291 // The kind of request that is currently in progress.
288 SafeBrowsingRequestType request_type_; 292 SafeBrowsingRequestType request_type_;
289 293
290 // The number of HTTP response errors, used for request backoff timing. 294 // The number of HTTP response errors, used for request backoff timing.
291 int update_error_count_; 295 int update_error_count_;
292 int gethash_error_count_; 296 int gethash_error_count_;
293 297
294 // Multipliers which double (max == 8) for each error after the second. 298 // Multipliers which double (max == 8) for each error after the second.
295 int update_back_off_mult_; 299 int update_back_off_mult_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 std::string url_prefix_; 365 std::string url_prefix_;
362 366
363 // When true, protocol manager will not start an update unless 367 // When true, protocol manager will not start an update unless
364 // ForceScheduleNextUpdate() is called. This is set for testing purpose. 368 // ForceScheduleNextUpdate() is called. This is set for testing purpose.
365 bool disable_auto_update_; 369 bool disable_auto_update_;
366 370
367 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); 371 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager);
368 }; 372 };
369 373
370 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 374 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698