| 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 // See https://developers.google.com/safe-browsing/developers_guide_v2 for |
| 10 // protocol details. |
| 11 // |
| 9 // The SafeBrowsingProtocolManager handles formatting and making requests of, | 12 // The SafeBrowsingProtocolManager handles formatting and making requests of, |
| 10 // and handling responses from, Google's SafeBrowsing servers. This class uses | 13 // and handling responses from, Google's SafeBrowsing servers. This class uses |
| 11 // The SafeBrowsingProtocolParser class to do the actual parsing. | 14 // The SafeBrowsingProtocolParser class to do the actual parsing. |
| 12 | 15 |
| 13 #include <deque> | 16 #include <deque> |
| 14 #include <set> | 17 #include <set> |
| 15 #include <string> | 18 #include <string> |
| 16 #include <vector> | 19 #include <vector> |
| 17 | 20 |
| 18 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Scheduled update callback. | 98 // Scheduled update callback. |
| 96 void GetNextUpdate(); | 99 void GetNextUpdate(); |
| 97 | 100 |
| 98 // Called by the SafeBrowsingService when our request for a list of all chunks | 101 // 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 | 102 // 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 | 103 // manager shouldn't fetch updates since they can't be written to disk. It |
| 101 // should try again later to open the database. | 104 // should try again later to open the database. |
| 102 void OnGetChunksComplete(const std::vector<SBListChunkRanges>& list, | 105 void OnGetChunksComplete(const std::vector<SBListChunkRanges>& list, |
| 103 bool database_error); | 106 bool database_error); |
| 104 | 107 |
| 105 // Called after the chunks that were parsed were inserted in the database. | |
| 106 void OnChunkInserted(); | |
| 107 | |
| 108 // The last time we received an update. | 108 // The last time we received an update. |
| 109 base::Time last_update() const { return last_update_; } | 109 base::Time last_update() const { return last_update_; } |
| 110 | 110 |
| 111 // Setter for additional_query_. To make sure the additional_query_ won't | 111 // Setter for additional_query_. To make sure the additional_query_ won't |
| 112 // be changed in the middle of an update, caller (e.g.: SafeBrowsingService) | 112 // be changed in the middle of an update, caller (e.g.: SafeBrowsingService) |
| 113 // should call this after callbacks triggered in UpdateFinished() or before | 113 // should call this after callbacks triggered in UpdateFinished() or before |
| 114 // IssueUpdateRequest(). | 114 // IssueUpdateRequest(). |
| 115 void set_additional_query(const std::string& query) { | 115 void set_additional_query(const std::string& query) { |
| 116 additional_query_ = query; | 116 additional_query_ = query; |
| 117 } | 117 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // current time is |now|. | 230 // current time is |now|. |
| 231 void HandleGetHashError(const base::Time& now); | 231 void HandleGetHashError(const base::Time& now); |
| 232 | 232 |
| 233 // Helper function for update completion. | 233 // Helper function for update completion. |
| 234 void UpdateFinished(bool success); | 234 void UpdateFinished(bool success); |
| 235 | 235 |
| 236 // A callback that runs if we timeout waiting for a response to an update | 236 // A callback that runs if we timeout waiting for a response to an update |
| 237 // request. We use this to properly set our update state. | 237 // request. We use this to properly set our update state. |
| 238 void UpdateResponseTimeout(); | 238 void UpdateResponseTimeout(); |
| 239 | 239 |
| 240 // Called after the chunks are added to the database. |
| 241 void OnAddChunksComplete(); |
| 242 |
| 240 private: | 243 private: |
| 241 // Map of GetHash requests to parameters which created it. | 244 // Map of GetHash requests to parameters which created it. |
| 242 struct FullHashDetails { | 245 struct FullHashDetails { |
| 243 FullHashDetails(); | 246 FullHashDetails(); |
| 244 FullHashDetails(FullHashCallback callback, bool is_download); | 247 FullHashDetails(FullHashCallback callback, bool is_download); |
| 245 ~FullHashDetails(); | 248 ~FullHashDetails(); |
| 246 | 249 |
| 247 FullHashCallback callback; | 250 FullHashCallback callback; |
| 248 bool is_download; | 251 bool is_download; |
| 249 }; | 252 }; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 const SafeBrowsingProtocolConfig& config) = 0; | 352 const SafeBrowsingProtocolConfig& config) = 0; |
| 350 private: | 353 private: |
| 351 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory); | 354 DISALLOW_COPY_AND_ASSIGN(SBProtocolManagerFactory); |
| 352 }; | 355 }; |
| 353 | 356 |
| 354 // Delegate interface for the SafeBrowsingProtocolManager. | 357 // Delegate interface for the SafeBrowsingProtocolManager. |
| 355 class SafeBrowsingProtocolManagerDelegate { | 358 class SafeBrowsingProtocolManagerDelegate { |
| 356 public: | 359 public: |
| 357 typedef base::Callback<void(const std::vector<SBListChunkRanges>&, bool)> | 360 typedef base::Callback<void(const std::vector<SBListChunkRanges>&, bool)> |
| 358 GetChunksCallback; | 361 GetChunksCallback; |
| 362 typedef base::Callback<void(void)> AddChunksCallback; |
| 359 | 363 |
| 360 virtual ~SafeBrowsingProtocolManagerDelegate(); | 364 virtual ~SafeBrowsingProtocolManagerDelegate(); |
| 361 | 365 |
| 362 // |UpdateStarted()| is called just before the SafeBrowsing update protocol | 366 // |UpdateStarted()| is called just before the SafeBrowsing update protocol |
| 363 // has begun. | 367 // has begun. |
| 364 virtual void UpdateStarted() = 0; | 368 virtual void UpdateStarted() = 0; |
| 365 | 369 |
| 366 // |UpdateFinished()| is called just after the SafeBrowsing update protocol | 370 // |UpdateFinished()| is called just after the SafeBrowsing update protocol |
| 367 // has completed. | 371 // has completed. |
| 368 virtual void UpdateFinished(bool success) = 0; | 372 virtual void UpdateFinished(bool success) = 0; |
| 369 | 373 |
| 370 // Wipe out the local database. The SafeBrowsing server can request this. | 374 // Wipe out the local database. The SafeBrowsing server can request this. |
| 371 virtual void ResetDatabase() = 0; | 375 virtual void ResetDatabase() = 0; |
| 372 | 376 |
| 373 // Retrieve all the local database chunks, and invoke |callback| with the | 377 // Retrieve all the local database chunks, and invoke |callback| with the |
| 374 // results. The SafeBrowsingProtocolManagerDelegate must only invoke the | 378 // results. The SafeBrowsingProtocolManagerDelegate must only invoke the |
| 375 // callback if the SafeBrowsingProtocolManager is still alive. Only one call | 379 // callback if the SafeBrowsingProtocolManager is still alive. Only one call |
| 376 // may be made to GetChunks at a time. | 380 // may be made to GetChunks at a time. |
| 377 virtual void GetChunks(GetChunksCallback callback) = 0; | 381 virtual void GetChunks(GetChunksCallback callback) = 0; |
| 378 | 382 |
| 379 // Add new chunks to the database. | 383 // Add new chunks to the database. Invokes |callback| when complete, but must |
| 380 virtual void AddChunks(const std::string& list, SBChunkList* chunks) = 0; | 384 // call at a later time. |
| 385 virtual void AddChunks(const std::string& list, SBChunkList* chunks, |
| 386 AddChunksCallback callback) = 0; |
| 381 | 387 |
| 382 // Delete chunks from the database. | 388 // Delete chunks from the database. |
| 383 virtual void DeleteChunks( | 389 virtual void DeleteChunks( |
| 384 std::vector<SBChunkDelete>* delete_chunks) = 0; | 390 std::vector<SBChunkDelete>* delete_chunks) = 0; |
| 385 }; | 391 }; |
| 386 | 392 |
| 387 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ | 393 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_MANAGER_H_ |
| OLD | NEW |