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

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

Issue 11615011: Small modifications to safebrowsing code to make it simpler to add the extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compiler Created 7 years, 11 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 | Annotate | Revision Log
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 // The Safe Browsing service is responsible for downloading anti-phishing and 5 // The Safe Browsing service is responsible for downloading anti-phishing and
6 // anti-malware tables and checking urls against them. 6 // anti-malware tables and checking urls against them.
7 7
8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 9 #define CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
10 10
11 #include <deque> 11 #include <deque>
12 #include <map>
12 #include <set> 13 #include <set>
13 #include <string> 14 #include <string>
14 #include <vector> 15 #include <vector>
15 16
16 #include "base/callback.h" 17 #include "base/callback.h"
17 #include "base/hash_tables.h" 18 #include "base/hash_tables.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 20 #include "base/memory/scoped_ptr.h"
20 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
21 #include "base/time.h" 22 #include "base/time.h"
(...skipping 18 matching lines...) Expand all
40 class DownloadProtectionService; 41 class DownloadProtectionService;
41 } 42 }
42 43
43 // Construction needs to happen on the main thread. 44 // Construction needs to happen on the main thread.
44 class SafeBrowsingDatabaseManager 45 class SafeBrowsingDatabaseManager
45 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>, 46 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>,
46 public SafeBrowsingProtocolManagerDelegate { 47 public SafeBrowsingProtocolManagerDelegate {
47 public: 48 public:
48 class Client; 49 class Client;
49 50
50 // Bundle of SafeBrowsing state for one URL or hash prefix check. 51 // Bundle of SafeBrowsing state while performing a URL or hash prefix check.
51 struct SafeBrowsingCheck { 52 struct SafeBrowsingCheck {
52 SafeBrowsingCheck(); 53 // |check_type| should correspond to the type of item that is being checked,
54 // either a URL or a binary hash/URL. This is largely for accounting.
55 //
56 // NOTE: since we actually just query strings and are returned a threat
57 // type, this cannot be used to predict the response type (e.g. we can
58 // query the MALWARE list but may be given results for phishing).
59 explicit SafeBrowsingCheck(safe_browsing_util::ListType check_type);
Scott Hess - ex-Googler 2013/01/11 23:44:05 Have you talked to the server people about this?
not at google - send to devlin 2013/01/14 23:00:55 As discussed (err, I think) this is just for knowi
53 ~SafeBrowsingCheck(); 60 ~SafeBrowsingCheck();
54 61
55 // Either |urls| or |prefix| is used to lookup database. 62 // Either |urls| or |full_hashes| is used to lookup database.
56 std::vector<GURL> urls; 63 std::vector<GURL> urls;
57 scoped_ptr<SBFullHash> full_hash; 64 std::vector<SBFullHash> full_hashes;
65
66 // Results from either |urls| or |full_hashes|.
67 std::map<GURL, SBThreatType> url_threats;
68 std::map<SBFullHash, SBThreatType> full_hash_threats;
Scott Hess - ex-Googler 2013/01/11 23:44:05 Having these maps seems over-engineered. I think
not at google - send to devlin 2013/01/14 23:00:55 I like the vector<pair<>> one, but it's much simpl
58 69
59 Client* client; 70 Client* client;
60 bool need_get_hash; 71 bool need_get_hash;
61 base::TimeTicks start; // When check was sent to SB service. 72 base::TimeTicks start; // When check was sent to SB service.
62 SBThreatType threat_type; 73 safe_browsing_util::ListType check_type; // See comment in constructor.
63 bool is_download; // If this check for download url or hash.
64 std::vector<SBPrefix> prefix_hits; 74 std::vector<SBPrefix> prefix_hits;
65 std::vector<SBFullHashResult> full_hits; 75 std::vector<SBFullHashResult> full_hits;
66 76
67 // Vends weak pointers for TimeoutCallback(). If the response is 77 // Vends weak pointers for TimeoutCallback(). If the response is
68 // received before the timeout fires, factory is destructed and 78 // received before the timeout fires, factory is destructed and
69 // the timeout won't be fired. 79 // the timeout won't be fired.
70 // TODO(lzheng): We should consider to use this time out check 80 // TODO(lzheng): We should consider to use this time out check
71 // for browsing too (instead of implementin in 81 // for browsing too (instead of implementin in
72 // safe_browsing_resource_handler.cc). 82 // safe_browsing_resource_handler.cc).
73 scoped_ptr<base::WeakPtrFactory< 83 scoped_ptr<base::WeakPtrFactory<
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 friend class SafeBrowsingServerTest; 191 friend class SafeBrowsingServerTest;
182 friend class SafeBrowsingServiceTest; 192 friend class SafeBrowsingServiceTest;
183 friend class SafeBrowsingServiceTestHelper; 193 friend class SafeBrowsingServiceTestHelper;
184 194
185 typedef std::set<SafeBrowsingCheck*> CurrentChecks; 195 typedef std::set<SafeBrowsingCheck*> CurrentChecks;
186 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; 196 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors;
187 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; 197 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests;
188 198
189 // Clients that we've queued up for checking later once the database is ready. 199 // Clients that we've queued up for checking later once the database is ready.
190 struct QueuedCheck { 200 struct QueuedCheck {
201 safe_browsing_util::ListType check_type;
191 Client* client; 202 Client* client;
192 GURL url; 203 GURL url;
193 base::TimeTicks start; // When check was queued. 204 base::TimeTicks start; // When check was queued.
194 }; 205 };
195 206
196 // Called to stop operations on the io_thread. This may be called multiple 207 // Called to stop operations on the io_thread. This may be called multiple
197 // times during the life of the DatabaseManager. Should be called on IO 208 // times during the life of the DatabaseManager. Should be called on IO
198 // thread. 209 // thread.
199 void DoStopOnIOThread(); 210 void DoStopOnIOThread();
200 211
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes. 299 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes.
289 void CheckDownloadUrlDone(SafeBrowsingCheck* check); 300 void CheckDownloadUrlDone(SafeBrowsingCheck* check);
290 301
291 // Calls the Client's callback on IO thread after CheckDownloadHash finishes. 302 // Calls the Client's callback on IO thread after CheckDownloadHash finishes.
292 void CheckDownloadHashDone(SafeBrowsingCheck* check); 303 void CheckDownloadHashDone(SafeBrowsingCheck* check);
293 304
294 // Helper function that calls safe browsing client and cleans up |checks_|. 305 // Helper function that calls safe browsing client and cleans up |checks_|.
295 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); 306 void SafeBrowsingCheckDone(SafeBrowsingCheck* check);
296 307
297 // Helper function to set |check| with default values and start a safe 308 // Helper function to set |check| with default values and start a safe
298 // browsing check with timeout of |timeout_ms|. |task| will be called upon 309 // browsing check with timeout of |timeout|. |task| will be called on
299 // success, otherwise TimeoutCallback will be called. 310 // success, otherwise TimeoutCallback will be called.
300 void StartDownloadCheck(SafeBrowsingCheck* check, 311 void StartSafeBrowsingCheck(SafeBrowsingCheck* check,
301 Client* client, 312 Client* client,
302 const base::Closure& task, 313 const base::Closure& task,
303 int64 timeout_ms); 314 const base::TimeDelta& timeout);
304 315
305 // SafeBrowsingProtocolManageDelegate override 316 // SafeBrowsingProtocolManageDelegate override
306 virtual void ResetDatabase() OVERRIDE; 317 virtual void ResetDatabase() OVERRIDE;
307 virtual void UpdateStarted() OVERRIDE; 318 virtual void UpdateStarted() OVERRIDE;
308 virtual void UpdateFinished(bool success) OVERRIDE; 319 virtual void UpdateFinished(bool success) OVERRIDE;
309 virtual void GetChunks(GetChunksCallback callback) OVERRIDE; 320 virtual void GetChunks(GetChunksCallback callback) OVERRIDE;
310 virtual void AddChunks(const std::string& list, SBChunkList* chunks, 321 virtual void AddChunks(const std::string& list, SBChunkList* chunks,
311 AddChunksCallback callback) OVERRIDE; 322 AddChunksCallback callback) OVERRIDE;
312 virtual void DeleteChunks( 323 virtual void DeleteChunks(
313 std::vector<SBChunkDelete>* delete_chunks) OVERRIDE; 324 std::vector<SBChunkDelete>* delete_chunks) OVERRIDE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 bool database_update_in_progress_; 367 bool database_update_in_progress_;
357 368
358 // Indicates if we're in the midst of trying to close the database. If this 369 // Indicates if we're in the midst of trying to close the database. If this
359 // is true, nothing on the IO thread should access the database. 370 // is true, nothing on the IO thread should access the database.
360 bool closing_database_; 371 bool closing_database_;
361 372
362 std::deque<QueuedCheck> queued_checks_; 373 std::deque<QueuedCheck> queued_checks_;
363 374
364 // When download url check takes this long, client's callback will be called 375 // When download url check takes this long, client's callback will be called
365 // without waiting for the result. 376 // without waiting for the result.
366 int64 download_urlcheck_timeout_ms_; 377 base::TimeDelta download_url_check_timeout_;
367 378
368 // Similar to |download_urlcheck_timeout_ms_|, but for download hash checks. 379 // Similar to |download_urlcheck_timeout_| but for download hash checks.
369 int64 download_hashcheck_timeout_ms_; 380 base::TimeDelta download_hash_check_timeout_;
381
382 // Similar to |download_urlcheck_timeout_| but for extension ID checks.
383 base::TimeDelta extension_id_check_timeout_;
370 384
371 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager); 385 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseManager);
372 }; 386 };
373 387
374 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_ 388 #endif // CHROME_BROWSER_SAFE_BROWSING_DATABASE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698