Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager.h

Issue 2450633003: Small: Implement CheckDownloadUrls -- not called yet. (Closed)
Patch Set: Remove histograms change. Will send that as a separate CL. Remove an unused variable. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_local_database_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 {
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 should always be the last value. 86 // This represents the case when we're trying to determine if any of the
87 CHECK_MAX 87 // URLs in a vector of URLs is unsafe for downloading binaries.
88 CHECK_DOWNLOAD_URLS = 1,
88 }; 89 };
89 90
90 // The information we need to process a URL safety reputation request and 91 // The information we need to process a URL safety reputation request and
91 // respond to the SafeBrowsing client that asked for it. 92 // respond to the SafeBrowsing client that asked for it.
92 // TODO(vakh): In its current form, it only includes information for 93 // TODO(vakh): In its current form, it only includes information for
93 // |CheckBrowseUrl| method. Extend it to serve other methods on |client|. 94 // |CheckBrowseUrl| and |CheckDownloadUrl| methods. Extend it to serve other
95 // methods on |client|.
94 struct PendingCheck { 96 struct PendingCheck {
95 PendingCheck(Client* client, 97 PendingCheck(Client* client,
96 ClientCallbackType client_callback_type, 98 ClientCallbackType client_callback_type,
97 const StoresToCheck& stores_to_check, 99 const StoresToCheck& stores_to_check,
98 const GURL& url); 100 const std::vector<GURL>& urls);
99 101
100 ~PendingCheck(); 102 ~PendingCheck();
101 103
102 // The SafeBrowsing client that's waiting for the safe/unsafe verdict. 104 // The SafeBrowsing client that's waiting for the safe/unsafe verdict.
103 Client* client; 105 Client* client;
104 106
105 // Determines which funtion from the |client| needs to be called once we 107 // Determines which funtion from the |client| needs to be called once we
106 // know whether the URL in |url| is safe or unsafe. 108 // know whether the URL in |url| is safe or unsafe.
107 ClientCallbackType client_callback_type; 109 const ClientCallbackType client_callback_type;
108 110
109 // The threat verdict for the URL being checked. 111 // The threat verdict for the URL being checked.
110 SBThreatType result_threat_type; 112 SBThreatType result_threat_type;
111 113
112 // When the check was sent to the SafeBrowsing service. Used to record the 114 // 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 115 // time it takes to get the uncached full hashes from the service (or a
114 // cached full hash response). 116 // cached full hash response).
115 base::TimeTicks full_hash_check_start; 117 base::TimeTicks full_hash_check_start;
116 118
117 // The SafeBrowsing lists to check hash prefixes in. 119 // The SafeBrowsing lists to check hash prefixes in.
118 StoresToCheck stores_to_check; 120 const StoresToCheck stores_to_check;
119 121
120 // The URL that is being checked for being unsafe. 122 // The URLs that are being checked for being unsafe.
121 GURL url; 123 const std::vector<GURL> urls;
122 124
123 // The metadata associated with the full hash of the severest match found 125 // The metadata associated with the full hash of the severest match found
124 // for that URL. 126 // for that URL.
125 ThreatMetadata url_metadata; 127 ThreatMetadata url_metadata;
126 }; 128 };
127 129
128 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks; 130 typedef std::vector<std::unique_ptr<PendingCheck>> QueuedChecks;
129 131
130 // The stores/lists to always get full hashes for, regardless of which store 132 // The stores/lists to always get full hashes for, regardless of which store
131 // the hash prefix matched. 133 // the hash prefix matched.
132 StoresToCheck GetStoresForFullHashRequests() override; 134 StoresToCheck GetStoresForFullHashRequests() override;
133 135
134 private: 136 private:
135 friend class V4LocalDatabaseManagerTest; 137 friend class V4LocalDatabaseManagerTest;
136 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest, 138 FRIEND_TEST_ALL_PREFIXES(V4LocalDatabaseManagerTest,
137 TestGetSeverestThreatTypeAndMetadata); 139 TestGetSeverestThreatTypeAndMetadata);
138 140
139 // The set of clients awaiting a full hash response. It is used for tracking 141 // The set of clients awaiting a full hash response. It is used for tracking
140 // which clients have cancelled their outstanding request. 142 // which clients have cancelled their outstanding request.
141 typedef std::unordered_set<Client*> PendingClients; 143 typedef std::unordered_set<const Client*> PendingClients;
142 144
143 // Called when all the stores managed by the database have been read from 145 // 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 146 // disk after startup and the database is ready for checking resource
145 // reputation. 147 // reputation.
146 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database); 148 void DatabaseReadyForChecks(std::unique_ptr<V4Database> v4_database);
147 149
148 // Called when all the stores managed by the database have been verified for 150 // 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 151 // checksum correctness after startup and the database is ready for applying
150 // updates. 152 // updates.
151 void DatabaseReadyForUpdates( 153 void DatabaseReadyForUpdates(
(...skipping 11 matching lines...) Expand all
163 // Finds the most severe |SBThreatType| and the corresponding |metadata| from 165 // Finds the most severe |SBThreatType| and the corresponding |metadata| from
164 // |full_hash_infos|. 166 // |full_hash_infos|.
165 void GetSeverestThreatTypeAndMetadata( 167 void GetSeverestThreatTypeAndMetadata(
166 SBThreatType* result_threat_type, 168 SBThreatType* result_threat_type,
167 ThreatMetadata* metadata, 169 ThreatMetadata* metadata,
168 const std::vector<FullHashInfo>& full_hash_infos); 170 const std::vector<FullHashInfo>& full_hash_infos);
169 171
170 // Returns the SBThreatType for a given ListIdentifier. 172 // Returns the SBThreatType for a given ListIdentifier.
171 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id); 173 SBThreatType GetSBThreatTypeForList(const ListIdentifier& list_id);
172 174
175 // Queues the check for async response if the database isn't ready yet.
176 // If the database is ready, checks the database for prefix matches and
177 // returns true immediately if there's no match. If a match is found, it
178 // schedules a task to perform full hash check and returns false.
179 bool HandleCheck(std::unique_ptr<PendingCheck> check);
180
173 // Called when the |v4_get_hash_protocol_manager_| has the full hash response 181 // 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 182 // available for the URL that we requested. It determines the severest
175 // threat type and responds to the |client| with that information. 183 // threat type and responds to the |client| with that information.
176 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check, 184 void OnFullHashResponse(std::unique_ptr<PendingCheck> pending_check,
177 const std::vector<FullHashInfo>& full_hash_infos); 185 const std::vector<FullHashInfo>& full_hash_infos);
178 186
179 // Performs the full hash checking of the URL in |check|. 187 // Performs the full hash checking of the URL in |check|.
180 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, 188 virtual void PerformFullHashCheck(std::unique_ptr<PendingCheck> check,
181 const FullHashToStoreAndHashPrefixesMap& 189 const FullHashToStoreAndHashPrefixesMap&
182 full_hash_to_store_and_hash_prefixes); 190 full_hash_to_store_and_hash_prefixes);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 251
244 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_; 252 base::WeakPtrFactory<V4LocalDatabaseManager> weak_factory_;
245 253
246 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>; 254 friend class base::RefCountedThreadSafe<V4LocalDatabaseManager>;
247 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager); 255 DISALLOW_COPY_AND_ASSIGN(V4LocalDatabaseManager);
248 }; // class V4LocalDatabaseManager 256 }; // class V4LocalDatabaseManager
249 257
250 } // namespace safe_browsing 258 } // namespace safe_browsing
251 259
252 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_ 260 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_LOCAL_DATABASE_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_local_database_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698