Chromium Code Reviews| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 // Must be initialized by calling StartOnIOThread() before using. | 71 // Must be initialized by calling StartOnIOThread() before using. |
| 72 V4LocalDatabaseManager(const base::FilePath& base_path); | 72 V4LocalDatabaseManager(const base::FilePath& base_path); |
| 73 | 73 |
| 74 ~V4LocalDatabaseManager() override; | 74 ~V4LocalDatabaseManager() override; |
| 75 | 75 |
| 76 void SetTaskRunnerForTest( | 76 void SetTaskRunnerForTest( |
| 77 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 77 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 78 task_runner_ = task_runner; | 78 task_runner_ = task_runner; |
| 79 } | 79 } |
| 80 | 80 |
| 81 enum class ClientCallbackType { | 81 enum class ClientCallbackType { |
|
Nathan Parker
2016/10/26 00:45:45
Nit: Could this and the PendingCheck go in the .cc
vakh (use Gerrit instead)
2016/10/26 19:53:22
Done.
| |
| 82 // This represents the case when we're trying to determine if a URL is | 82 // This represents the case when we're trying to determine if a URL is |
| 83 // unsafe from the following perspectives: Malware, Phishing, UwS. | 83 // unsafe from the following perspectives: Malware, Phishing, UwS. |
| 84 CHECK_BROWSE_URL = 0, | 84 CHECK_BROWSE_URL = 0, |
| 85 | 85 |
| 86 // This represents the case when we're trying to determine if any of the | |
| 87 // URLs in a vector of URLs is unsafe for downloading binaries. | |
| 88 CHECK_DOWNLOAD_URLS = 1, | |
| 89 | |
| 86 // This should always be the last value. | 90 // This should always be the last value. |
| 87 CHECK_MAX | 91 CHECK_MAX |
|
Nathan Parker
2016/10/26 00:45:45
Nit: you don't really need a max if you're going t
vakh (use Gerrit instead)
2016/10/26 19:53:22
Done.
| |
| 88 }; | 92 }; |
| 89 | 93 |
| 90 // The information we need to process a URL safety reputation request and | 94 // The information we need to process a URL safety reputation request and |
| 91 // respond to the SafeBrowsing client that asked for it. | 95 // respond to the SafeBrowsing client that asked for it. |
| 92 // TODO(vakh): In its current form, it only includes information for | 96 // TODO(vakh): In its current form, it only includes information for |
| 93 // |CheckBrowseUrl| method. Extend it to serve other methods on |client|. | 97 // |CheckBrowseUrl| and |CheckDownloadUrl| methods. Extend it to serve other |
| 98 // methods on |client|. | |
| 94 struct PendingCheck { | 99 struct PendingCheck { |
| 95 PendingCheck(Client* client, | 100 PendingCheck(Client* client, |
| 96 ClientCallbackType client_callback_type, | 101 ClientCallbackType client_callback_type, |
| 97 const StoresToCheck& stores_to_check, | 102 const StoresToCheck& stores_to_check, |
| 98 const GURL& url); | 103 const std::vector<GURL>& urls); |
| 99 | 104 |
| 100 ~PendingCheck(); | 105 ~PendingCheck(); |
| 101 | 106 |
| 102 // The SafeBrowsing client that's waiting for the safe/unsafe verdict. | 107 // The SafeBrowsing client that's waiting for the safe/unsafe verdict. |
| 103 Client* client; | 108 Client* client; |
| 104 | 109 |
| 105 // Determines which funtion from the |client| needs to be called once we | 110 // Determines which funtion from the |client| needs to be called once we |
| 106 // know whether the URL in |url| is safe or unsafe. | 111 // know whether the URL in |url| is safe or unsafe. |
| 107 ClientCallbackType client_callback_type; | 112 const ClientCallbackType client_callback_type; |
| 108 | 113 |
| 109 // The threat verdict for the URL being checked. | 114 // The threat verdict for the URL being checked. |
| 110 SBThreatType result_threat_type; | 115 SBThreatType result_threat_type; |
| 111 | 116 |
| 112 // When the check was sent to the SafeBrowsing service. Used to record the | 117 // When the check was sent to the SafeBrowsing service. Used to record the |
| 113 // time it takes to get the uncached full hashes from the service (or a | 118 // time it takes to get the uncached full hashes from the service (or a |
| 114 // cached full hash response). | 119 // cached full hash response). |
| 115 base::TimeTicks full_hash_check_start; | 120 base::TimeTicks full_hash_check_start; |
| 116 | 121 |
| 117 // The SafeBrowsing lists to check hash prefixes in. | 122 // The SafeBrowsing lists to check hash prefixes in. |
| 118 StoresToCheck stores_to_check; | 123 const StoresToCheck stores_to_check; |
| 119 | 124 |
| 120 // The URL that is being checked for being unsafe. | 125 // The URL that is being checked for being unsafe. |
|
Nathan Parker
2016/10/26 00:45:45
URL(s) that are...
vakh (use Gerrit instead)
2016/10/26 19:53:21
Done.
| |
| 121 GURL url; | 126 const std::vector<GURL> urls; |
| 122 | 127 |
| 123 // The metadata associated with the full hash of the severest match found | 128 // The metadata associated with the full hash of the severest match found |
| 124 // for that URL. | 129 // for that URL. |
| 125 ThreatMetadata url_metadata; | 130 ThreatMetadata url_metadata; |
| 126 }; | 131 }; |
| 127 | 132 |
| 128 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; | 133 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; |
| 129 | 134 |
| 130 // The stores/lists to always get full hashes for, regardless of which store | 135 // The stores/lists to always get full hashes for, regardless of which store |
| 131 // the hash prefix matched. | 136 // the hash prefix matched. |
| 132 StoresToCheck GetStoresForFullHashRequests() override; | 137 StoresToCheck GetStoresForFullHashRequests() override; |
| 133 | 138 |
| 134 private: | 139 private: |
| 135 friend class V4LocalDatabaseManagerTest; | 140 friend class V4LocalDatabaseManagerTest; |
| 136 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, | 141 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, |
| 137 TestGetSeverestThreatTypeAndMetadata); | 142 TestGetSeverestThreatTypeAndMetadata); |
| 138 | 143 |
| 139 // The set of clients awaiting a full hash response. It is used for tracking | 144 // The set of clients awaiting a full hash response. It is used for tracking |
| 140 // which clients have cancelled their outstanding request. | 145 // which clients have cancelled their outstanding request. |
| 141 typedef std::unordered_set<Client*> PendingClients; | 146 typedef std::unordered_set<const Client*> PendingClients; |
| 142 | 147 |
| 143 // Called when all the stores managed by the database have been read from | 148 // Called when all the stores managed by the database have been read from |
| 144 // disk after startup and the database is ready for checking resource | 149 // disk after startup and the database is ready for checking resource |
| 145 // reputation. | 150 // reputation. |
| 146 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); | 151 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); |
| 147 | 152 |
| 148 // Called when all the stores managed by the database have been verified for | 153 // Called when all the stores managed by the database have been verified for |
| 149 // checksum correctness after startup and the database is ready for applying | 154 // checksum correctness after startup and the database is ready for applying |
| 150 // updates. | 155 // updates. |
| 151 void DatabaseReadyForUpdates( | 156 void DatabaseReadyForUpdates( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 163 // Finds the most severe |SBThreatType| and the corresponding |metadata| from | 168 // Finds the most severe |SBThreatType| and the corresponding |metadata| from |
| 164 // |full_hash_infos|. | 169 // |full_hash_infos|. |
| 165 void GetSeverestThreatTypeAndMetadata( | 170 void GetSeverestThreatTypeAndMetadata( |
| 166 SBThreatType* result_threat_type, | 171 SBThreatType* result_threat_type, |
| 167 ThreatMetadata* metadata, | 172 ThreatMetadata* metadata, |
| 168 const std::vector<FullHashInfo>& full_hash_infos); | 173 const std::vector<FullHashInfo>& full_hash_infos); |
| 169 | 174 |
| 170 // Returns the SBThreatType for a given ListIdentifier. | 175 // Returns the SBThreatType for a given ListIdentifier. |
| 171 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); | 176 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); |
| 172 | 177 |
| 178 // Queues the check for async response if the database isn't ready yet. | |
| 179 // If the database is ready, checks the database for prefix matches and | |
| 180 // returns true immediately if there's no match. If a match is found, it | |
| 181 // schedules a task to perform full hash check and returns false. | |
| 182 bool HandleCheck(std::unique_ptr<PendingCheck> check); | |
| 183 | |
| 173 // Called when the |v4_get_hash_protocol_manager_| has the full hash response | 184 // Called when the |v4_get_hash_protocol_manager_| has the full hash response |
| 174 // available for the URL that we requested. It determines the severest | 185 // available for the URL that we requested. It determines the severest |
| 175 // threat type and responds to the |client| with that information. | 186 // threat type and responds to the |client| with that information. |
| 176 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, | 187 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, |
| 177 const std::vector<FullHashInfo>& full_hash_infos); | 188 const std::vector<FullHashInfo>& full_hash_infos); |
| 178 | 189 |
| 179 // Performs the full hash checking of the URL in |check|. | 190 // Performs the full hash checking of the URL in |check|. |
| 180 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, | 191 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, |
| 181 const FullHashToStoreAndHashPrefixesMap& | 192 const FullHashToStoreAndHashPrefixesMap& |
| 182 full_hash_to_store_and_hash_prefixes); | 193 full_hash_to_store_and_hash_prefixes); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 254 |
| 244 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_; | 255 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_; |
| 245 | 256 |
| 246 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | 257 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; |
| 247 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | 258 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); |
| 248 }; // class V4LocalDatabaseManager | 259 }; // class V4LocalDatabaseManager |
| 249 | 260 |
| 250 } // namespace safe_browsing | 261 } // namespace safe_browsing |
| 251 | 262 |
| 252 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 263 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |