| 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" |
| 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/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/metrics/sparse_histogram.h" | 15 #include "base/metrics/sparse_histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/thread_task_runner_handle.h" |
| 20 #include "base/time/time.h" | 22 #include "base/time/time.h" |
| 21 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/safe_browsing/client_model.pb.h" | 27 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 26 #include "chrome/common/safe_browsing/csd.pb.h" | 28 #include "chrome/common/safe_browsing/csd.pb.h" |
| 27 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 29 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 28 #include "components/variations/variations_associated_data.h" | 30 #include "components/variations/variations_associated_data.h" |
| 29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 client_malware_reports_.end()); | 174 client_malware_reports_.end()); |
| 173 client_malware_reports_.clear(); | 175 client_malware_reports_.clear(); |
| 174 cache_.clear(); | 176 cache_.clear(); |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 void ClientSideDetectionService::SendClientReportPhishingRequest( | 180 void ClientSideDetectionService::SendClientReportPhishingRequest( |
| 179 ClientPhishingRequest* verdict, | 181 ClientPhishingRequest* verdict, |
| 180 const ClientReportPhishingRequestCallback& callback) { | 182 const ClientReportPhishingRequestCallback& callback) { |
| 181 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 182 base::MessageLoop::current()->PostTask( | 184 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 183 FROM_HERE, | 185 FROM_HERE, |
| 184 base::Bind(&ClientSideDetectionService::StartClientReportPhishingRequest, | 186 base::Bind(&ClientSideDetectionService::StartClientReportPhishingRequest, |
| 185 weak_factory_.GetWeakPtr(), verdict, callback)); | 187 weak_factory_.GetWeakPtr(), verdict, callback)); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void ClientSideDetectionService::SendClientReportMalwareRequest( | 190 void ClientSideDetectionService::SendClientReportMalwareRequest( |
| 189 ClientMalwareRequest* verdict, | 191 ClientMalwareRequest* verdict, |
| 190 const ClientReportMalwareRequestCallback& callback) { | 192 const ClientReportMalwareRequestCallback& callback) { |
| 191 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 192 base::MessageLoop::current()->PostTask( | 194 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 193 FROM_HERE, | 195 FROM_HERE, |
| 194 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, | 196 base::Bind(&ClientSideDetectionService::StartClientReportMalwareRequest, |
| 195 weak_factory_.GetWeakPtr(), verdict, callback)); | 197 weak_factory_.GetWeakPtr(), verdict, callback)); |
| 196 } | 198 } |
| 197 | 199 |
| 198 bool ClientSideDetectionService::IsPrivateIPAddress( | 200 bool ClientSideDetectionService::IsPrivateIPAddress( |
| 199 const std::string& ip_address) const { | 201 const std::string& ip_address) const { |
| 200 net::IPAddressNumber ip_number; | 202 net::IPAddressNumber ip_number; |
| 201 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { | 203 if (!net::ParseIPLiteralToNumber(ip_address, &ip_number)) { |
| 202 DVLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; | 204 DVLOG(2) << "Unable to parse IP address: '" << ip_address << "'"; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 content::RenderProcessHost::AllHostsIterator()); | 268 content::RenderProcessHost::AllHostsIterator()); |
| 267 !i.IsAtEnd(); i.Advance()) { | 269 !i.IsAtEnd(); i.Advance()) { |
| 268 SendModelToProcess(i.GetCurrentValue()); | 270 SendModelToProcess(i.GetCurrentValue()); |
| 269 } | 271 } |
| 270 } | 272 } |
| 271 | 273 |
| 272 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { | 274 void ClientSideDetectionService::ScheduleFetchModel(int64 delay_ms) { |
| 273 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 275 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 274 switches::kSbDisableAutoUpdate)) | 276 switches::kSbDisableAutoUpdate)) |
| 275 return; | 277 return; |
| 276 base::MessageLoop::current()->PostDelayedTask( | 278 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 277 FROM_HERE, | 279 FROM_HERE, base::Bind(&ClientSideDetectionService::StartFetchModel, |
| 278 base::Bind(&ClientSideDetectionService::StartFetchModel, | 280 weak_factory_.GetWeakPtr()), |
| 279 weak_factory_.GetWeakPtr()), | |
| 280 base::TimeDelta::FromMilliseconds(delay_ms)); | 281 base::TimeDelta::FromMilliseconds(delay_ms)); |
| 281 } | 282 } |
| 282 | 283 |
| 283 // static | 284 // static |
| 284 std::string ClientSideDetectionService::MakeModelName() { | 285 std::string ClientSideDetectionService::MakeModelName() { |
| 285 std::string num_str = variations::GetVariationParamValue( | 286 std::string num_str = variations::GetVariationParamValue( |
| 286 kClientModelFinchExperiment, kClientModelFinchParam); | 287 kClientModelFinchExperiment, kClientModelFinchParam); |
| 287 int model_number = 0; | 288 int model_number = 0; |
| 288 if (!base::StringToInt(num_str, &model_number)) { | 289 if (!base::StringToInt(num_str, &model_number)) { |
| 289 model_number = 0; // Default model | 290 model_number = 0; // Default model |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 GURL ClientSideDetectionService::GetClientReportUrl( | 676 GURL ClientSideDetectionService::GetClientReportUrl( |
| 676 const std::string& report_url) { | 677 const std::string& report_url) { |
| 677 GURL url(report_url); | 678 GURL url(report_url); |
| 678 std::string api_key = google_apis::GetAPIKey(); | 679 std::string api_key = google_apis::GetAPIKey(); |
| 679 if (!api_key.empty()) | 680 if (!api_key.empty()) |
| 680 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 681 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 681 | 682 |
| 682 return url; | 683 return url; |
| 683 } | 684 } |
| 684 } // namespace safe_browsing | 685 } // namespace safe_browsing |
| OLD | NEW |