| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 weak_factory_.GetWeakPtr()), | 244 weak_factory_.GetWeakPtr()), |
| 245 base::TimeDelta::FromMilliseconds(delay_ms)); | 245 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ClientSideDetectionService::StartFetchModel() { | 248 void ClientSideDetectionService::StartFetchModel() { |
| 249 if (enabled_) { | 249 if (enabled_) { |
| 250 // Start fetching the model either from the cache or possibly from the | 250 // Start fetching the model either from the cache or possibly from the |
| 251 // network if the model isn't in the cache. | 251 // network if the model isn't in the cache. |
| 252 model_fetcher_.reset(content::URLFetcher::Create( | 252 model_fetcher_.reset(content::URLFetcher::Create( |
| 253 0 /* ID used for testing */, GURL(kClientModelUrl), | 253 0 /* ID used for testing */, GURL(kClientModelUrl), |
| 254 content::URLFetcher::GET, this)); | 254 net::URLFetcher::GET, this)); |
| 255 model_fetcher_->SetRequestContext(request_context_getter_.get()); | 255 model_fetcher_->SetRequestContext(request_context_getter_.get()); |
| 256 model_fetcher_->Start(); | 256 model_fetcher_->Start(); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 void ClientSideDetectionService::EndFetchModel(ClientModelStatus status) { | 260 void ClientSideDetectionService::EndFetchModel(ClientModelStatus status) { |
| 261 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.ClientModelStatus", | 261 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.ClientModelStatus", |
| 262 status, | 262 status, |
| 263 MODEL_STATUS_MAX); | 263 MODEL_STATUS_MAX); |
| 264 if (status == MODEL_SUCCESS) { | 264 if (status == MODEL_SUCCESS) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 295 | 295 |
| 296 std::string request_data; | 296 std::string request_data; |
| 297 if (!request->SerializeToString(&request_data)) { | 297 if (!request->SerializeToString(&request_data)) { |
| 298 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); | 298 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); |
| 299 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; | 299 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; |
| 300 if (!callback.is_null()) | 300 if (!callback.is_null()) |
| 301 callback.Run(GURL(request->url()), false); | 301 callback.Run(GURL(request->url()), false); |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 | 304 |
| 305 content::URLFetcher* fetcher = content::URLFetcher::Create( | 305 net::URLFetcher* fetcher = content::URLFetcher::Create( |
| 306 0 /* ID used for testing */, GURL(kClientReportPhishingUrl), | 306 0 /* ID used for testing */, GURL(kClientReportPhishingUrl), |
| 307 content::URLFetcher::POST, this); | 307 net::URLFetcher::POST, this); |
| 308 | 308 |
| 309 // Remember which callback and URL correspond to the current fetcher object. | 309 // Remember which callback and URL correspond to the current fetcher object. |
| 310 ClientReportInfo* info = new ClientReportInfo; | 310 ClientReportInfo* info = new ClientReportInfo; |
| 311 info->callback = callback; | 311 info->callback = callback; |
| 312 info->phishing_url = GURL(request->url()); | 312 info->phishing_url = GURL(request->url()); |
| 313 client_phishing_reports_[fetcher] = info; | 313 client_phishing_reports_[fetcher] = info; |
| 314 | 314 |
| 315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
| 316 fetcher->SetRequestContext(request_context_getter_.get()); | 316 fetcher->SetRequestContext(request_context_getter_.get()); |
| 317 fetcher->SetUploadData("application/octet-stream", request_data); | 317 fetcher->SetUploadData("application/octet-stream", request_data); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 for (int i = 0; i < model.page_term_size(); ++i) { | 528 for (int i = 0; i < model.page_term_size(); ++i) { |
| 529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { | 529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { |
| 530 return false; | 530 return false; |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 return true; | 533 return true; |
| 534 } | 534 } |
| 535 } // namespace safe_browsing | 535 } // namespace safe_browsing |
| OLD | NEW |