Chromium Code Reviews| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ClientSideDetectionService::StartClientReportPhishingRequest( | 256 void ClientSideDetectionService::StartClientReportPhishingRequest( |
| 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) && cb.get()) { |
|
Brian Ryner
2011/07/19 21:27:10
This doesn't seem quite right -- don't we want to
noelutz
2011/07/19 22:28:08
Done.
| |
| 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 cb->Run(GURL(request->url()), false); |
| 268 return; | 268 return; |
| 269 } | 269 } |
| 270 | 270 |
| 271 URLFetcher* fetcher = URLFetcher::Create(0 /* ID is not used */, | 271 URLFetcher* fetcher = URLFetcher::Create(0 /* ID is not used */, |
| 272 GURL(kClientReportPhishingUrl), | 272 GURL(kClientReportPhishingUrl), |
| 273 URLFetcher::POST, | 273 URLFetcher::POST, |
| 274 this); | 274 this); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 | 329 |
| 330 void ClientSideDetectionService::HandlePhishingVerdict( | 330 void ClientSideDetectionService::HandlePhishingVerdict( |
| 331 const URLFetcher* source, | 331 const URLFetcher* source, |
| 332 const GURL& url, | 332 const GURL& url, |
| 333 const net::URLRequestStatus& status, | 333 const net::URLRequestStatus& status, |
| 334 int response_code, | 334 int response_code, |
| 335 const net::ResponseCookies& cookies, | 335 const net::ResponseCookies& cookies, |
| 336 const std::string& data) { | 336 const std::string& data) { |
| 337 ClientPhishingResponse response; | 337 ClientPhishingResponse response; |
| 338 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); | 338 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); |
| 339 bool isphishing = false; | |
|
Garrett Casto
2011/07/19 21:18:48
is_phishing?
mattm
2011/07/19 21:25:55
nit: is_phishing
noelutz
2011/07/19 22:28:08
Done.
noelutz
2011/07/19 22:28:08
Done.
| |
| 339 if (status.is_success() && RC_REQUEST_OK == response_code && | 340 if (status.is_success() && RC_REQUEST_OK == response_code && |
| 340 response.ParseFromString(data)) { | 341 response.ParseFromString(data)) { |
| 341 // Cache response, possibly flushing an old one. | 342 // Cache response, possibly flushing an old one. |
| 342 cache_[info->phishing_url] = | 343 cache_[info->phishing_url] = |
| 343 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); | 344 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); |
| 344 info->callback->Run(info->phishing_url, response.phishy()); | 345 isphishing = response.phishy(); |
| 345 } else { | 346 } else { |
| 346 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 347 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
| 347 << info->phishing_url << " status: " << status.status() << " " | 348 << info->phishing_url << " status: " << status.status() << " " |
| 348 << "response_code:" << response_code; | 349 << "response_code:" << response_code; |
| 349 info->callback->Run(info->phishing_url, false); | 350 } |
| 351 if (info->callback.get()) { | |
| 352 info->callback->Run(info->phishing_url, isphishing); | |
| 350 } | 353 } |
| 351 client_phishing_reports_.erase(source); | 354 client_phishing_reports_.erase(source); |
| 352 delete source; | 355 delete source; |
| 353 } | 356 } |
| 354 | 357 |
| 355 bool ClientSideDetectionService::IsInCache(const GURL& url) { | 358 bool ClientSideDetectionService::IsInCache(const GURL& url) { |
| 356 UpdateCache(); | 359 UpdateCache(); |
| 357 | 360 |
| 358 return cache_.find(url) != cache_.end(); | 361 return cache_.find(url) != cache_.end(); |
| 359 } | 362 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 // |size| bits sets to one. | 467 // |size| bits sets to one. |
| 465 std::string mask(net::kIPv6AddressSize, '\x00'); | 468 std::string mask(net::kIPv6AddressSize, '\x00'); |
| 466 mask.replace(0, size / 8, size / 8, '\xFF'); | 469 mask.replace(0, size / 8, size / 8, '\xFF'); |
| 467 if (size % 8) { | 470 if (size % 8) { |
| 468 mask[size / 8] = 0xFF << (8 - (size % 8)); | 471 mask[size / 8] = 0xFF << (8 - (size % 8)); |
| 469 } | 472 } |
| 470 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix()); | 473 (*bad_subnets)[mask].insert(model.bad_subnet(i).prefix()); |
| 471 } | 474 } |
| 472 } | 475 } |
| 473 } // namespace safe_browsing | 476 } // namespace safe_browsing |
| OLD | NEW |