| OLD | NEW |
| 1 // Copyright (c) 2010 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_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MessageLoop::current()->PostTask( | 98 MessageLoop::current()->PostTask( |
| 99 FROM_HERE, | 99 FROM_HERE, |
| 100 method_factory_.NewRunnableMethod( | 100 method_factory_.NewRunnableMethod( |
| 101 &ClientSideDetectionService::StartClientReportPhishingRequest, | 101 &ClientSideDetectionService::StartClientReportPhishingRequest, |
| 102 phishing_url, score, thumbnail, callback)); | 102 phishing_url, score, thumbnail, callback)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ClientSideDetectionService::OnURLFetchComplete( | 105 void ClientSideDetectionService::OnURLFetchComplete( |
| 106 const URLFetcher* source, | 106 const URLFetcher* source, |
| 107 const GURL& url, | 107 const GURL& url, |
| 108 const URLRequestStatus& status, | 108 const net::URLRequestStatus& status, |
| 109 int response_code, | 109 int response_code, |
| 110 const ResponseCookies& cookies, | 110 const ResponseCookies& cookies, |
| 111 const std::string& data) { | 111 const std::string& data) { |
| 112 if (source == model_fetcher_) { | 112 if (source == model_fetcher_) { |
| 113 HandleModelResponse(source, url, status, response_code, cookies, data); | 113 HandleModelResponse(source, url, status, response_code, cookies, data); |
| 114 // The fetcher object will be invalid after this method returns. | 114 // The fetcher object will be invalid after this method returns. |
| 115 model_fetcher_ = NULL; | 115 model_fetcher_ = NULL; |
| 116 } else if (client_phishing_reports_.find(source) != | 116 } else if (client_phishing_reports_.find(source) != |
| 117 client_phishing_reports_.end()) { | 117 client_phishing_reports_.end()) { |
| 118 HandlePhishingVerdict(source, url, status, response_code, cookies, data); | 118 HandlePhishingVerdict(source, url, status, response_code, cookies, data); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE); | 269 fetcher->set_load_flags(net::LOAD_DISABLE_CACHE); |
| 270 fetcher->set_request_context(request_context_getter_.get()); | 270 fetcher->set_request_context(request_context_getter_.get()); |
| 271 fetcher->set_upload_data("application/octet-stream", request_data); | 271 fetcher->set_upload_data("application/octet-stream", request_data); |
| 272 fetcher->Start(); | 272 fetcher->Start(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void ClientSideDetectionService::HandleModelResponse( | 275 void ClientSideDetectionService::HandleModelResponse( |
| 276 const URLFetcher* source, | 276 const URLFetcher* source, |
| 277 const GURL& url, | 277 const GURL& url, |
| 278 const URLRequestStatus& status, | 278 const net::URLRequestStatus& status, |
| 279 int response_code, | 279 int response_code, |
| 280 const ResponseCookies& cookies, | 280 const ResponseCookies& cookies, |
| 281 const std::string& data) { | 281 const std::string& data) { |
| 282 if (status.is_success() && RC_REQUEST_OK == response_code) { | 282 if (status.is_success() && RC_REQUEST_OK == response_code) { |
| 283 // Copy the model because it has to be accessible after this function | 283 // Copy the model because it has to be accessible after this function |
| 284 // returns. Once we have written the model to a file we will delete the | 284 // returns. Once we have written the model to a file we will delete the |
| 285 // temporary model string. TODO(noelutz): don't store the model to disk if | 285 // temporary model string. TODO(noelutz): don't store the model to disk if |
| 286 // it's invalid. | 286 // it's invalid. |
| 287 tmp_model_string_.reset(new std::string(data)); | 287 tmp_model_string_.reset(new std::string(data)); |
| 288 base::FileUtilProxy::CreateOrOpenCallback* cb = | 288 base::FileUtilProxy::CreateOrOpenCallback* cb = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 299 SetModelStatus(ERROR_STATUS); | 299 SetModelStatus(ERROR_STATUS); |
| 300 } | 300 } |
| 301 } else { | 301 } else { |
| 302 SetModelStatus(ERROR_STATUS); | 302 SetModelStatus(ERROR_STATUS); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 void ClientSideDetectionService::HandlePhishingVerdict( | 306 void ClientSideDetectionService::HandlePhishingVerdict( |
| 307 const URLFetcher* source, | 307 const URLFetcher* source, |
| 308 const GURL& url, | 308 const GURL& url, |
| 309 const URLRequestStatus& status, | 309 const net::URLRequestStatus& status, |
| 310 int response_code, | 310 int response_code, |
| 311 const ResponseCookies& cookies, | 311 const ResponseCookies& cookies, |
| 312 const std::string& data) { | 312 const std::string& data) { |
| 313 ClientPhishingResponse response; | 313 ClientPhishingResponse response; |
| 314 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); | 314 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); |
| 315 if (status.is_success() && RC_REQUEST_OK == response_code && | 315 if (status.is_success() && RC_REQUEST_OK == response_code && |
| 316 response.ParseFromString(data)) { | 316 response.ParseFromString(data)) { |
| 317 info->callback->Run(info->phishing_url, response.phishy()); | 317 info->callback->Run(info->phishing_url, response.phishy()); |
| 318 } else { | 318 } else { |
| 319 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 319 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
| 320 << info->phishing_url; | 320 << info->phishing_url; |
| 321 info->callback->Run(info->phishing_url, false); | 321 info->callback->Run(info->phishing_url, false); |
| 322 } | 322 } |
| 323 client_phishing_reports_.erase(source); | 323 client_phishing_reports_.erase(source); |
| 324 } | 324 } |
| 325 | 325 |
| 326 } // namespace safe_browsing | 326 } // namespace safe_browsing |
| OLD | NEW |