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

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

Powered by Google App Engine
This is Rietveld 408576698