OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/client_side_detection_service.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util_proxy.h" | 8 #include "base/file_util_proxy.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 ClientPhishingRequest* verdict, | 257 ClientPhishingRequest* verdict, |
258 ClientReportPhishingRequestCallback* callback) { | 258 ClientReportPhishingRequestCallback* callback) { |
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
260 scoped_ptr<ClientPhishingRequest> request(verdict); | 260 scoped_ptr<ClientPhishingRequest> request(verdict); |
261 scoped_ptr<ClientReportPhishingRequestCallback> cb(callback); | 261 scoped_ptr<ClientReportPhishingRequestCallback> cb(callback); |
262 | 262 |
263 std::string request_data; | 263 std::string request_data; |
264 if (!request->SerializeToString(&request_data)) { | 264 if (!request->SerializeToString(&request_data)) { |
265 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); | 265 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); |
266 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; | 266 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; |
267 cb->Run(GURL(request->url()), false); | 267 if (cb.get()) { |
| 268 cb->Run(GURL(request->url()), false); |
| 269 } |
268 return; | 270 return; |
269 } | 271 } |
270 | 272 |
271 URLFetcher* fetcher = URLFetcher::Create(0 /* ID is not used */, | 273 URLFetcher* fetcher = URLFetcher::Create(0 /* ID is not used */, |
272 GURL(kClientReportPhishingUrl), | 274 GURL(kClientReportPhishingUrl), |
273 URLFetcher::POST, | 275 URLFetcher::POST, |
274 this); | 276 this); |
275 | 277 |
276 // Remember which callback and URL correspond to the current fetcher object. | 278 // Remember which callback and URL correspond to the current fetcher object. |
277 ClientReportInfo* info = new ClientReportInfo; | 279 ClientReportInfo* info = new ClientReportInfo; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 331 |
330 void ClientSideDetectionService::HandlePhishingVerdict( | 332 void ClientSideDetectionService::HandlePhishingVerdict( |
331 const URLFetcher* source, | 333 const URLFetcher* source, |
332 const GURL& url, | 334 const GURL& url, |
333 const net::URLRequestStatus& status, | 335 const net::URLRequestStatus& status, |
334 int response_code, | 336 int response_code, |
335 const net::ResponseCookies& cookies, | 337 const net::ResponseCookies& cookies, |
336 const std::string& data) { | 338 const std::string& data) { |
337 ClientPhishingResponse response; | 339 ClientPhishingResponse response; |
338 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); | 340 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); |
| 341 bool is_phishing = false; |
339 if (status.is_success() && RC_REQUEST_OK == response_code && | 342 if (status.is_success() && RC_REQUEST_OK == response_code && |
340 response.ParseFromString(data)) { | 343 response.ParseFromString(data)) { |
341 // Cache response, possibly flushing an old one. | 344 // Cache response, possibly flushing an old one. |
342 cache_[info->phishing_url] = | 345 cache_[info->phishing_url] = |
343 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); | 346 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); |
344 info->callback->Run(info->phishing_url, response.phishy()); | 347 is_phishing = response.phishy(); |
345 } else { | 348 } else { |
346 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 349 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
347 << info->phishing_url << " status: " << status.status() << " " | 350 << info->phishing_url << " status: " << status.status() << " " |
348 << "response_code:" << response_code; | 351 << "response_code:" << response_code; |
349 info->callback->Run(info->phishing_url, false); | 352 } |
| 353 if (info->callback.get()) { |
| 354 info->callback->Run(info->phishing_url, is_phishing); |
350 } | 355 } |
351 client_phishing_reports_.erase(source); | 356 client_phishing_reports_.erase(source); |
352 delete source; | 357 delete source; |
353 } | 358 } |
354 | 359 |
355 bool ClientSideDetectionService::IsInCache(const GURL& url) { | 360 bool ClientSideDetectionService::IsInCache(const GURL& url) { |
356 UpdateCache(); | 361 UpdateCache(); |
357 | 362 |
358 return cache_.find(url) != cache_.end(); | 363 return cache_.find(url) != cache_.end(); |
359 } | 364 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // |size| bits sets to one. | 469 // |size| bits sets to one. |
465 std::string mask(net::kIPv6AddressSize, '\x00'); | 470 std::string mask(net::kIPv6AddressSize, '\x00'); |
466 mask.replace(0, size / 8, size / 8, '\xFF'); | 471 mask.replace(0, size / 8, size / 8, '\xFF'); |
467 if (size % 8) { | 472 if (size % 8) { |
468 mask[size / 8] = 0xFF << (8 - (size % 8)); | 473 mask[size / 8] = 0xFF << (8 - (size % 8)); |
469 } | 474 } |
470 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix()); | 475 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix()); |
471 } | 476 } |
472 } | 477 } |
473 } // namespace safe_browsing | 478 } // namespace safe_browsing |
OLD | NEW |