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

Side by Side Diff: chrome/browser/safe_browsing/local_database_manager.h

Issue 1848973004: Makes V4UpdateProtocolManager auto-schedule update fetching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v4_01_
Patch Set: Delete v4_update_protocol_manager_ on IO thread stop. And fix BUILD.gn Created 4 years, 8 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Safe Browsing Database Manager implementation that manages a local 5 // Safe Browsing Database Manager implementation that manages a local
6 // database. This is used by Desktop Chromium. 6 // database. This is used by Desktop Chromium.
7 7
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_
9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ 9 #define CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_
10 10
(...skipping 10 matching lines...) Expand all
21 #include "base/gtest_prod_util.h" 21 #include "base/gtest_prod_util.h"
22 #include "base/macros.h" 22 #include "base/macros.h"
23 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
24 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
25 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
26 #include "base/synchronization/lock.h" 26 #include "base/synchronization/lock.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "chrome/browser/safe_browsing/protocol_manager.h" 28 #include "chrome/browser/safe_browsing/protocol_manager.h"
29 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 29 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
30 #include "components/safe_browsing_db/database_manager.h" 30 #include "components/safe_browsing_db/database_manager.h"
31 #include "components/safe_browsing_db/safebrowsing.pb.h"
31 #include "components/safe_browsing_db/util.h" 32 #include "components/safe_browsing_db/util.h"
33 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
34 #include "components/safe_browsing_db/v4_update_protocol_manager.h"
32 #include "url/gurl.h" 35 #include "url/gurl.h"
33 36
34 namespace net { 37 namespace net {
35 class URLRequestContext; 38 class URLRequestContext;
36 class URLRequestContextGetter; 39 class URLRequestContextGetter;
37 } 40 }
38 41
39 namespace safe_browsing { 42 namespace safe_browsing {
40 43
41 class SafeBrowsingService; 44 class SafeBrowsingService;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 std::vector<SBThreatType> url_results; 78 std::vector<SBThreatType> url_results;
76 std::vector<ThreatMetadata> url_metadata; 79 std::vector<ThreatMetadata> url_metadata;
77 std::vector<std::string> url_hit_hash; 80 std::vector<std::string> url_hit_hash;
78 std::vector<SBFullHash> full_hashes; 81 std::vector<SBFullHash> full_hashes;
79 std::vector<SBThreatType> full_hash_results; 82 std::vector<SBThreatType> full_hash_results;
80 83
81 SafeBrowsingDatabaseManager::Client* client; 84 SafeBrowsingDatabaseManager::Client* client;
82 bool is_extended_reporting; 85 bool is_extended_reporting;
83 bool need_get_hash; 86 bool need_get_hash;
84 base::TimeTicks start; // When check was sent to SB service. 87 base::TimeTicks start; // When check was sent to SB service.
85 ListType check_type; // See comment in constructor. 88 ListType check_type; // See comment in constructor.
86 std::vector<SBThreatType> expected_threats; 89 std::vector<SBThreatType> expected_threats;
87 std::vector<SBPrefix> prefix_hits; 90 std::vector<SBPrefix> prefix_hits;
88 std::vector<SBFullHashResult> cache_hits; 91 std::vector<SBFullHashResult> cache_hits;
89 92
90 // Invoke one of client's callbacks with these results. 93 // Invoke one of client's callbacks with these results.
91 void OnSafeBrowsingResult(); 94 void OnSafeBrowsingResult();
92 95
93 // Vends weak pointers for async callbacks on the IO thread, such as 96 // Vends weak pointers for async callbacks on the IO thread, such as
94 // timeout checks and replies from checks performed on the SB task runner. 97 // timeout checks and replies from checks performed on the SB task runner.
95 // TODO(lzheng): We should consider to use this time out check 98 // TODO(lzheng): We should consider to use this time out check
(...skipping 28 matching lines...) Expand all
124 bool CheckResourceUrl(const GURL& url, Client* client) override; 127 bool CheckResourceUrl(const GURL& url, Client* client) override;
125 bool MatchCsdWhitelistUrl(const GURL& url) override; 128 bool MatchCsdWhitelistUrl(const GURL& url) override;
126 bool MatchMalwareIP(const std::string& ip_address) override; 129 bool MatchMalwareIP(const std::string& ip_address) override;
127 bool MatchDownloadWhitelistUrl(const GURL& url) override; 130 bool MatchDownloadWhitelistUrl(const GURL& url) override;
128 bool MatchDownloadWhitelistString(const std::string& str) override; 131 bool MatchDownloadWhitelistString(const std::string& str) override;
129 bool MatchInclusionWhitelistUrl(const GURL& url) override; 132 bool MatchInclusionWhitelistUrl(const GURL& url) override;
130 bool MatchModuleWhitelistString(const std::string& str) override; 133 bool MatchModuleWhitelistString(const std::string& str) override;
131 bool IsMalwareKillSwitchOn() override; 134 bool IsMalwareKillSwitchOn() override;
132 bool IsCsdWhitelistKillSwitchOn() override; 135 bool IsCsdWhitelistKillSwitchOn() override;
133 void CancelCheck(Client* client) override; 136 void CancelCheck(Client* client) override;
134 void StartOnIOThread( 137 void StartOnIOThread(net::URLRequestContextGetter* request_context_getter,
135 net::URLRequestContextGetter* request_context_getter, 138 const V4ProtocolConfig& config) override;
136 const V4ProtocolConfig& config) override;
137 void StopOnIOThread(bool shutdown) override; 139 void StopOnIOThread(bool shutdown) override;
138 bool download_protection_enabled() const override; 140 bool download_protection_enabled() const override;
139 141
140 protected: 142 protected:
141 ~LocalSafeBrowsingDatabaseManager() override; 143 ~LocalSafeBrowsingDatabaseManager() override;
142 144
143 // protected for tests. 145 // protected for tests.
144 void NotifyDatabaseUpdateFinished(bool update_succeeded); 146 void NotifyDatabaseUpdateFinished(bool update_succeeded);
145 147
146 private: 148 private:
147 // Called on the IO thread when the SafeBrowsingProtocolManager has received 149 // Called on the IO thread when the SafeBrowsingProtocolManager has received
148 // the full hash results for prefix hits detected in the database. 150 // the full hash results for prefix hits detected in the database.
149 void HandleGetHashResults(SafeBrowsingCheck* check, 151 void HandleGetHashResults(SafeBrowsingCheck* check,
150 const std::vector<SBFullHashResult>& full_hashes, 152 const std::vector<SBFullHashResult>& full_hashes,
151 const base::TimeDelta& cache_lifetime); 153 const base::TimeDelta& cache_lifetime);
152 154
153 friend class base::RefCountedThreadSafe<LocalSafeBrowsingDatabaseManager>; 155 friend class base::RefCountedThreadSafe<LocalSafeBrowsingDatabaseManager>;
154 friend class SafeBrowsingServerTest; 156 friend class SafeBrowsingServerTest;
155 friend class SafeBrowsingServiceTest; 157 friend class SafeBrowsingServiceTest;
156 friend class SafeBrowsingServiceTestHelper; 158 friend class SafeBrowsingServiceTestHelper;
157 friend class LocalDatabaseManagerTest; 159 friend class LocalDatabaseManagerTest;
158 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, 160 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, GetUrlSeverestThreatType);
159 GetUrlSeverestThreatType);
160 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest, 161 FRIEND_TEST_ALL_PREFIXES(LocalDatabaseManagerTest,
161 ServiceStopWithPendingChecks); 162 ServiceStopWithPendingChecks);
162 163
163 typedef std::set<SafeBrowsingCheck*> CurrentChecks; 164 typedef std::set<SafeBrowsingCheck*> CurrentChecks;
164 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; 165 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors;
165 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; 166 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests;
166 167
167 // Clients that we've queued up for checking later once the database is ready. 168 // Clients that we've queued up for checking later once the database is ready.
168 struct QueuedCheck { 169 struct QueuedCheck {
169 QueuedCheck(const ListType check_type, 170 QueuedCheck(const ListType check_type,
(...skipping 17 matching lines...) Expand all
187 const std::vector<SBFullHashResult>& full_hashes); 188 const std::vector<SBFullHashResult>& full_hashes);
188 189
189 // Given a URL, compare all the possible host + path full hashes to the set of 190 // Given a URL, compare all the possible host + path full hashes to the set of
190 // provided full hashes. Returns the threat type of the severest matching 191 // provided full hashes. Returns the threat type of the severest matching
191 // result from |full_hashes|, or SAFE if none match. 192 // result from |full_hashes|, or SAFE if none match.
192 static SBThreatType GetUrlSeverestThreatType( 193 static SBThreatType GetUrlSeverestThreatType(
193 const GURL& url, 194 const GURL& url,
194 const std::vector<SBFullHashResult>& full_hashes, 195 const std::vector<SBFullHashResult>& full_hashes,
195 size_t* index); 196 size_t* index);
196 197
198 void UpdateRequestCompleted(const std::vector<ListUpdateResponse>& responses);
199
197 // Called to stop operations on the io_thread. This may be called multiple 200 // Called to stop operations on the io_thread. This may be called multiple
198 // times during the life of the DatabaseManager. Should be called on IO 201 // times during the life of the DatabaseManager. Should be called on IO
199 // thread. 202 // thread.
200 void DoStopOnIOThread(); 203 void DoStopOnIOThread();
201 204
202 // Returns whether |database_| exists and is accessible. 205 // Returns whether |database_| exists and is accessible.
203 bool DatabaseAvailable() const; 206 bool DatabaseAvailable() const;
204 207
205 // Called on the IO thread. If the database does not exist, queues up a call 208 // Called on the IO thread. If the database does not exist, queues up a call
206 // on the db thread to create it. Returns whether the database is available. 209 // on the db thread to create it. Returns whether the database is available.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // checks them. 252 // checks them.
250 void DatabaseLoadComplete(); 253 void DatabaseLoadComplete();
251 254
252 // Called on the database thread to add/remove chunks and host keys. 255 // Called on the database thread to add/remove chunks and host keys.
253 void AddDatabaseChunks( 256 void AddDatabaseChunks(
254 const std::string& list, 257 const std::string& list,
255 scoped_ptr<std::vector<scoped_ptr<SBChunkData>>> chunks, 258 scoped_ptr<std::vector<scoped_ptr<SBChunkData>>> chunks,
256 AddChunksCallback callback); 259 AddChunksCallback callback);
257 260
258 void DeleteDatabaseChunks( 261 void DeleteDatabaseChunks(
259 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes); 262 scoped_ptr<std::vector<SBChunkDelete>> chunk_deletes);
260 263
261 void NotifyClientBlockingComplete(Client* client, bool proceed); 264 void NotifyClientBlockingComplete(Client* client, bool proceed);
262 265
263 void DatabaseUpdateFinished(bool update_succeeded); 266 void DatabaseUpdateFinished(bool update_succeeded);
264 267
265 // Called on the db thread to close the database. See CloseDatabase(). 268 // Called on the db thread to close the database. See CloseDatabase().
266 void OnCloseDatabase(); 269 void OnCloseDatabase();
267 270
268 // Runs on the db thread to reset the database. We assume that resetting the 271 // Runs on the db thread to reset the database. We assume that resetting the
269 // database is a synchronous operation. 272 // database is a synchronous operation.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 376
374 // Indicates if we're in the midst of trying to close the database. If this 377 // Indicates if we're in the midst of trying to close the database. If this
375 // is true, nothing on the IO thread should access the database. 378 // is true, nothing on the IO thread should access the database.
376 bool closing_database_; 379 bool closing_database_;
377 380
378 std::deque<QueuedCheck> queued_checks_; 381 std::deque<QueuedCheck> queued_checks_;
379 382
380 // Timeout to use for safe browsing checks. 383 // Timeout to use for safe browsing checks.
381 base::TimeDelta check_timeout_; 384 base::TimeDelta check_timeout_;
382 385
386 // Stores the current status of the lists to download from the SafeBrowsing
387 // servers.
388 base::hash_map<UpdateListIdentifier, std::string> current_list_states_;
389
390 // The protocol manager that downloads the hash prefix updates.
391 scoped_ptr<V4UpdateProtocolManager> v4_update_protocol_manager_;
392
383 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager); 393 DISALLOW_COPY_AND_ASSIGN(LocalSafeBrowsingDatabaseManager);
384 }; // class LocalSafeBrowsingDatabaseManager 394 }; // class LocalSafeBrowsingDatabaseManager
385 395
386 } // namespace safe_browsing 396 } // namespace safe_browsing
387 397
388 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_ 398 #endif // CHROME_BROWSER_SAFE_BROWSING_LOCAL_DATABASE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698