| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, | 111 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, |
| 112 TestGetSeverestThreatTypeAndMetadata); | 112 TestGetSeverestThreatTypeAndMetadata); |
| 113 | 113 |
| 114 // The set of clients awaiting a full hash response. It is used for tracking | 114 // The set of clients awaiting a full hash response. It is used for tracking |
| 115 // which clients have cancelled their outstanding request. | 115 // which clients have cancelled their outstanding request. |
| 116 typedef std::unordered_set<Client*> PendingClients; | 116 typedef std::unordered_set<Client*> PendingClients; |
| 117 | 117 |
| 118 ~V4LocalDatabaseManager() override; | 118 ~V4LocalDatabaseManager() override; |
| 119 | 119 |
| 120 // Returns the SBThreatType for a given ListIdentifier. |
| 121 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); |
| 122 |
| 123 // Finds the most severe |SBThreatType| and the corresponding |metadata| from |
| 124 // |full_hash_infos|. |
| 125 void GetSeverestThreatTypeAndMetadata( |
| 126 SBThreatType* result_threat_type, |
| 127 ThreatMetadata* metadata, |
| 128 const std::vector<FullHashInfo>& full_hash_infos); |
| 129 |
| 120 // The callback called each time the protocol manager downloads updates | 130 // The callback called each time the protocol manager downloads updates |
| 121 // successfully. | 131 // successfully. |
| 122 void UpdateRequestCompleted( | 132 void UpdateRequestCompleted( |
| 123 std::unique_ptr<ParsedServerResponse> parsed_server_response); | 133 std::unique_ptr<ParsedServerResponse> parsed_server_response); |
| 124 | 134 |
| 125 void SetupUpdateProtocolManager( | 135 void SetupUpdateProtocolManager( |
| 126 net::URLRequestContextGetter* request_context_getter, | 136 net::URLRequestContextGetter* request_context_getter, |
| 127 const V4ProtocolConfig& config); | 137 const V4ProtocolConfig& config); |
| 128 | 138 |
| 129 void SetupDatabase(); | 139 void SetupDatabase(); |
| 130 | 140 |
| 131 // Called when the |v4_get_hash_protocol_manager_| has the full hash response | 141 // Called when the |v4_get_hash_protocol_manager_| has the full hash response |
| 132 // avaialble for the URL that we requested. It determines the severest | 142 // available for the URL that we requested. It determines the severest |
| 133 // threat type and responds to the |client| with that information. | 143 // threat type and responds to the |client| with that information. |
| 134 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, | 144 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, |
| 135 const std::vector<FullHashInfo>& full_hash_infos); | 145 const std::vector<FullHashInfo>& full_hash_infos); |
| 136 | 146 |
| 137 // Called when all the stores managed by the database have been read from | 147 // Called when all the stores managed by the database have been read from |
| 138 // disk after startup and the database is ready for use. | 148 // disk after startup and the database is ready for use. |
| 139 void DatabaseReady(std::unique_ptr<V4Database> v4_database); | 149 void DatabaseReady(std::unique_ptr<V4Database> v4_database); |
| 140 | 150 |
| 141 // Called when the database has been updated and schedules the next update. | 151 // Called when the database has been updated and schedules the next update. |
| 142 void DatabaseUpdated(); | 152 void DatabaseUpdated(); |
| 143 | 153 |
| 144 // Calls the appopriate method on the |client| object, based on the contents | 154 // Calls the appopriate method on the |client| object, based on the contents |
| 145 // of |pending_check|. | 155 // of |pending_check|. |
| 146 void RespondToClient(std::unique_ptr<PendingCheck> pending_check); | 156 void RespondToClient(std::unique_ptr<PendingCheck> pending_check); |
| 147 | 157 |
| 148 // Finds the most severe |SBThreatType| and the corresponding |metadata| from | |
| 149 // |full_hash_infos|. | |
| 150 static void GetSeverestThreatTypeAndMetadata( | |
| 151 SBThreatType* result_threat_type, | |
| 152 ThreatMetadata* metadata, | |
| 153 const std::vector<FullHashInfo>& full_hash_infos); | |
| 154 | |
| 155 // The base directory under which to create the files that contain hashes. | 158 // The base directory under which to create the files that contain hashes. |
| 156 const base::FilePath base_path_; | 159 const base::FilePath base_path_; |
| 157 | 160 |
| 158 // Whether the service is running. | 161 // Whether the service is running. |
| 159 bool enabled_; | 162 bool enabled_; |
| 160 | 163 |
| 161 // The set of clients that are waiting for a full hash response from the | 164 // The set of clients that are waiting for a full hash response from the |
| 162 // SafeBrowsing service. | 165 // SafeBrowsing service. |
| 163 PendingClients pending_clients_; | 166 PendingClients pending_clients_; |
| 164 | 167 |
| 165 // The list of stores to manage (for hash prefixes and full hashes), along | 168 // The list of stores to manage (for hash prefixes and full hashes). Each |
| 166 // with the corresponding filename on disk for each of them. | 169 // element contains the identifier for the store, the corresponding |
| 167 StoreIdAndFileNames store_id_file_names_; | 170 // SBThreatType, whether to fetch hash prefixes for that store, and the |
| 171 // name of the file on disk that would contain the prefixes, if applicable. |
| 172 ListInfos list_infos_; |
| 168 | 173 |
| 169 // The protocol manager that downloads the hash prefix updates. | 174 // The protocol manager that downloads the hash prefix updates. |
| 170 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; | 175 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; |
| 171 | 176 |
| 172 // The database that manages the stores containing the hash prefix updates. | 177 // The database that manages the stores containing the hash prefix updates. |
| 173 // All writes to this variable must happen on the IO thread only. | 178 // All writes to this variable must happen on the IO thread only. |
| 174 std::unique_ptr<V4Database> v4_database_; | 179 std::unique_ptr<V4Database> v4_database_; |
| 175 | 180 |
| 176 // Called when the V4Database has finished applying the latest update and is | 181 // Called when the V4Database has finished applying the latest update and is |
| 177 // ready to process next update. | 182 // ready to process next update. |
| 178 DatabaseUpdatedCallback db_updated_callback_; | 183 DatabaseUpdatedCallback db_updated_callback_; |
| 179 | 184 |
| 180 // The sequenced task runner for running safe browsing database operations. | 185 // The sequenced task runner for running safe browsing database operations. |
| 181 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 186 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 182 | 187 |
| 183 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | 188 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; |
| 184 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | 189 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); |
| 185 }; // class V4LocalDatabaseManager | 190 }; // class V4LocalDatabaseManager |
| 186 | 191 |
| 187 } // namespace safe_browsing | 192 } // namespace safe_browsing |
| 188 | 193 |
| 189 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 194 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |