| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| 7 | 7 |
| 8 // A class that provides the interface between the SafeBrowsing protocol manager | 8 // A class that provides the interface between the SafeBrowsing protocol manager |
| 9 // and database that holds the downloaded updates. | 9 // and database that holds the downloaded updates. |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 // | 64 // |
| 65 // End: SafeBrowsingDatabaseManager implementation | 65 // End: SafeBrowsingDatabaseManager implementation |
| 66 // | 66 // |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 // Construct V4LocalDatabaseManager. | 69 // Construct V4LocalDatabaseManager. |
| 70 // Must be initialized by calling StartOnIOThread() before using. | 70 // Must be initialized by calling StartOnIOThread() before using. |
| 71 V4LocalDatabaseManager(const base::FilePath& base_path); | 71 V4LocalDatabaseManager(const base::FilePath& base_path); |
| 72 | 72 |
| 73 ~V4LocalDatabaseManager() override; |
| 74 |
| 75 void SetTaskRunnerForTest( |
| 76 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 77 task_runner_ = task_runner; |
| 78 } |
| 79 |
| 73 enum class ClientCallbackType { | 80 enum class ClientCallbackType { |
| 74 // This represents the case when we're trying to determine if a URL is | 81 // This represents the case when we're trying to determine if a URL is |
| 75 // unsafe from the following perspectives: Malware, Phishing, UwS. | 82 // unsafe from the following perspectives: Malware, Phishing, UwS. |
| 76 CHECK_BROWSE_URL = 0, | 83 CHECK_BROWSE_URL = 0, |
| 77 | 84 |
| 78 // This should always be the last value. | 85 // This should always be the last value. |
| 79 CHECK_MAX | 86 CHECK_MAX |
| 80 }; | 87 }; |
| 81 | 88 |
| 82 // The information we need to process a URL safety reputation request and | 89 // The information we need to process a URL safety reputation request and |
| (...skipping 30 matching lines...) Expand all Loading... |
| 113 }; | 120 }; |
| 114 | 121 |
| 115 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; | 122 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; |
| 116 | 123 |
| 117 // The stores/lists to always get full hashes for, regardless of which store | 124 // The stores/lists to always get full hashes for, regardless of which store |
| 118 // the hash prefix matched. | 125 // the hash prefix matched. |
| 119 StoresToCheck GetStoresForFullHashRequests() override; | 126 StoresToCheck GetStoresForFullHashRequests() override; |
| 120 | 127 |
| 121 private: | 128 private: |
| 122 friend class V4LocalDatabaseManagerTest; | 129 friend class V4LocalDatabaseManagerTest; |
| 123 void SetTaskRunnerForTest( | |
| 124 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | |
| 125 task_runner_ = task_runner; | |
| 126 } | |
| 127 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, | 130 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, |
| 128 TestGetSeverestThreatTypeAndMetadata); | 131 TestGetSeverestThreatTypeAndMetadata); |
| 129 | 132 |
| 130 // The set of clients awaiting a full hash response. It is used for tracking | 133 // The set of clients awaiting a full hash response. It is used for tracking |
| 131 // which clients have cancelled their outstanding request. | 134 // which clients have cancelled their outstanding request. |
| 132 typedef std::unordered_set<Client*> PendingClients; | 135 typedef std::unordered_set<Client*> PendingClients; |
| 133 | 136 |
| 134 ~V4LocalDatabaseManager() override; | |
| 135 | |
| 136 // Called when all the stores managed by the database have been read from | 137 // Called when all the stores managed by the database have been read from |
| 137 // disk after startup and the database is ready for checking resource | 138 // disk after startup and the database is ready for checking resource |
| 138 // reputation. | 139 // reputation. |
| 139 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); | 140 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); |
| 140 | 141 |
| 141 // Called when all the stores managed by the database have been verified for | 142 // Called when all the stores managed by the database have been verified for |
| 142 // checksum correctness after startup and the database is ready for applying | 143 // checksum correctness after startup and the database is ready for applying |
| 143 // updates. | 144 // updates. |
| 144 void DatabaseReadyForUpdates( | 145 void DatabaseReadyForUpdates( |
| 145 const std::vector<ListIdentifier>& stores_to_reset); | 146 const std::vector<ListIdentifier>& stores_to_reset); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 // Returns the SBThreatType for a given ListIdentifier. | 164 // Returns the SBThreatType for a given ListIdentifier. |
| 164 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); | 165 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); |
| 165 | 166 |
| 166 // Called when the |v4_get_hash_protocol_manager_| has the full hash response | 167 // Called when the |v4_get_hash_protocol_manager_| has the full hash response |
| 167 // available for the URL that we requested. It determines the severest | 168 // available for the URL that we requested. It determines the severest |
| 168 // threat type and responds to the |client| with that information. | 169 // threat type and responds to the |client| with that information. |
| 169 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, | 170 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, |
| 170 const std::vector<FullHashInfo>& full_hash_infos); | 171 const std::vector<FullHashInfo>& full_hash_infos); |
| 171 | 172 |
| 172 // Performs the full hash checking of the URL in |check|. | 173 // Performs the full hash checking of the URL in |check|. |
| 173 void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, | 174 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, |
| 174 const FullHashToStoreAndHashPrefixesMap& | 175 const FullHashToStoreAndHashPrefixesMap& |
| 175 full_hash_to_store_and_hash_prefixes); | 176 full_hash_to_store_and_hash_prefixes); |
| 176 | 177 |
| 177 // When the database is ready to use, process the checks that were queued | 178 // When the database is ready to use, process the checks that were queued |
| 178 // while the database was loading from disk. | 179 // while the database was loading from disk. |
| 179 void ProcessQueuedChecks(); | 180 void ProcessQueuedChecks(); |
| 180 | 181 |
| 181 // Called on StopOnIOThread, it responds to the clients that are waiting for | 182 // Called on StopOnIOThread, it responds to the clients that are waiting for |
| 182 // the database to become available with the verdict as SAFE. | 183 // the database to become available with the verdict as SAFE. |
| 183 void RespondSafeToQueuedChecks(); | 184 void RespondSafeToQueuedChecks(); |
| 184 | 185 |
| 185 // Calls the appopriate method on the |client| object, based on the contents | 186 // Calls the appopriate method on the |client| object, based on the contents |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // The protocol manager that downloads the hash prefix updates. | 235 // The protocol manager that downloads the hash prefix updates. |
| 235 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; | 236 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; |
| 236 | 237 |
| 237 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | 238 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; |
| 238 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | 239 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); |
| 239 }; // class V4LocalDatabaseManager | 240 }; // class V4LocalDatabaseManager |
| 240 | 241 |
| 241 } // namespace safe_browsing | 242 } // namespace safe_browsing |
| 242 | 243 |
| 243 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 244 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |