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

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: cleanup Created 8 years 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 19 matching lines...) Expand all
41 class DownloadProtectionService; 42 class DownloadProtectionService;
42 } 43 }
43 44
44 // Construction needs to happen on the main thread. 45 // Construction needs to happen on the main thread.
45 class SafeBrowsingDatabaseManager 46 class SafeBrowsingDatabaseManager
46 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>, 47 : public base::RefCountedThreadSafe<SafeBrowsingDatabaseManager>,
47 public SafeBrowsingProtocolManagerDelegate { 48 public SafeBrowsingProtocolManagerDelegate {
48 public: 49 public:
49 class Client; 50 class Client;
50 51
51 // Bundle of SafeBrowsing state for one URL or hash prefix check. 52 // Bundle of SafeBrowsing state while performing a URL or hash prefix check.
52 struct SafeBrowsingCheck { 53 struct SafeBrowsingCheck {
53 SafeBrowsingCheck(); 54 // |check_type| should correspond to the type of item that is being checked,
55 // either a URL or a binary hash/URL. This is largely for accounting.
56 //
57 // NOTE: since we actually just query strings and are returned a threat
58 // type, this cannot be used to predict the response type (e.g. we can
59 // query the MALWARE list but may be given results for phishing).
60 explicit SafeBrowsingCheck(safe_browsing_util::ListType check_type);
54 ~SafeBrowsingCheck(); 61 ~SafeBrowsingCheck();
55 62
56 // Either |urls| or |prefix| is used to lookup database. 63 // Either |urls| or |full_hashes| is used to lookup database.
57 std::vector<GURL> urls; 64 std::vector<GURL> urls;
58 scoped_ptr<SBFullHash> full_hash; 65 std::vector<SBFullHash> full_hashes;
66
67 // Results from either |urls| or |full_hashes|.
68 std::map<GURL, SBThreatType> url_threats;
69 std::map<SBFullHash, SBThreatType> full_hash_threats;
not at google - send to devlin 2012/12/18 00:48:46 Needed because extensions will be checking multipl
Scott Hess - ex-Googler 2013/01/11 23:44:05 I haven't gotten far enough to see why this would
not at google - send to devlin 2013/01/14 23:00:55 Done.
59 70
60 Client* client; 71 Client* client;
61 bool need_get_hash; 72 bool need_get_hash;
62 base::TimeTicks start; // When check was sent to SB service. 73 base::TimeTicks start; // When check was sent to SB service.
63 SBThreatType threat_type; 74 safe_browsing_util::ListType check_type; // See comment in constructor.
not at google - send to devlin 2012/12/18 00:48:46 Needed because it's not just URL or download anymo
64 bool is_download; // If this check for download url or hash.
65 std::vector<SBPrefix> prefix_hits; 75 std::vector<SBPrefix> prefix_hits;
66 std::vector<SBFullHashResult> full_hits; 76 std::vector<SBFullHashResult> full_hits;
67 77
68 // Vends weak pointers for TimeoutCallback(). If the response is 78 // Vends weak pointers for TimeoutCallback(). If the response is
69 // received before the timeout fires, factory is destructed and 79 // received before the timeout fires, factory is destructed and
70 // the timeout won't be fired. 80 // the timeout won't be fired.
71 // TODO(lzheng): We should consider to use this time out check 81 // TODO(lzheng): We should consider to use this time out check
72 // for browsing too (instead of implementin in 82 // for browsing too (instead of implementin in
73 // safe_browsing_resource_handler.cc). 83 // safe_browsing_resource_handler.cc).
74 scoped_ptr<base::WeakPtrFactory< 84 scoped_ptr<base::WeakPtrFactory<
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 friend class SafeBrowsingServerTest; 192 friend class SafeBrowsingServerTest;
183 friend class SafeBrowsingServiceTest; 193 friend class SafeBrowsingServiceTest;
184 friend class SafeBrowsingServiceTestHelper; 194 friend class SafeBrowsingServiceTestHelper;
185 195
186 typedef std::set<SafeBrowsingCheck*> CurrentChecks; 196 typedef std::set<SafeBrowsingCheck*> CurrentChecks;
187 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors; 197 typedef std::vector<SafeBrowsingCheck*> GetHashRequestors;
188 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests; 198 typedef base::hash_map<SBPrefix, GetHashRequestors> GetHashRequests;
189 199
190 // Clients that we've queued up for checking later once the database is ready. 200 // Clients that we've queued up for checking later once the database is ready.
191 struct QueuedCheck { 201 struct QueuedCheck {
202 safe_browsing_util::ListType check_type;
192 Client* client; 203 Client* client;
193 GURL url; 204 GURL url;
194 base::TimeTicks start; // When check was queued. 205 base::TimeTicks start; // When check was queued.
195 }; 206 };
196 207
197 // Called to stop operations on the io_thread. This may be called multiple 208 // 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 209 // times during the life of the DatabaseManager. Should be called on IO
199 // thread. 210 // thread.
200 void DoStopOnIOThread(); 211 void DoStopOnIOThread();
201 212
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes. 300 // Calls the Client's callback on IO thread after CheckDownloadUrl finishes.
290 void CheckDownloadUrlDone(SafeBrowsingCheck* check); 301 void CheckDownloadUrlDone(SafeBrowsingCheck* check);
291 302
292 // Calls the Client's callback on IO thread after CheckDownloadHash finishes. 303 // Calls the Client's callback on IO thread after CheckDownloadHash finishes.
293 void CheckDownloadHashDone(SafeBrowsingCheck* check); 304 void CheckDownloadHashDone(SafeBrowsingCheck* check);
294 305
295 // Helper function that calls safe browsing client and cleans up |checks_|. 306 // Helper function that calls safe browsing client and cleans up |checks_|.
296 void SafeBrowsingCheckDone(SafeBrowsingCheck* check); 307 void SafeBrowsingCheckDone(SafeBrowsingCheck* check);
297 308
298 // Helper function to set |check| with default values and start a safe 309 // Helper function to set |check| with default values and start a safe
299 // browsing check with timeout of |timeout_ms|. |task| will be called upon 310 // browsing check with timeout of |timeout|. |task| will be called on
300 // success, otherwise TimeoutCallback will be called. 311 // success, otherwise TimeoutCallback will be called.
301 void StartDownloadCheck(SafeBrowsingCheck* check, 312 void StartSafeBrowsingCheck(SafeBrowsingCheck* check,
302 Client* client, 313 Client* client,
303 const base::Closure& task, 314 const base::Closure& task,
304 int64 timeout_ms); 315 const base::TimeDelta& timeout);
305 316
306 // SafeBrowsingProtocolManageDelegate override 317 // SafeBrowsingProtocolManageDelegate override
307 virtual void ResetDatabase() OVERRIDE; 318 virtual void ResetDatabase() OVERRIDE;
308 virtual void UpdateStarted() OVERRIDE; 319 virtual void UpdateStarted() OVERRIDE;
309 virtual void UpdateFinished(bool success) OVERRIDE; 320 virtual void UpdateFinished(bool success) OVERRIDE;
310 virtual void GetChunks(GetChunksCallback callback) OVERRIDE; 321 virtual void GetChunks(GetChunksCallback callback) OVERRIDE;
311 virtual void AddChunks(const std::string& list, SBChunkList* chunks) OVERRIDE; 322 virtual void AddChunks(const std::string& list, SBChunkList* chunks) OVERRIDE;
312 virtual void DeleteChunks( 323 virtual void DeleteChunks(
313 std::vector<SBChunkDelete>* delete_chunks) OVERRIDE; 324 std::vector<SBChunkDelete>* delete_chunks) OVERRIDE;
314 325
(...skipping 41 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_;
not at google - send to devlin 2012/12/18 00:48:46 Cleanup.
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