| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 client_malware_reports_.end()); | 137 client_malware_reports_.end()); |
| 138 client_malware_reports_.clear(); | 138 client_malware_reports_.clear(); |
| 139 cache_.clear(); | 139 cache_.clear(); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ClientSideDetectionService::SendClientReportPhishingRequest( | 143 void ClientSideDetectionService::SendClientReportPhishingRequest( |
| 144 ClientPhishingRequest* verdict, | 144 ClientPhishingRequest* verdict, |
| 145 const ClientReportPhishingRequestCallback& callback) { | 145 const ClientReportPhishingRequestCallback& callback) { |
| 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 147 MessageLoop::current()->PostTask( | 147 base::MessageLoop::current()->PostTask( |
| 148 FROM_HERE, | 148 FROM_HERE, |
| 149 base::Bind(&ClientSideDetectionService::StartClientReportPhishingRequest, | 149 base::Bind(&ClientSideDetectionService::StartClientReportPhishingRequest, |
| 150 weak_factory_.GetWeakPtr(), verdict, callback)); | 150 weak_factory_.GetWeakPtr(), |
| 151 verdict, |
| 152 callback)); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void ClientSideDetectionService::SendClientReportMalwareRequest( | 155 void ClientSideDetectionService::SendClientReportMalwareRequest( |
| 154 ClientMalwareRequest* verdict, | 156 ClientMalwareRequest* verdict, |
| 155 const ClientReportMalwareRequestCallback& callback) { | 157 const ClientReportMalwareRequestCallback& callback) { |
| 156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 157 MessageLoop::current()->PostTask( | 159 base::MessageLoop::current()->PostTask( |
| 158 FROM_HERE, | 160 FROM_HERE, |
| 159 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, | 161 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, |
| 160 weak_factory_.GetWeakPtr(), verdict, callback)); | 162 weak_factory_.GetWeakPtr(), |
| 163 verdict, |
| 164 callback)); |
| 161 } | 165 } |
| 162 | 166 |
| 163 bool ClientSideDetectionService::IsPrivateIPAddress( | 167 bool ClientSideDetectionService::IsPrivateIPAddress( |
| 164 const std::string& ip_address) const { | 168 const std::string& ip_address) const { |
| 165 net::IPAddressNumber ip_number; | 169 net::IPAddressNumber ip_number; |
| 166 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { | 170 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { |
| 167 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; | 171 VLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; |
| 168 // Err on the side of safety and assume this might be private. | 172 // Err on the side of safety and assume this might be private. |
| 169 return true; | 173 return true; |
| 170 } | 174 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 content::RenderProcessHost::AllHostsIterator()); | 271 content::RenderProcessHost::AllHostsIterator()); |
| 268 !i.IsAtEnd(); i.Advance()) { | 272 !i.IsAtEnd(); i.Advance()) { |
| 269 SendModelToProcess(i.GetCurrentValue()); | 273 SendModelToProcess(i.GetCurrentValue()); |
| 270 } | 274 } |
| 271 } | 275 } |
| 272 | 276 |
| 273 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { | 277 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { |
| 274 if (CommandLine::ForCurrentProcess()->HasSwitch( | 278 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 275 switches::kSbDisableAutoUpdate)) | 279 switches::kSbDisableAutoUpdate)) |
| 276 return; | 280 return; |
| 277 MessageLoop::current()->PostDelayedTask( | 281 base::MessageLoop::current()->PostDelayedTask( |
| 278 FROM_HERE, | 282 FROM_HERE, |
| 279 base::Bind(&ClientSideDetectionService::StartFetchModel, | 283 base::Bind(&ClientSideDetectionService::StartFetchModel, |
| 280 weak_factory_.GetWeakPtr()), | 284 weak_factory_.GetWeakPtr()), |
| 281 base::TimeDelta::FromMilliseconds(delay_ms)); | 285 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 282 } | 286 } |
| 283 | 287 |
| 284 void ClientSideDetectionService::StartFetchModel() { | 288 void ClientSideDetectionService::StartFetchModel() { |
| 285 if (enabled_) { | 289 if (enabled_) { |
| 286 // Start fetching the model either from the cache or possibly from the | 290 // Start fetching the model either from the cache or possibly from the |
| 287 // network if the model isn't in the cache. | 291 // network if the model isn't in the cache. |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 const std::string& report_url) { | 642 const std::string& report_url) { |
| 639 std::string url = report_url; | 643 std::string url = report_url; |
| 640 std::string api_key = google_apis::GetAPIKey(); | 644 std::string api_key = google_apis::GetAPIKey(); |
| 641 if (!api_key.empty()) { | 645 if (!api_key.empty()) { |
| 642 base::StringAppendF(&url, "?key=%s", | 646 base::StringAppendF(&url, "?key=%s", |
| 643 net::EscapeQueryParamValue(api_key, true).c_str()); | 647 net::EscapeQueryParamValue(api_key, true).c_str()); |
| 644 } | 648 } |
| 645 return url; | 649 return url; |
| 646 } | 650 } |
| 647 } // namespace safe_browsing | 651 } // namespace safe_browsing |
| OLD | NEW |