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

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

Issue 11347005: Change SafeBrowsingProtocolManager::GetFullHash signature. (Closed) Base URL: http://git.chromium.org/chromium/src.git@in_progress
Patch Set: Fix rebase with browser_test Created 8 years, 1 month 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
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 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const std::string& client_name, 54 const std::string& client_name,
55 net::URLRequestContextGetter* request_context_getter, 55 net::URLRequestContextGetter* request_context_getter,
56 const std::string& url_prefix, 56 const std::string& url_prefix,
57 bool disable_auto_update) = 0; 57 bool disable_auto_update) = 0;
58 private: 58 private:
59 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory); 59 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory);
60 }; 60 };
61 61
62 class SafeBrowsingProtocolManager : public net::URLFetcherDelegate { 62 class SafeBrowsingProtocolManager : public net::URLFetcherDelegate {
63 public: 63 public:
64 // FullHashCallback is invoked when GetFullHash completes.
65 // Parameters:
66 // - The vector of full hash results. If empty, indicates that there
67 // were no matches, and that the resource is safe.
68 // - Whether the result can be cached. This may not be the case when
69 // the result did not come from the SB server, for example.
70 typedef base::Callback<void(const std::vector<SBFullHashResult>&,
71 bool)> FullHashCallback;
72
64 virtual ~SafeBrowsingProtocolManager(); 73 virtual ~SafeBrowsingProtocolManager();
65 74
66 // Makes the passed |factory| the factory used to instantiate 75 // Makes the passed |factory| the factory used to instantiate
67 // a SafeBrowsingService. Useful for tests. 76 // a SafeBrowsingService. Useful for tests.
68 static void RegisterFactory(SBProtocolManagerFactory* factory) { 77 static void RegisterFactory(SBProtocolManagerFactory* factory) {
69 factory_ = factory; 78 factory_ = factory;
70 } 79 }
71 80
72 // Create an instance of the safe browsing service. 81 // Create an instance of the safe browsing service.
73 static SafeBrowsingProtocolManager* Create( 82 static SafeBrowsingProtocolManager* Create(
74 SafeBrowsingService* sb_service, 83 SafeBrowsingService* sb_service,
75 const std::string& client_name, 84 const std::string& client_name,
76 net::URLRequestContextGetter* request_context_getter, 85 net::URLRequestContextGetter* request_context_getter,
77 const std::string& url_prefix, 86 const std::string& url_prefix,
78 bool disable_auto_update); 87 bool disable_auto_update);
79 88
80 // Sets up the update schedule and internal state for making periodic requests 89 // Sets up the update schedule and internal state for making periodic requests
81 // of the SafeBrowsing service. 90 // of the SafeBrowsing service.
82 virtual void Initialize(); 91 virtual void Initialize();
83 92
84 // net::URLFetcherDelegate interface. 93 // net::URLFetcherDelegate interface.
85 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 94 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
86 95
87 // API used by the SafeBrowsingService for issuing queries. When the results 96 // Retrieve the full hash for a set of prefixes, and invoke the callback
88 // are available, SafeBrowsingService::HandleGetHashResults is called. 97 // argument when the results are retrieved. The callback may be invoked
89 virtual void GetFullHash(SafeBrowsingService::SafeBrowsingCheck* check, 98 // synchronously.
90 const std::vector<SBPrefix>& prefixes); 99 virtual void GetFullHash(const std::vector<SBPrefix>& prefixes,
100 FullHashCallback callback,
101 bool is_download);
91 102
92 // Forces the start of next update after |interval| time. 103 // Forces the start of next update after |interval| time.
93 void ForceScheduleNextUpdate(base::TimeDelta interval); 104 void ForceScheduleNextUpdate(base::TimeDelta interval);
94 105
95 // Scheduled update callback. 106 // Scheduled update callback.
96 void GetNextUpdate(); 107 void GetNextUpdate();
97 108
98 // Called by the SafeBrowsingService when our request for a list of all chunks 109 // 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 110 // 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 111 // manager shouldn't fetch updates since they can't be written to disk. It
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void HandleGetHashError(const base::Time& now); 279 void HandleGetHashError(const base::Time& now);
269 280
270 // Helper function for update completion. 281 // Helper function for update completion.
271 void UpdateFinished(bool success); 282 void UpdateFinished(bool success);
272 283
273 // A callback that runs if we timeout waiting for a response to an update 284 // A callback that runs if we timeout waiting for a response to an update
274 // request. We use this to properly set our update state. 285 // request. We use this to properly set our update state.
275 void UpdateResponseTimeout(); 286 void UpdateResponseTimeout();
276 287
277 private: 288 private:
289 // Map of GetHash requests to parameters which created it.
290 struct FullHashDetails {
291 FullHashDetails();
292 FullHashDetails(FullHashCallback callback, bool is_download);
293 ~FullHashDetails();
mattm 2012/10/29 23:57:09 Maybe put a blank line between the methods and the
cbentzel 2012/10/30 11:34:03 Done.
294 FullHashCallback callback;
295 bool is_download;
296 };
297 typedef base::hash_map<const net::URLFetcher*, FullHashDetails> HashRequests;
298
278 // The factory that controls the creation of SafeBrowsingProtocolManager. 299 // The factory that controls the creation of SafeBrowsingProtocolManager.
279 // This is used by tests. 300 // This is used by tests.
280 static SBProtocolManagerFactory* factory_; 301 static SBProtocolManagerFactory* factory_;
281 302
282 // Main SafeBrowsing interface object. 303 // Main SafeBrowsing interface object.
283 SafeBrowsingService* sb_service_; 304 SafeBrowsingService* sb_service_;
284 305
285 // Current active request (in case we need to cancel) for updates or chunks 306 // Current active request (in case we need to cancel) for updates or chunks
286 // from the SafeBrowsing service. We can only have one of these outstanding 307 // from the SafeBrowsing service. We can only have one of these outstanding
287 // at any given time unlike GetHash requests, which are tracked separately. 308 // at any given time unlike GetHash requests, which are tracked separately.
(...skipping 17 matching lines...) Expand all
305 std::string list_name_; 326 std::string list_name_;
306 327
307 // For managing the next earliest time to query the SafeBrowsing servers for 328 // For managing the next earliest time to query the SafeBrowsing servers for
308 // updates. 329 // updates.
309 base::TimeDelta next_update_interval_; 330 base::TimeDelta next_update_interval_;
310 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_; 331 base::OneShotTimer<SafeBrowsingProtocolManager> update_timer_;
311 332
312 // All chunk requests that need to be made. 333 // All chunk requests that need to be made.
313 std::deque<ChunkUrl> chunk_request_urls_; 334 std::deque<ChunkUrl> chunk_request_urls_;
314 335
315 // Map of GetHash requests.
316 typedef base::hash_map<const net::URLFetcher*,
317 SafeBrowsingService::SafeBrowsingCheck*> HashRequests;
318 HashRequests hash_requests_; 336 HashRequests hash_requests_;
319 337
320 // The next scheduled update has special behavior for the first 2 requests. 338 // The next scheduled update has special behavior for the first 2 requests.
321 enum UpdateRequestState { 339 enum UpdateRequestState {
322 FIRST_REQUEST = 0, 340 FIRST_REQUEST = 0,
323 SECOND_REQUEST, 341 SECOND_REQUEST,
324 NORMAL_REQUEST 342 NORMAL_REQUEST
325 }; 343 };
326 UpdateRequestState update_state_; 344 UpdateRequestState update_state_;
327 345
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 std::string url_prefix_; 382 std::string url_prefix_;
365 383
366 // When true, protocol manager will not start an update unless 384 // When true, protocol manager will not start an update unless
367 // ForceScheduleNextUpdate() is called. This is set for testing purpose. 385 // ForceScheduleNextUpdate() is called. This is set for testing purpose.
368 bool disable_auto_update_; 386 bool disable_auto_update_;
369 387
370 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); 388 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager);
371 }; 389 };
372 390
373 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 391 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/protocol_manager.cc » ('j') | chrome/browser/safe_browsing/protocol_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698