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/content_url_request_user_data.h" |
27 #include "content/public/common/url_fetcher.h" | 28 #include "content/public/common/url_fetcher.h" |
28 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
29 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
30 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
31 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
32 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
33 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
34 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
35 | 36 |
36 using content::BrowserThread; | 37 using content::BrowserThread; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 247 } |
247 | 248 |
248 void ClientSideDetectionService::StartFetchModel() { | 249 void ClientSideDetectionService::StartFetchModel() { |
249 if (enabled_) { | 250 if (enabled_) { |
250 // Start fetching the model either from the cache or possibly from the | 251 // Start fetching the model either from the cache or possibly from the |
251 // network if the model isn't in the cache. | 252 // network if the model isn't in the cache. |
252 model_fetcher_.reset(content::URLFetcher::Create( | 253 model_fetcher_.reset(content::URLFetcher::Create( |
253 0 /* ID used for testing */, GURL(kClientModelUrl), | 254 0 /* ID used for testing */, GURL(kClientModelUrl), |
254 content::URLFetcher::GET, this)); | 255 content::URLFetcher::GET, this)); |
255 model_fetcher_->SetRequestContext(request_context_getter_.get()); | 256 model_fetcher_->SetRequestContext(request_context_getter_.get()); |
| 257 // TODO(jochen): Do cookie audit. |
| 258 model_fetcher_->SetContentURLRequestUserData( |
| 259 new content::ContentURLRequestUserData()); |
256 model_fetcher_->Start(); | 260 model_fetcher_->Start(); |
257 } | 261 } |
258 } | 262 } |
259 | 263 |
260 void ClientSideDetectionService::EndFetchModel(ClientModelStatus status) { | 264 void ClientSideDetectionService::EndFetchModel(ClientModelStatus status) { |
261 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.ClientModelStatus", | 265 UMA_HISTOGRAM_ENUMERATION("SBClientPhishing.ClientModelStatus", |
262 status, | 266 status, |
263 MODEL_STATUS_MAX); | 267 MODEL_STATUS_MAX); |
264 if (status == MODEL_SUCCESS) { | 268 if (status == MODEL_SUCCESS) { |
265 SetBadSubnets(*model_, &bad_subnets_); | 269 SetBadSubnets(*model_, &bad_subnets_); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 content::URLFetcher::POST, this); | 311 content::URLFetcher::POST, this); |
308 | 312 |
309 // Remember which callback and URL correspond to the current fetcher object. | 313 // Remember which callback and URL correspond to the current fetcher object. |
310 ClientReportInfo* info = new ClientReportInfo; | 314 ClientReportInfo* info = new ClientReportInfo; |
311 info->callback = callback; | 315 info->callback = callback; |
312 info->phishing_url = GURL(request->url()); | 316 info->phishing_url = GURL(request->url()); |
313 client_phishing_reports_[fetcher] = info; | 317 client_phishing_reports_[fetcher] = info; |
314 | 318 |
315 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); | 319 fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
316 fetcher->SetRequestContext(request_context_getter_.get()); | 320 fetcher->SetRequestContext(request_context_getter_.get()); |
| 321 // TODO(jochen): Do cookie audit. |
| 322 fetcher->SetContentURLRequestUserData( |
| 323 new content::ContentURLRequestUserData()); |
317 fetcher->SetUploadData("application/octet-stream", request_data); | 324 fetcher->SetUploadData("application/octet-stream", request_data); |
318 fetcher->Start(); | 325 fetcher->Start(); |
319 | 326 |
320 // Record that we made a request | 327 // Record that we made a request |
321 phishing_report_times_.push(base::Time::Now()); | 328 phishing_report_times_.push(base::Time::Now()); |
322 } | 329 } |
323 | 330 |
324 void ClientSideDetectionService::HandleModelResponse( | 331 void ClientSideDetectionService::HandleModelResponse( |
325 const content::URLFetcher* source, | 332 const content::URLFetcher* source, |
326 const GURL& url, | 333 const GURL& url, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 } | 533 } |
527 } | 534 } |
528 for (int i = 0; i < model.page_term_size(); ++i) { | 535 for (int i = 0; i < model.page_term_size(); ++i) { |
529 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { | 536 if (model.page_term(i) < 0 || model.page_term(i) > max_index) { |
530 return false; | 537 return false; |
531 } | 538 } |
532 } | 539 } |
533 return true; | 540 return true; |
534 } | 541 } |
535 } // namespace safe_browsing | 542 } // namespace safe_browsing |
OLD | NEW |