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

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

Issue 11784038: Add backup URL support for SafeBrowsing data requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reduce duplication in comments Created 7 years, 11 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 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl); 173 FRIEND_TEST_ALL_PREFIXES(SafeBrowsingProtocolManagerTest, TestUpdateUrl);
174 friend class SafeBrowsingServerTest; 174 friend class SafeBrowsingServerTest;
175 friend class SBProtocolManagerFactoryImpl; 175 friend class SBProtocolManagerFactoryImpl;
176 176
177 // Internal API for fetching information from the SafeBrowsing servers. The 177 // Internal API for fetching information from the SafeBrowsing servers. The
178 // GetHash requests are higher priority since they can block user requests 178 // GetHash requests are higher priority since they can block user requests
179 // so are handled separately. 179 // so are handled separately.
180 enum SafeBrowsingRequestType { 180 enum SafeBrowsingRequestType {
181 NO_REQUEST = 0, // No requests in progress 181 NO_REQUEST = 0, // No requests in progress
182 UPDATE_REQUEST, // Request for redirect URLs 182 UPDATE_REQUEST, // Request for redirect URLs
183 BACKUP_UPDATE_REQUEST, // Request for redirect URLs to a backup URL.
183 CHUNK_REQUEST, // Request for a specific chunk 184 CHUNK_REQUEST, // Request for a specific chunk
184 }; 185 };
185 186
187 // Which type of backup update request is being used.
188 enum BackupUpdateReason {
189 BACKUP_UPDATE_REASON_CONNECT,
190 BACKUP_UPDATE_REASON_HTTP,
191 BACKUP_UPDATE_REASON_NETWORK,
192 BACKUP_UPDATE_REASON_MAX,
193 };
194
186 // Generates Update URL for querying about the latest set of chunk updates. 195 // Generates Update URL for querying about the latest set of chunk updates.
187 GURL UpdateUrl() const; 196 GURL UpdateUrl() const;
197
198 // Generates backup Update URL for querying about the latest set of chunk
199 // updates. |url_prefix| is the base prefix to use.
200 GURL BackupUpdateUrl(BackupUpdateReason reason) const;
201
188 // Generates GetHash request URL for retrieving full hashes. 202 // Generates GetHash request URL for retrieving full hashes.
189 GURL GetHashUrl() const; 203 GURL GetHashUrl() const;
190 // Generates URL for reporting safe browsing hits for UMA users. 204 // Generates URL for reporting safe browsing hits for UMA users.
191 205
192 // Composes a ChunkUrl based on input string. 206 // Composes a ChunkUrl based on input string.
193 GURL NextChunkUrl(const std::string& input) const; 207 GURL NextChunkUrl(const std::string& input) const;
194 208
195 // Returns the time for the next update request. If |back_off| is true, 209 // Returns the time for the next update request. If |back_off| is true,
196 // the time returned will increment an error count and return the appriate 210 // the time returned will increment an error count and return the appriate
197 // next time (see ScheduleNextUpdate below). 211 // next time (see ScheduleNextUpdate below).
(...skipping 12 matching lines...) Expand all
210 // ForceScheduleNextUpdate has to be called to trigger the update. 224 // ForceScheduleNextUpdate has to be called to trigger the update.
211 void ScheduleNextUpdate(bool back_off); 225 void ScheduleNextUpdate(bool back_off);
212 226
213 // Sends a request for a list of chunks we should download to the SafeBrowsing 227 // Sends a request for a list of chunks we should download to the SafeBrowsing
214 // servers. In order to format this request, we need to send all the chunk 228 // servers. In order to format this request, we need to send all the chunk
215 // numbers for each list that we have to the server. Getting the chunk numbers 229 // numbers for each list that we have to the server. Getting the chunk numbers
216 // requires a database query (run on the database thread), and the request 230 // requires a database query (run on the database thread), and the request
217 // is sent upon completion of that query in OnGetChunksComplete. 231 // is sent upon completion of that query in OnGetChunksComplete.
218 void IssueUpdateRequest(); 232 void IssueUpdateRequest();
219 233
234 // Sends a backup request for a list of chunks to download, when the primary
235 // update request failed. |reason| specifies why the backup is needed. Unlike
236 // the primary IssueUpdateRequest, this does not need to hit the local
237 // SafeBrowsing database since the existing chunk numbers are remembered from
238 // the primary update request.
239 void IssueBackupUpdateRequest(BackupUpdateReason reason);
240
220 // Sends a request for a chunk to the SafeBrowsing servers. 241 // Sends a request for a chunk to the SafeBrowsing servers.
221 void IssueChunkRequest(); 242 void IssueChunkRequest();
222 243
223 // Formats a string returned from the database into: 244 // Formats a string returned from the database into:
224 // "list_name;a:<add_chunk_ranges>:s:<sub_chunk_ranges>\n" 245 // "list_name;a:<add_chunk_ranges>:s:<sub_chunk_ranges>\n"
225 static std::string FormatList(const SBListChunkRanges& list); 246 static std::string FormatList(const SBListChunkRanges& list);
226 247
227 // Runs the protocol parser on received data and update the 248 // Runs the protocol parser on received data and update the
228 // SafeBrowsingService with the new content. Returns 'true' on successful 249 // SafeBrowsingService with the new content. Returns 'true' on successful
229 // parse, 'false' on error. 250 // parse, 'false' on error.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // A string that is appended to the end of URLs for download, gethash, 353 // A string that is appended to the end of URLs for download, gethash,
333 // safebrowsing hits and chunk update requests. 354 // safebrowsing hits and chunk update requests.
334 std::string additional_query_; 355 std::string additional_query_;
335 356
336 // The context we use to issue network requests. 357 // The context we use to issue network requests.
337 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 358 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
338 359
339 // URL prefix where browser fetches safebrowsing chunk updates, and hashes. 360 // URL prefix where browser fetches safebrowsing chunk updates, and hashes.
340 std::string url_prefix_; 361 std::string url_prefix_;
341 362
363 // Backup URL prefixes for updates.
364 std::string backup_url_prefixes_[BACKUP_UPDATE_REASON_MAX];
365
366 // The current reason why the backup update request is happening.
367 BackupUpdateReason backup_update_reason_;
368
369 // Data to POST when doing an update.
370 std::string update_list_data_;
371
342 // When true, protocol manager will not start an update unless 372 // When true, protocol manager will not start an update unless
343 // ForceScheduleNextUpdate() is called. This is set for testing purpose. 373 // ForceScheduleNextUpdate() is called. This is set for testing purpose.
344 bool disable_auto_update_; 374 bool disable_auto_update_;
345 375
346 // ID for URLFetchers for testing. 376 // ID for URLFetchers for testing.
347 int url_fetcher_id_; 377 int url_fetcher_id_;
348 378
349 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager); 379 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingProtocolManager);
350 }; 380 };
351 381
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // call at a later time. 422 // call at a later time.
393 virtual void AddChunks(const std::string& list, SBChunkList* chunks, 423 virtual void AddChunks(const std::string& list, SBChunkList* chunks,
394 AddChunksCallback callback) = 0; 424 AddChunksCallback callback) = 0;
395 425
396 // Delete chunks from the database. 426 // Delete chunks from the database.
397 virtual void DeleteChunks( 427 virtual void DeleteChunks(
398 std::vector<SBChunkDelete>* delete_chunks) = 0; 428 std::vector<SBChunkDelete>* delete_chunks) = 0;
399 }; 429 };
400 430
401 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ 431 #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