| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/memory/weak_ptr.h" |
| 13 #include "components/safe_browsing_db/database_manager.h" | 14 #include "components/safe_browsing_db/database_manager.h" |
| 14 #include "components/safe_browsing_db/hit_report.h" | 15 #include "components/safe_browsing_db/hit_report.h" |
| 15 #include "components/safe_browsing_db/v4_database.h" | 16 #include "components/safe_browsing_db/v4_database.h" |
| 16 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" | 17 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" |
| 17 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 18 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 18 #include "components/safe_browsing_db/v4_update_protocol_manager.h" | 19 #include "components/safe_browsing_db/v4_update_protocol_manager.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 using content::ResourceType; | 22 using content::ResourceType; |
| 22 | 23 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 64 |
| 64 // | 65 // |
| 65 // End: SafeBrowsingDatabaseManager implementation | 66 // End: SafeBrowsingDatabaseManager implementation |
| 66 // | 67 // |
| 67 | 68 |
| 68 protected: | 69 protected: |
| 69 // Construct V4LocalDatabaseManager. | 70 // Construct V4LocalDatabaseManager. |
| 70 // Must be initialized by calling StartOnIOThread() before using. | 71 // Must be initialized by calling StartOnIOThread() before using. |
| 71 V4LocalDatabaseManager(const base::FilePath& base_path); | 72 V4LocalDatabaseManager(const base::FilePath& base_path); |
| 72 | 73 |
| 74 ~V4LocalDatabaseManager() override; |
| 75 |
| 76 void SetTaskRunnerForTest( |
| 77 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 78 task_runner_ = task_runner; |
| 79 } |
| 80 |
| 73 enum class ClientCallbackType { | 81 enum class ClientCallbackType { |
| 74 // 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 |
| 75 // unsafe from the following perspectives: Malware, Phishing, UwS. | 83 // unsafe from the following perspectives: Malware, Phishing, UwS. |
| 76 CHECK_BROWSE_URL = 0, | 84 CHECK_BROWSE_URL = 0, |
| 77 | 85 |
| 78 // This should always be the last value. | 86 // This should always be the last value. |
| 79 CHECK_MAX | 87 CHECK_MAX |
| 80 }; | 88 }; |
| 81 | 89 |
| 82 // The information we need to process a URL safety reputation request and | 90 // The information we need to process a URL safety reputation request and |
| (...skipping 30 matching lines...) Expand all Loading... |
| 113 }; | 121 }; |
| 114 | 122 |
| 115 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; | 123 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; |
| 116 | 124 |
| 117 // The stores/lists to always get full hashes for, regardless of which store | 125 // The stores/lists to always get full hashes for, regardless of which store |
| 118 // the hash prefix matched. | 126 // the hash prefix matched. |
| 119 StoresToCheck GetStoresForFullHashRequests() override; | 127 StoresToCheck GetStoresForFullHashRequests() override; |
| 120 | 128 |
| 121 private: | 129 private: |
| 122 friend class V4LocalDatabaseManagerTest; | 130 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, | 131 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, |
| 128 TestGetSeverestThreatTypeAndMetadata); | 132 TestGetSeverestThreatTypeAndMetadata); |
| 129 | 133 |
| 130 // The set of clients awaiting a full hash response. It is used for tracking | 134 // The set of clients awaiting a full hash response. It is used for tracking |
| 131 // which clients have cancelled their outstanding request. | 135 // which clients have cancelled their outstanding request. |
| 132 typedef std::unordered_set<Client*> PendingClients; | 136 typedef std::unordered_set<Client*> PendingClients; |
| 133 | 137 |
| 134 ~V4LocalDatabaseManager() override; | |
| 135 | |
| 136 // Called when all the stores managed by the database have been read from | 138 // 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 | 139 // disk after startup and the database is ready for checking resource |
| 138 // reputation. | 140 // reputation. |
| 139 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); | 141 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); |
| 140 | 142 |
| 141 // Called when all the stores managed by the database have been verified for | 143 // 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 | 144 // checksum correctness after startup and the database is ready for applying |
| 143 // updates. | 145 // updates. |
| 144 void DatabaseReadyForUpdates( | 146 void DatabaseReadyForUpdates( |
| 145 const std::vector<ListIdentifier>& stores_to_reset); | 147 const std::vector<ListIdentifier>& stores_to_reset); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 // Returns the SBThreatType for a given ListIdentifier. | 165 // Returns the SBThreatType for a given ListIdentifier. |
| 164 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); | 166 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); |
| 165 | 167 |
| 166 // Called when the |v4_get_hash_protocol_manager_| has the full hash response | 168 // 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 | 169 // available for the URL that we requested. It determines the severest |
| 168 // threat type and responds to the |client| with that information. | 170 // threat type and responds to the |client| with that information. |
| 169 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, | 171 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, |
| 170 const std::vector<FullHashInfo>& full_hash_infos); | 172 const std::vector<FullHashInfo>& full_hash_infos); |
| 171 | 173 |
| 172 // Performs the full hash checking of the URL in |check|. | 174 // Performs the full hash checking of the URL in |check|. |
| 173 void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, | 175 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, |
| 174 const FullHashToStoreAndHashPrefixesMap& | 176 const FullHashToStoreAndHashPrefixesMap& |
| 175 full_hash_to_store_and_hash_prefixes); | 177 full_hash_to_store_and_hash_prefixes); |
| 176 | 178 |
| 177 // When the database is ready to use, process the checks that were queued | 179 // When the database is ready to use, process the checks that were queued |
| 178 // while the database was loading from disk. | 180 // while the database was loading from disk. |
| 179 void ProcessQueuedChecks(); | 181 void ProcessQueuedChecks(); |
| 180 | 182 |
| 181 // Called on StopOnIOThread, it responds to the clients that are waiting for | 183 // Called on StopOnIOThread, it responds to the clients that are waiting for |
| 182 // the database to become available with the verdict as SAFE. | 184 // the database to become available with the verdict as SAFE. |
| 183 void RespondSafeToQueuedChecks(); | 185 void RespondSafeToQueuedChecks(); |
| 184 | 186 |
| 185 // Calls the appopriate method on the |client| object, based on the contents | 187 // Calls the appopriate method on the |client| object, based on the contents |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // The sequenced task runner for running safe browsing database operations. | 229 // The sequenced task runner for running safe browsing database operations. |
| 228 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 230 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 229 | 231 |
| 230 // The database that manages the stores containing the hash prefix updates. | 232 // The database that manages the stores containing the hash prefix updates. |
| 231 // All writes to this variable must happen on the IO thread only. | 233 // All writes to this variable must happen on the IO thread only. |
| 232 std::unique_ptr<V4Database> v4_database_; | 234 std::unique_ptr<V4Database> v4_database_; |
| 233 | 235 |
| 234 // The protocol manager that downloads the hash prefix updates. | 236 // The protocol manager that downloads the hash prefix updates. |
| 235 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; | 237 std::unique_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_; |
| 236 | 238 |
| 239 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_; |
| 240 |
| 237 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; | 241 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; |
| 238 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); | 242 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); |
| 239 }; // class V4LocalDatabaseManager | 243 }; // class V4LocalDatabaseManager |
| 240 | 244 |
| 241 } // namespace safe_browsing | 245 } // namespace safe_browsing |
| 242 | 246 |
| 243 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ | 247 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ |
| OLD | NEW |