OLD | NEW |
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/client_side_detection_service.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/location.h" | 11 #include "base/location.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/safe_browsing/client_model.pb.h" | 22 #include "chrome/common/safe_browsing/client_model.pb.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 !i.IsAtEnd(); i.Advance()) { | 261 !i.IsAtEnd(); i.Advance()) { |
262 SendModelToProcess(i.GetCurrentValue()); | 262 SendModelToProcess(i.GetCurrentValue()); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 void ClientSideDetectionService::StartClientReportPhishingRequest( | 266 void ClientSideDetectionService::StartClientReportPhishingRequest( |
267 ClientPhishingRequest* verdict, | 267 ClientPhishingRequest* verdict, |
268 bool is_extended_reporting, | 268 bool is_extended_reporting, |
269 const ClientReportPhishingRequestCallback& callback) { | 269 const ClientReportPhishingRequestCallback& callback) { |
270 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 270 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
271 scoped_ptr<ClientPhishingRequest> request(verdict); | 271 std::unique_ptr<ClientPhishingRequest> request(verdict); |
272 | 272 |
273 if (!enabled_) { | 273 if (!enabled_) { |
274 if (!callback.is_null()) | 274 if (!callback.is_null()) |
275 callback.Run(GURL(request->url()), false); | 275 callback.Run(GURL(request->url()), false); |
276 return; | 276 return; |
277 } | 277 } |
278 | 278 |
279 // Fill in metadata about which model we used. | 279 // Fill in metadata about which model we used. |
280 if (is_extended_reporting) { | 280 if (is_extended_reporting) { |
281 request->set_model_filename(model_loader_extended_->name()); | 281 request->set_model_filename(model_loader_extended_->name()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 fetcher->Start(); | 314 fetcher->Start(); |
315 | 315 |
316 // Record that we made a request | 316 // Record that we made a request |
317 phishing_report_times_.push(base::Time::Now()); | 317 phishing_report_times_.push(base::Time::Now()); |
318 } | 318 } |
319 | 319 |
320 void ClientSideDetectionService::StartClientReportMalwareRequest( | 320 void ClientSideDetectionService::StartClientReportMalwareRequest( |
321 ClientMalwareRequest* verdict, | 321 ClientMalwareRequest* verdict, |
322 const ClientReportMalwareRequestCallback& callback) { | 322 const ClientReportMalwareRequestCallback& callback) { |
323 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
324 scoped_ptr<ClientMalwareRequest> request(verdict); | 324 std::unique_ptr<ClientMalwareRequest> request(verdict); |
325 | 325 |
326 if (!enabled_) { | 326 if (!enabled_) { |
327 if (!callback.is_null()) | 327 if (!callback.is_null()) |
328 callback.Run(GURL(request->url()), GURL(request->url()), false); | 328 callback.Run(GURL(request->url()), GURL(request->url()), false); |
329 return; | 329 return; |
330 } | 330 } |
331 | 331 |
332 std::string request_data; | 332 std::string request_data; |
333 if (!request->SerializeToString(&request_data)) { | 333 if (!request->SerializeToString(&request_data)) { |
334 UpdateEnumUMAHistogram(REPORT_FAILED_SERIALIZATION); | 334 UpdateEnumUMAHistogram(REPORT_FAILED_SERIALIZATION); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 366 |
367 | 367 |
368 void ClientSideDetectionService::HandlePhishingVerdict( | 368 void ClientSideDetectionService::HandlePhishingVerdict( |
369 const net::URLFetcher* source, | 369 const net::URLFetcher* source, |
370 const GURL& url, | 370 const GURL& url, |
371 const net::URLRequestStatus& status, | 371 const net::URLRequestStatus& status, |
372 int response_code, | 372 int response_code, |
373 const net::ResponseCookies& cookies, | 373 const net::ResponseCookies& cookies, |
374 const std::string& data) { | 374 const std::string& data) { |
375 ClientPhishingResponse response; | 375 ClientPhishingResponse response; |
376 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); | 376 std::unique_ptr<ClientReportInfo> info(client_phishing_reports_[source]); |
377 bool is_phishing = false; | 377 bool is_phishing = false; |
378 if (status.is_success() && net::HTTP_OK == response_code && | 378 if (status.is_success() && net::HTTP_OK == response_code && |
379 response.ParseFromString(data)) { | 379 response.ParseFromString(data)) { |
380 // Cache response, possibly flushing an old one. | 380 // Cache response, possibly flushing an old one. |
381 cache_[info->phishing_url] = | 381 cache_[info->phishing_url] = |
382 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); | 382 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); |
383 is_phishing = response.phishy(); | 383 is_phishing = response.phishy(); |
384 } else { | 384 } else { |
385 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 385 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
386 << info->phishing_url << " status: " << status.status() << " " | 386 << info->phishing_url << " status: " << status.status() << " " |
(...skipping 14 matching lines...) Expand all Loading... |
401 const std::string& data) { | 401 const std::string& data) { |
402 if (status.is_success()) { | 402 if (status.is_success()) { |
403 UMA_HISTOGRAM_SPARSE_SLOWLY( | 403 UMA_HISTOGRAM_SPARSE_SLOWLY( |
404 "SBClientMalware.IPBlacklistRequestResponseCode", response_code); | 404 "SBClientMalware.IPBlacklistRequestResponseCode", response_code); |
405 } | 405 } |
406 // status error is negative, so we put - in front of it. | 406 // status error is negative, so we put - in front of it. |
407 UMA_HISTOGRAM_SPARSE_SLOWLY( | 407 UMA_HISTOGRAM_SPARSE_SLOWLY( |
408 "SBClientMalware.IPBlacklistRequestNetError", -status.error()); | 408 "SBClientMalware.IPBlacklistRequestNetError", -status.error()); |
409 | 409 |
410 ClientMalwareResponse response; | 410 ClientMalwareResponse response; |
411 scoped_ptr<ClientMalwareReportInfo> info(client_malware_reports_[source]); | 411 std::unique_ptr<ClientMalwareReportInfo> info( |
| 412 client_malware_reports_[source]); |
412 bool should_blacklist = false; | 413 bool should_blacklist = false; |
413 if (status.is_success() && net::HTTP_OK == response_code && | 414 if (status.is_success() && net::HTTP_OK == response_code && |
414 response.ParseFromString(data)) { | 415 response.ParseFromString(data)) { |
415 should_blacklist = response.blacklist(); | 416 should_blacklist = response.blacklist(); |
416 } else { | 417 } else { |
417 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 418 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
418 << info->original_url << " status: " << status.status() << " " | 419 << info->original_url << " status: " << status.status() << " " |
419 << "response_code:" << response_code; | 420 << "response_code:" << response_code; |
420 } | 421 } |
421 | 422 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 const std::string& report_url) { | 521 const std::string& report_url) { |
521 GURL url(report_url); | 522 GURL url(report_url); |
522 std::string api_key = google_apis::GetAPIKey(); | 523 std::string api_key = google_apis::GetAPIKey(); |
523 if (!api_key.empty()) | 524 if (!api_key.empty()) |
524 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 525 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
525 | 526 |
526 return url; | 527 return url; |
527 } | 528 } |
528 | 529 |
529 } // namespace safe_browsing | 530 } // namespace safe_browsing |
OLD | NEW |