| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/safe_browsing/client_model.pb.h" | 20 #include "chrome/common/safe_browsing/client_model.pb.h" |
| 21 #include "chrome/common/safe_browsing/csd.pb.h" | 21 #include "chrome/common/safe_browsing/csd.pb.h" |
| 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" | 22 #include "chrome/common/safe_browsing/safebrowsing_messages.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/common/url_fetcher.h" | |
| 28 #include "crypto/sha2.h" | 27 #include "crypto/sha2.h" |
| 29 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
| 30 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
| 31 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_status_code.h" | 31 #include "net/http/http_status_code.h" |
| 32 #include "net/url_request/url_fetcher.h" |
| 33 #include "net/url_request/url_request_context_getter.h" | 33 #include "net/url_request/url_request_context_getter.h" |
| 34 #include "net/url_request/url_request_status.h" | 34 #include "net/url_request/url_request_status.h" |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 | 37 |
| 38 namespace safe_browsing { | 38 namespace safe_browsing { |
| 39 | 39 |
| 40 const size_t ClientSideDetectionService::kMaxModelSizeBytes = 90 * 1024; | 40 const size_t ClientSideDetectionService::kMaxModelSizeBytes = 90 * 1024; |
| 41 const int ClientSideDetectionService::kMaxReportsPerInterval = 3; | 41 const int ClientSideDetectionService::kMaxReportsPerInterval = 3; |
| 42 // TODO(noelutz): once we know this mechanism works as intended we should fetch | 42 // TODO(noelutz): once we know this mechanism works as intended we should fetch |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 FROM_HERE, | 242 FROM_HERE, |
| 243 base::Bind(&ClientSideDetectionService::StartFetchModel, | 243 base::Bind(&ClientSideDetectionService::StartFetchModel, |
| 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(net::URLFetcher::Create( |
| 253 0 /* ID used for testing */, GURL(kClientModelUrl), | 253 0 /* ID used for testing */, GURL(kClientModelUrl), |
| 254 net::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, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 net::URLFetcher* fetcher = content::URLFetcher::Create( | 305 net::URLFetcher* fetcher = net::URLFetcher::Create( |
| 306 0 /* ID used for testing */, GURL(kClientReportPhishingUrl), | 306 0 /* ID used for testing */, GURL(kClientReportPhishingUrl), |
| 307 net::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); |
| (...skipping 210 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 |