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

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

Issue 1420053005: Move code in components/safe_browsing_db and chrome/browser/s_b/ under the safe_browsing namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@02_components_move
Patch Set: CR feedback. Remove using from *.h Created 5 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
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 #include "chrome/browser/safe_browsing/local_database_manager.h" 5 #include "chrome/browser/safe_browsing/local_database_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/common/chrome_paths.h" 32 #include "chrome/common/chrome_paths.h"
33 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "components/safe_browsing_db/util.h" 35 #include "components/safe_browsing_db/util.h"
36 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "url/url_constants.h" 38 #include "url/url_constants.h"
39 39
40 using content::BrowserThread; 40 using content::BrowserThread;
41 41
42 namespace safe_browsing {
43
42 namespace { 44 namespace {
43 45
44 // Timeout for match checks, e.g. download URLs, hashes. 46 // Timeout for match checks, e.g. download URLs, hashes.
45 const int kCheckTimeoutMs = 10000; 47 const int kCheckTimeoutMs = 10000;
46 48
47 // Records disposition information about the check. |hit| should be 49 // Records disposition information about the check. |hit| should be
48 // |true| if there were any prefix hits in |full_hashes|. 50 // |true| if there were any prefix hits in |full_hashes|.
49 void RecordGetHashCheckStatus( 51 void RecordGetHashCheckStatus(
50 bool hit, 52 bool hit,
51 safe_browsing::ListType check_type, 53 ListType check_type,
52 const std::vector<SBFullHashResult>& full_hashes) { 54 const std::vector<SBFullHashResult>& full_hashes) {
53 SafeBrowsingProtocolManager::ResultType result; 55 SafeBrowsingProtocolManager::ResultType result;
54 if (full_hashes.empty()) { 56 if (full_hashes.empty()) {
55 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY; 57 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_EMPTY;
56 } else if (hit) { 58 } else if (hit) {
57 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT; 59 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_HIT;
58 } else { 60 } else {
59 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS; 61 result = SafeBrowsingProtocolManager::GET_HASH_FULL_HASH_MISS;
60 } 62 }
61 bool is_download = check_type == safe_browsing::BINURL; 63 bool is_download = check_type == BINURL;
62 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result); 64 SafeBrowsingProtocolManager::RecordGetHashResult(is_download, result);
63 } 65 }
64 66
65 bool IsExpectedThreat( 67 bool IsExpectedThreat(
66 const SBThreatType threat_type, 68 const SBThreatType threat_type,
67 const std::vector<SBThreatType>& expected_threats) { 69 const std::vector<SBThreatType>& expected_threats) {
68 return expected_threats.end() != std::find(expected_threats.begin(), 70 return expected_threats.end() != std::find(expected_threats.begin(),
69 expected_threats.end(), 71 expected_threats.end(),
70 threat_type); 72 threat_type);
71 } 73 }
72 74
73 // Return the severest list id from the results in |full_hashes| which matches 75 // Return the severest list id from the results in |full_hashes| which matches
74 // |hash|, or INVALID if none match. 76 // |hash|, or INVALID if none match.
75 safe_browsing::ListType GetHashSeverestThreatListType( 77 ListType GetHashSeverestThreatListType(
76 const SBFullHash& hash, 78 const SBFullHash& hash,
77 const std::vector<SBFullHashResult>& full_hashes, 79 const std::vector<SBFullHashResult>& full_hashes,
78 size_t* index) { 80 size_t* index) {
79 safe_browsing::ListType pending_threat = safe_browsing::INVALID; 81 ListType pending_threat = INVALID;
80 for (size_t i = 0; i < full_hashes.size(); ++i) { 82 for (size_t i = 0; i < full_hashes.size(); ++i) {
81 if (safe_browsing::SBFullHashEqual(hash, full_hashes[i].hash)) { 83 if (SBFullHashEqual(hash, full_hashes[i].hash)) {
82 const safe_browsing::ListType threat = 84 const ListType threat =
83 static_cast<safe_browsing::ListType>(full_hashes[i].list_id); 85 static_cast<ListType>(full_hashes[i].list_id);
84 switch (threat) { 86 switch (threat) {
85 case safe_browsing::INVALID: 87 case INVALID:
86 // |full_hashes| should never contain INVALID as a |list_id|. 88 // |full_hashes| should never contain INVALID as a |list_id|.
87 NOTREACHED(); 89 NOTREACHED();
88 break; 90 break;
89 case safe_browsing::MALWARE: // Falls through. 91 case MALWARE: // Falls through.
90 case safe_browsing::PHISH: // Falls through. 92 case PHISH: // Falls through.
91 case safe_browsing::BINURL: // Falls through. 93 case BINURL: // Falls through.
92 case safe_browsing::CSDWHITELIST: // Falls through. 94 case CSDWHITELIST: // Falls through.
93 case safe_browsing::DOWNLOADWHITELIST: // Falls through. 95 case DOWNLOADWHITELIST: // Falls through.
94 case safe_browsing::INCLUSIONWHITELIST: // Falls through. 96 case INCLUSIONWHITELIST: // Falls through.
95 case safe_browsing::EXTENSIONBLACKLIST: // Falls through. 97 case EXTENSIONBLACKLIST: // Falls through.
96 case safe_browsing::IPBLACKLIST: 98 case IPBLACKLIST:
97 if (index) 99 if (index)
98 *index = i; 100 *index = i;
99 return threat; 101 return threat;
100 case safe_browsing::UNWANTEDURL: 102 case UNWANTEDURL:
101 // UNWANTEDURL is considered less severe than other threats, keep 103 // UNWANTEDURL is considered less severe than other threats, keep
102 // looking. 104 // looking.
103 pending_threat = threat; 105 pending_threat = threat;
104 if (index) 106 if (index)
105 *index = i; 107 *index = i;
106 break; 108 break;
107 } 109 }
108 } 110 }
109 } 111 }
110 return pending_threat; 112 return pending_threat;
111 } 113 }
112 114
113 // Given a URL, compare all the possible host + path full hashes to the set of 115 // Given a URL, compare all the possible host + path full hashes to the set of
114 // provided full hashes. Returns the list id of the severest matching result 116 // provided full hashes. Returns the list id of the severest matching result
115 // from |full_hashes|, or INVALID if none match. 117 // from |full_hashes|, or INVALID if none match.
116 safe_browsing::ListType GetUrlSeverestThreatListType( 118 ListType GetUrlSeverestThreatListType(
117 const GURL& url, 119 const GURL& url,
118 const std::vector<SBFullHashResult>& full_hashes, 120 const std::vector<SBFullHashResult>& full_hashes,
119 size_t* index) { 121 size_t* index) {
120 if (full_hashes.empty()) 122 if (full_hashes.empty())
121 return safe_browsing::INVALID; 123 return INVALID;
122 124
123 std::vector<std::string> patterns; 125 std::vector<std::string> patterns;
124 safe_browsing::GeneratePatternsToCheck(url, &patterns); 126 GeneratePatternsToCheck(url, &patterns);
125 127
126 safe_browsing::ListType pending_threat = safe_browsing::INVALID; 128 ListType pending_threat = INVALID;
127 for (size_t i = 0; i < patterns.size(); ++i) { 129 for (size_t i = 0; i < patterns.size(); ++i) {
128 safe_browsing::ListType threat = GetHashSeverestThreatListType( 130 ListType threat = GetHashSeverestThreatListType(
129 safe_browsing::SBFullHashForString(patterns[i]), full_hashes, index); 131 SBFullHashForString(patterns[i]), full_hashes, index);
130 switch (threat) { 132 switch (threat) {
131 case safe_browsing::INVALID: 133 case INVALID:
132 // Ignore patterns with no matching threat. 134 // Ignore patterns with no matching threat.
133 break; 135 break;
134 case safe_browsing::MALWARE: // Falls through. 136 case MALWARE: // Falls through.
135 case safe_browsing::PHISH: // Falls through. 137 case PHISH: // Falls through.
136 case safe_browsing::BINURL: // Falls through. 138 case BINURL: // Falls through.
137 case safe_browsing::CSDWHITELIST: // Falls through. 139 case CSDWHITELIST: // Falls through.
138 case safe_browsing::DOWNLOADWHITELIST: // Falls through. 140 case DOWNLOADWHITELIST: // Falls through.
139 case safe_browsing::INCLUSIONWHITELIST: // Falls through. 141 case INCLUSIONWHITELIST: // Falls through.
140 case safe_browsing::EXTENSIONBLACKLIST: // Falls through. 142 case EXTENSIONBLACKLIST: // Falls through.
141 case safe_browsing::IPBLACKLIST: 143 case IPBLACKLIST:
142 return threat; 144 return threat;
143 case safe_browsing::UNWANTEDURL: 145 case UNWANTEDURL:
144 // UNWANTEDURL is considered less severe than other threats, keep 146 // UNWANTEDURL is considered less severe than other threats, keep
145 // looking. 147 // looking.
146 pending_threat = threat; 148 pending_threat = threat;
147 break; 149 break;
148 } 150 }
149 } 151 }
150 return pending_threat; 152 return pending_threat;
151 } 153 }
152 154
153 SBThreatType GetThreatTypeFromListType(safe_browsing::ListType list_type) { 155 SBThreatType GetThreatTypeFromListType(
156 ListType list_type) {
mattm 2015/11/12 00:36:05 formatting
vakh (old account. dont use) 2015/11/12 09:27:42 Done.
154 switch (list_type) { 157 switch (list_type) {
155 case safe_browsing::PHISH: 158 case PHISH:
156 return SB_THREAT_TYPE_URL_PHISHING; 159 return SB_THREAT_TYPE_URL_PHISHING;
157 case safe_browsing::MALWARE: 160 case MALWARE:
158 return SB_THREAT_TYPE_URL_MALWARE; 161 return SB_THREAT_TYPE_URL_MALWARE;
159 case safe_browsing::UNWANTEDURL: 162 case UNWANTEDURL:
160 return SB_THREAT_TYPE_URL_UNWANTED; 163 return SB_THREAT_TYPE_URL_UNWANTED;
161 case safe_browsing::BINURL: 164 case BINURL:
162 return SB_THREAT_TYPE_BINARY_MALWARE_URL; 165 return SB_THREAT_TYPE_BINARY_MALWARE_URL;
163 case safe_browsing::EXTENSIONBLACKLIST: 166 case EXTENSIONBLACKLIST:
164 return SB_THREAT_TYPE_EXTENSION; 167 return SB_THREAT_TYPE_EXTENSION;
165 default: 168 default:
166 DVLOG(1) << "Unknown safe browsing list id " << list_type; 169 DVLOG(1) << "Unknown safe browsing list id " << list_type;
167 return SB_THREAT_TYPE_SAFE; 170 return SB_THREAT_TYPE_SAFE;
168 } 171 }
169 } 172 }
170 173
171 } // namespace 174 } // namespace
172 175
173 // static 176 // static
(...skipping 10 matching lines...) Expand all
184 const std::vector<SBFullHashResult>& full_hashes, 187 const std::vector<SBFullHashResult>& full_hashes,
185 size_t* index) { 188 size_t* index) {
186 return GetThreatTypeFromListType( 189 return GetThreatTypeFromListType(
187 GetUrlSeverestThreatListType(url, full_hashes, index)); 190 GetUrlSeverestThreatListType(url, full_hashes, index));
188 } 191 }
189 192
190 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck( 193 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::SafeBrowsingCheck(
191 const std::vector<GURL>& urls, 194 const std::vector<GURL>& urls,
192 const std::vector<SBFullHash>& full_hashes, 195 const std::vector<SBFullHash>& full_hashes,
193 Client* client, 196 Client* client,
194 safe_browsing::ListType check_type, 197 ListType check_type,
195 const std::vector<SBThreatType>& expected_threats) 198 const std::vector<SBThreatType>& expected_threats)
196 : urls(urls), 199 : urls(urls),
197 url_results(urls.size(), SB_THREAT_TYPE_SAFE), 200 url_results(urls.size(), SB_THREAT_TYPE_SAFE),
198 url_metadata(urls.size()), 201 url_metadata(urls.size()),
199 full_hashes(full_hashes), 202 full_hashes(full_hashes),
200 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE), 203 full_hash_results(full_hashes.size(), SB_THREAT_TYPE_SAFE),
201 client(client), 204 client(client),
202 need_get_hash(false), 205 need_get_hash(false),
203 check_type(check_type), 206 check_type(check_type),
204 expected_threats(expected_threats) { 207 expected_threats(expected_threats) {
205 DCHECK_EQ(urls.empty(), !full_hashes.empty()) 208 DCHECK_EQ(urls.empty(), !full_hashes.empty())
206 << "Exactly one of urls and full_hashes must be set"; 209 << "Exactly one of urls and full_hashes must be set";
207 } 210 }
208 211
209 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() { 212 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::~SafeBrowsingCheck() {
210 } 213 }
211 214
212 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck:: 215 void LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck::
213 OnSafeBrowsingResult() { 216 OnSafeBrowsingResult() {
214 DCHECK_CURRENTLY_ON(BrowserThread::IO); 217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
215 218
216 DCHECK(client); 219 DCHECK(client);
217 DCHECK_EQ(urls.size(), url_results.size()); 220 DCHECK_EQ(urls.size(), url_results.size());
218 DCHECK_EQ(full_hashes.size(), full_hash_results.size()); 221 DCHECK_EQ(full_hashes.size(), full_hash_results.size());
219 if (!urls.empty()) { 222 if (!urls.empty()) {
220 DCHECK(full_hashes.empty()); 223 DCHECK(full_hashes.empty());
221 switch (check_type) { 224 switch (check_type) {
222 case safe_browsing::MALWARE: 225 case MALWARE:
223 case safe_browsing::PHISH: 226 case PHISH:
224 case safe_browsing::UNWANTEDURL: 227 case UNWANTEDURL:
225 DCHECK_EQ(1u, urls.size()); 228 DCHECK_EQ(1u, urls.size());
226 client->OnCheckBrowseUrlResult(urls[0], url_results[0], 229 client->OnCheckBrowseUrlResult(urls[0], url_results[0],
227 url_metadata[0]); 230 url_metadata[0]);
228 break; 231 break;
229 case safe_browsing::BINURL: 232 case BINURL:
230 DCHECK_EQ(urls.size(), url_results.size()); 233 DCHECK_EQ(urls.size(), url_results.size());
231 client->OnCheckDownloadUrlResult( 234 client->OnCheckDownloadUrlResult(
232 urls, *std::max_element(url_results.begin(), url_results.end())); 235 urls, *std::max_element(url_results.begin(), url_results.end()));
233 break; 236 break;
234 default: 237 default:
235 NOTREACHED(); 238 NOTREACHED();
236 } 239 }
237 } else if (!full_hashes.empty()) { 240 } else if (!full_hashes.empty()) {
238 switch (check_type) { 241 switch (check_type) {
239 case safe_browsing::EXTENSIONBLACKLIST: { 242 case EXTENSIONBLACKLIST: {
240 std::set<std::string> unsafe_extension_ids; 243 std::set<std::string> unsafe_extension_ids;
241 for (size_t i = 0; i < full_hashes.size(); ++i) { 244 for (size_t i = 0; i < full_hashes.size(); ++i) {
242 std::string extension_id = 245 std::string extension_id =
243 safe_browsing::SBFullHashToString(full_hashes[i]); 246 SBFullHashToString(full_hashes[i]);
244 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION) 247 if (full_hash_results[i] == SB_THREAT_TYPE_EXTENSION)
245 unsafe_extension_ids.insert(extension_id); 248 unsafe_extension_ids.insert(extension_id);
246 } 249 }
247 client->OnCheckExtensionsResult(unsafe_extension_ids); 250 client->OnCheckExtensionsResult(unsafe_extension_ids);
248 break; 251 break;
249 } 252 }
250 default: 253 default:
251 NOTREACHED(); 254 NOTREACHED();
252 } 255 }
253 } else { 256 } else {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 DCHECK_CURRENTLY_ON(BrowserThread::IO); 335 DCHECK_CURRENTLY_ON(BrowserThread::IO);
333 if (!enabled_ || !enable_download_protection_) 336 if (!enabled_ || !enable_download_protection_)
334 return true; 337 return true;
335 338
336 // We need to check the database for url prefix, and later may fetch the url 339 // We need to check the database for url prefix, and later may fetch the url
337 // from the safebrowsing backends. These need to be asynchronous. 340 // from the safebrowsing backends. These need to be asynchronous.
338 SafeBrowsingCheck* check = 341 SafeBrowsingCheck* check =
339 new SafeBrowsingCheck(url_chain, 342 new SafeBrowsingCheck(url_chain,
340 std::vector<SBFullHash>(), 343 std::vector<SBFullHash>(),
341 client, 344 client,
342 safe_browsing::BINURL, 345 BINURL,
343 std::vector<SBThreatType>(1, 346 std::vector<SBThreatType>(1,
344 SB_THREAT_TYPE_BINARY_MALWARE_URL)); 347 SB_THREAT_TYPE_BINARY_MALWARE_URL));
345 std::vector<SBPrefix> prefixes; 348 std::vector<SBPrefix> prefixes;
346 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes); 349 SafeBrowsingDatabase::GetDownloadUrlPrefixes(url_chain, &prefixes);
347 StartSafeBrowsingCheck( 350 StartSafeBrowsingCheck(
348 check, 351 check,
349 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread, 352 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckDownloadUrlOnSBThread,
350 this, prefixes)); 353 this, prefixes));
351 return false; 354 return false;
352 } 355 }
353 356
354 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs( 357 bool LocalSafeBrowsingDatabaseManager::CheckExtensionIDs(
355 const std::set<std::string>& extension_ids, 358 const std::set<std::string>& extension_ids,
356 Client* client) { 359 Client* client) {
357 DCHECK_CURRENTLY_ON(BrowserThread::IO); 360 DCHECK_CURRENTLY_ON(BrowserThread::IO);
358 361
359 if (!enabled_ || !enable_extension_blacklist_) 362 if (!enabled_ || !enable_extension_blacklist_)
360 return true; 363 return true;
361 364
362 std::vector<SBFullHash> extension_id_hashes; 365 std::vector<SBFullHash> extension_id_hashes;
363 std::transform(extension_ids.begin(), extension_ids.end(), 366 std::transform(extension_ids.begin(), extension_ids.end(),
364 std::back_inserter(extension_id_hashes), 367 std::back_inserter(extension_id_hashes),
365 safe_browsing::StringToSBFullHash); 368 StringToSBFullHash);
366 std::vector<SBPrefix> prefixes; 369 std::vector<SBPrefix> prefixes;
367 for (const SBFullHash& hash : extension_id_hashes) 370 for (const SBFullHash& hash : extension_id_hashes)
368 prefixes.push_back(hash.prefix); 371 prefixes.push_back(hash.prefix);
369 372
370 SafeBrowsingCheck* check = new SafeBrowsingCheck( 373 SafeBrowsingCheck* check = new SafeBrowsingCheck(
371 std::vector<GURL>(), 374 std::vector<GURL>(),
372 extension_id_hashes, 375 extension_id_hashes,
373 client, 376 client,
374 safe_browsing::EXTENSIONBLACKLIST, 377 EXTENSIONBLACKLIST,
375 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION)); 378 std::vector<SBThreatType>(1, SB_THREAT_TYPE_EXTENSION));
376 StartSafeBrowsingCheck( 379 StartSafeBrowsingCheck(
377 check, 380 check,
378 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread, 381 base::Bind(&LocalSafeBrowsingDatabaseManager::CheckExtensionIDsOnSBThread,
379 this, prefixes)); 382 this, prefixes));
380 return false; 383 return false;
381 } 384 }
382 385
383 bool LocalSafeBrowsingDatabaseManager::MatchMalwareIP( 386 bool LocalSafeBrowsingDatabaseManager::MatchMalwareIP(
384 const std::string& ip_address) { 387 const std::string& ip_address) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (!CanCheckUrl(url)) 455 if (!CanCheckUrl(url))
453 return true; 456 return true;
454 457
455 std::vector<SBThreatType> expected_threats; 458 std::vector<SBThreatType> expected_threats;
456 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE); 459 expected_threats.push_back(SB_THREAT_TYPE_URL_MALWARE);
457 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING); 460 expected_threats.push_back(SB_THREAT_TYPE_URL_PHISHING);
458 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED); 461 expected_threats.push_back(SB_THREAT_TYPE_URL_UNWANTED);
459 462
460 const base::TimeTicks start = base::TimeTicks::Now(); 463 const base::TimeTicks start = base::TimeTicks::Now();
461 if (!MakeDatabaseAvailable()) { 464 if (!MakeDatabaseAvailable()) {
462 QueuedCheck queued_check(safe_browsing::MALWARE, // or PHISH 465 QueuedCheck queued_check(MALWARE, // or PHISH
463 client, 466 client,
464 url, 467 url,
465 expected_threats, 468 expected_threats,
466 start); 469 start);
467 queued_checks_.push_back(queued_check); 470 queued_checks_.push_back(queued_check);
468 return false; 471 return false;
469 } 472 }
470 473
471 // Cache hits should, in general, be the same for both (ignoring potential 474 // Cache hits should, in general, be the same for both (ignoring potential
472 // cache evictions in the second call for entries that were just about to be 475 // cache evictions in the second call for entries that were just about to be
(...skipping 30 matching lines...) Expand all
503 506
504 // Needs to be asynchronous, since we could be in the constructor of a 507 // Needs to be asynchronous, since we could be in the constructor of a
505 // ResourceDispatcherHost event handler which can't pause there. 508 // ResourceDispatcherHost event handler which can't pause there.
506 // This check will ping the Safe Browsing servers and get all lists which it 509 // This check will ping the Safe Browsing servers and get all lists which it
507 // matches. These lists will then be filtered against the |expected_threats| 510 // matches. These lists will then be filtered against the |expected_threats|
508 // and the result callback for MALWARE (which is the same as for PHISH and 511 // and the result callback for MALWARE (which is the same as for PHISH and
509 // UNWANTEDURL) will eventually be invoked with the final decision. 512 // UNWANTEDURL) will eventually be invoked with the final decision.
510 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), 513 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url),
511 std::vector<SBFullHash>(), 514 std::vector<SBFullHash>(),
512 client, 515 client,
513 safe_browsing::MALWARE, 516 MALWARE,
514 expected_threats); 517 expected_threats);
515 check->need_get_hash = cache_hits.empty(); 518 check->need_get_hash = cache_hits.empty();
516 check->prefix_hits.swap(prefix_hits); 519 check->prefix_hits.swap(prefix_hits);
517 check->cache_hits.swap(cache_hits); 520 check->cache_hits.swap(cache_hits);
518 checks_.insert(check); 521 checks_.insert(check);
519 522
520 BrowserThread::PostTask( 523 BrowserThread::PostTask(
521 BrowserThread::IO, FROM_HERE, 524 BrowserThread::IO, FROM_HERE,
522 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check)); 525 base::Bind(&LocalSafeBrowsingDatabaseManager::OnCheckDone, this, check));
523 526
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 void LocalSafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished( 668 void LocalSafeBrowsingDatabaseManager::NotifyDatabaseUpdateFinished(
666 bool update_succeeded) { 669 bool update_succeeded) {
667 DCHECK_CURRENTLY_ON(BrowserThread::UI); 670 DCHECK_CURRENTLY_ON(BrowserThread::UI);
668 content::NotificationService::current()->Notify( 671 content::NotificationService::current()->Notify(
669 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 672 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
670 content::Source<SafeBrowsingDatabaseManager>(this), 673 content::Source<SafeBrowsingDatabaseManager>(this),
671 content::Details<bool>(&update_succeeded)); 674 content::Details<bool>(&update_succeeded));
672 } 675 }
673 676
674 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck( 677 LocalSafeBrowsingDatabaseManager::QueuedCheck::QueuedCheck(
675 const safe_browsing::ListType check_type, 678 const ListType check_type,
676 Client* client, 679 Client* client,
677 const GURL& url, 680 const GURL& url,
678 const std::vector<SBThreatType>& expected_threats, 681 const std::vector<SBThreatType>& expected_threats,
679 const base::TimeTicks& start) 682 const base::TimeTicks& start)
680 : check_type(check_type), 683 : check_type(check_type),
681 client(client), 684 client(client),
682 url(url), 685 url(url),
683 expected_threats(expected_threats), 686 expected_threats(expected_threats),
684 start(start) { 687 start(start) {
685 } 688 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 return is_extended_reporting; 868 return is_extended_reporting;
866 } 869 }
867 870
868 void LocalSafeBrowsingDatabaseManager::RequestFullHash( 871 void LocalSafeBrowsingDatabaseManager::RequestFullHash(
869 SafeBrowsingCheck* check) { 872 SafeBrowsingCheck* check) {
870 DCHECK_CURRENTLY_ON(BrowserThread::IO); 873 DCHECK_CURRENTLY_ON(BrowserThread::IO);
871 874
872 if (!enabled_) 875 if (!enabled_)
873 return; 876 return;
874 877
875 bool is_download = check->check_type == safe_browsing::BINURL; 878 bool is_download = check->check_type == BINURL;
876 sb_service_->protocol_manager()->GetFullHash( 879 sb_service_->protocol_manager()->GetFullHash(
877 check->prefix_hits, 880 check->prefix_hits,
878 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults, 881 base::Bind(&LocalSafeBrowsingDatabaseManager::HandleGetHashResults,
879 base::Unretained(this), check), 882 base::Unretained(this), check),
880 is_download, check->is_extended_reporting); 883 is_download, check->is_extended_reporting);
881 } 884 }
882 885
883 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase( 886 void LocalSafeBrowsingDatabaseManager::GetAllChunksFromDatabase(
884 GetChunksCallback callback) { 887 GetChunksCallback callback) {
885 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); 888 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 void LocalSafeBrowsingDatabaseManager::OnResetDatabase() { 1021 void LocalSafeBrowsingDatabaseManager::OnResetDatabase() {
1019 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread()); 1022 DCHECK(safe_browsing_task_runner_->RunsTasksOnCurrentThread());
1020 1023
1021 GetDatabase()->ResetDatabase(); 1024 GetDatabase()->ResetDatabase();
1022 } 1025 }
1023 1026
1024 void LocalSafeBrowsingDatabaseManager::OnHandleGetHashResults( 1027 void LocalSafeBrowsingDatabaseManager::OnHandleGetHashResults(
1025 SafeBrowsingCheck* check, 1028 SafeBrowsingCheck* check,
1026 const std::vector<SBFullHashResult>& full_hashes) { 1029 const std::vector<SBFullHashResult>& full_hashes) {
1027 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1030 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1028 safe_browsing::ListType check_type = check->check_type; 1031 ListType check_type = check->check_type;
1029 SBPrefix prefix = check->prefix_hits[0]; 1032 SBPrefix prefix = check->prefix_hits[0];
1030 GetHashRequests::iterator it = gethash_requests_.find(prefix); 1033 GetHashRequests::iterator it = gethash_requests_.find(prefix);
1031 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) { 1034 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) {
1032 const bool hit = HandleOneCheck(check, full_hashes); 1035 const bool hit = HandleOneCheck(check, full_hashes);
1033 RecordGetHashCheckStatus(hit, check_type, full_hashes); 1036 RecordGetHashCheckStatus(hit, check_type, full_hashes);
1034 return; 1037 return;
1035 } 1038 }
1036 1039
1037 // Call back all interested parties, noting if any has a hit. 1040 // Call back all interested parties, noting if any has a hit.
1038 GetHashRequestors& requestors = it->second; 1041 GetHashRequestors& requestors = it->second;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 check->weak_ptr_factory_->GetWeakPtr(), check)); 1185 check->weak_ptr_factory_->GetWeakPtr(), check));
1183 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1186 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1184 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback, 1187 FROM_HERE, base::Bind(&LocalSafeBrowsingDatabaseManager::TimeoutCallback,
1185 check->weak_ptr_factory_->GetWeakPtr(), check), 1188 check->weak_ptr_factory_->GetWeakPtr(), check),
1186 check_timeout_); 1189 check_timeout_);
1187 } 1190 }
1188 1191
1189 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const { 1192 bool LocalSafeBrowsingDatabaseManager::download_protection_enabled() const {
1190 return enable_download_protection_; 1193 return enable_download_protection_;
1191 } 1194 }
1195
1196 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698