| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 base::MessageLoop::current()->PostTask( | 181 base::MessageLoop::current()->PostTask( |
| 182 FROM_HERE, | 182 FROM_HERE, |
| 183 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, | 183 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, |
| 184 weak_factory_.GetWeakPtr(), verdict, callback)); | 184 weak_factory_.GetWeakPtr(), verdict, callback)); |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool ClientSideDetectionService::IsPrivateIPAddress( | 187 bool ClientSideDetectionService::IsPrivateIPAddress( |
| 188 const std::string& ip_address) const { | 188 const std::string& ip_address) const { |
| 189 net::IPAddressNumber ip_number; | 189 net::IPAddressNumber ip_number; |
| 190 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { | 190 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { |
| 191 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; | 191 DVLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; |
| 192 // Err on the side of safety and assume this might be private. | 192 // Err on the side of safety and assume this might be private. |
| 193 return true; | 193 return true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 return net::IsIPAddressReserved(ip_number); | 196 return net::IsIPAddressReserved(ip_number); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void ClientSideDetectionService::OnURLFetchComplete( | 199 void ClientSideDetectionService::OnURLFetchComplete( |
| 200 const net::URLFetcher* source) { | 200 const net::URLFetcher* source) { |
| 201 std::string data; | 201 std::string data; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ClientSideDetectionService::SendModelToProcess( | 236 void ClientSideDetectionService::SendModelToProcess( |
| 237 content::RenderProcessHost* process) { | 237 content::RenderProcessHost* process) { |
| 238 // The ClientSideDetectionService is enabled if _any_ active profile has | 238 // The ClientSideDetectionService is enabled if _any_ active profile has |
| 239 // SafeBrowsing turned on. Here we check the profile for each renderer | 239 // SafeBrowsing turned on. Here we check the profile for each renderer |
| 240 // process and only send the model to those that have SafeBrowsing enabled. | 240 // process and only send the model to those that have SafeBrowsing enabled. |
| 241 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); | 241 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
| 242 std::string model; | 242 std::string model; |
| 243 if (profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { | 243 if (profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled)) { |
| 244 VLOG(2) << "Sending phishing model to RenderProcessHost @" << process; | 244 DVLOG(2) << "Sending phishing model to RenderProcessHost @" << process; |
| 245 model = model_str_; | 245 model = model_str_; |
| 246 } else { | 246 } else { |
| 247 VLOG(2) << "Disabling client-side phishing detection for " | 247 DVLOG(2) << "Disabling client-side phishing detection for " |
| 248 << "RenderProcessHost @" << process; | 248 << "RenderProcessHost @" << process; |
| 249 } | 249 } |
| 250 process->Send(new SafeBrowsingMsg_SetPhishingModel(model)); | 250 process->Send(new SafeBrowsingMsg_SetPhishingModel(model)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void ClientSideDetectionService::SendModelToRenderers() { | 253 void ClientSideDetectionService::SendModelToRenderers() { |
| 254 for (content::RenderProcessHost::iterator i( | 254 for (content::RenderProcessHost::iterator i( |
| 255 content::RenderProcessHost::AllHostsIterator()); | 255 content::RenderProcessHost::AllHostsIterator()); |
| 256 !i.IsAtEnd(); i.Advance()) { | 256 !i.IsAtEnd(); i.Advance()) { |
| 257 SendModelToProcess(i.GetCurrentValue()); | 257 SendModelToProcess(i.GetCurrentValue()); |
| 258 } | 258 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 if (!enabled_) { | 314 if (!enabled_) { |
| 315 if (!callback.is_null()) | 315 if (!callback.is_null()) |
| 316 callback.Run(GURL(request->url()), false); | 316 callback.Run(GURL(request->url()), false); |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 | 319 |
| 320 std::string request_data; | 320 std::string request_data; |
| 321 if (!request->SerializeToString(&request_data)) { | 321 if (!request->SerializeToString(&request_data)) { |
| 322 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); | 322 UMA_HISTOGRAM_COUNTS("SBClientPhishing.RequestNotSerialized", 1); |
| 323 VLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; | 323 DVLOG(1) << "Unable to serialize the CSD request. Proto file changed?"; |
| 324 if (!callback.is_null()) | 324 if (!callback.is_null()) |
| 325 callback.Run(GURL(request->url()), false); | 325 callback.Run(GURL(request->url()), false); |
| 326 return; | 326 return; |
| 327 } | 327 } |
| 328 | 328 |
| 329 net::URLFetcher* fetcher = net::URLFetcher::Create( | 329 net::URLFetcher* fetcher = net::URLFetcher::Create( |
| 330 0 /* ID used for testing */, | 330 0 /* ID used for testing */, |
| 331 GetClientReportUrl(kClientReportPhishingUrl), | 331 GetClientReportUrl(kClientReportPhishingUrl), |
| 332 net::URLFetcher::POST, this); | 332 net::URLFetcher::POST, this); |
| 333 | 333 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 GURL ClientSideDetectionService::GetClientReportUrl( | 635 GURL ClientSideDetectionService::GetClientReportUrl( |
| 636 const std::string& report_url) { | 636 const std::string& report_url) { |
| 637 GURL url(report_url); | 637 GURL url(report_url); |
| 638 std::string api_key = google_apis::GetAPIKey(); | 638 std::string api_key = google_apis::GetAPIKey(); |
| 639 if (!api_key.empty()) | 639 if (!api_key.empty()) |
| 640 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 640 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 641 | 641 |
| 642 return url; | 642 return url; |
| 643 } | 643 } |
| 644 } // namespace safe_browsing | 644 } // namespace safe_browsing |
| OLD | NEW |