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

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

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

Powered by Google App Engine
This is Rietveld 408576698