Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/safe_browsing/client_side_detection_service.cc

Issue 6014003: Intergration of the client-side phishing detection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dont DCHECK because some unit tests are failing. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/logging.h" 10 #include "base/logging.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/platform_file.h" 13 #include "base/platform_file.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browser_thread.h" 19 #include "chrome/browser/browser_thread.h"
20 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
19 #include "chrome/browser/safe_browsing/csd.pb.h" 21 #include "chrome/browser/safe_browsing/csd.pb.h"
22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
23 #include "chrome/browser/tab_contents/tab_contents.h"
24 #include "chrome/browser/tab_contents/tab_util.h"
25 #include "chrome/common/chrome_switches.h"
lzheng 2011/02/11 19:39:42 Is this used somewhere? You might want to double c
noelutz 2011/02/15 23:00:55 Done.
20 #include "chrome/common/net/http_return.h" 26 #include "chrome/common/net/http_return.h"
21 #include "chrome/common/net/url_fetcher.h" 27 #include "chrome/common/net/url_fetcher.h"
22 #include "chrome/common/net/url_request_context_getter.h" 28 #include "chrome/common/net/url_request_context_getter.h"
23 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
24 #include "net/base/load_flags.h" 30 #include "net/base/load_flags.h"
25 #include "net/url_request/url_request_status.h" 31 #include "net/url_request/url_request_status.h"
32 #include "webkit/glue/resource_type.h"
26 33
27 namespace safe_browsing { 34 namespace safe_browsing {
28 35
29 const int ClientSideDetectionService::kMaxReportsPerDay = 3; 36 const int ClientSideDetectionService::kMaxReportsPerDay = 3;
30 37
31 const char ClientSideDetectionService::kClientReportPhishingUrl[] = 38 const char ClientSideDetectionService::kClientReportPhishingUrl[] =
32 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing"; 39 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing";
33 const char ClientSideDetectionService::kClientModelUrl[] = 40 const char ClientSideDetectionService::kClientModelUrl[] =
34 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb"; 41 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb";
35 42
36 struct ClientSideDetectionService::ClientReportInfo { 43 struct ClientSideDetectionService::ClientReportInfo {
37 scoped_ptr<ClientReportPhishingRequestCallback> callback; 44 scoped_ptr<ClientReportPhishingRequestCallback> callback;
38 GURL phishing_url; 45 GURL phishing_url;
39 }; 46 };
40 47
41 ClientSideDetectionService::ClientSideDetectionService( 48 ClientSideDetectionService::ClientSideDetectionService(
42 const FilePath& model_path, 49 const FilePath& model_path,
43 URLRequestContextGetter* request_context_getter) 50 URLRequestContextGetter* request_context_getter)
44 : model_path_(model_path), 51 : model_path_(model_path),
45 model_status_(UNKNOWN_STATUS), 52 model_status_(UNKNOWN_STATUS),
46 model_file_(base::kInvalidPlatformFileValue), 53 model_file_(base::kInvalidPlatformFileValue),
47 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 54 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
48 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), 55 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
49 request_context_getter_(request_context_getter) { 56 request_context_getter_(request_context_getter) {
50 } 57 }
51 58
59 ClientSideDetectionService::ClientSideDetectionService()
60 : model_path_(),
Brian Ryner 2011/02/11 01:30:39 As I mentioned on another CL, I'm kind of concerne
noelutz 2011/02/15 23:00:55 Done.
61 model_status_(UNKNOWN_STATUS),
62 model_file_(base::kInvalidPlatformFileValue),
63 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
64 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
65 request_context_getter_(NULL) {
66 }
67
52 ClientSideDetectionService::~ClientSideDetectionService() { 68 ClientSideDetectionService::~ClientSideDetectionService() {
53 method_factory_.RevokeAll(); 69 method_factory_.RevokeAll();
54 STLDeleteContainerPairPointers(client_phishing_reports_.begin(), 70 STLDeleteContainerPairPointers(client_phishing_reports_.begin(),
55 client_phishing_reports_.end()); 71 client_phishing_reports_.end());
56 client_phishing_reports_.clear(); 72 client_phishing_reports_.clear();
57 STLDeleteElements(&open_callbacks_); 73 STLDeleteElements(&open_callbacks_);
58 CloseModelFile(); 74 CloseModelFile();
59 } 75 }
60 76
61 /* static */ 77 /* static */
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 int response_code, 320 int response_code,
305 const ResponseCookies& cookies, 321 const ResponseCookies& cookies,
306 const std::string& data) { 322 const std::string& data) {
307 ClientPhishingResponse response; 323 ClientPhishingResponse response;
308 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); 324 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]);
309 if (status.is_success() && RC_REQUEST_OK == response_code && 325 if (status.is_success() && RC_REQUEST_OK == response_code &&
310 response.ParseFromString(data)) { 326 response.ParseFromString(data)) {
311 info->callback->Run(info->phishing_url, response.phishy()); 327 info->callback->Run(info->phishing_url, response.phishy());
312 } else { 328 } else {
313 DLOG(ERROR) << "Unable to get the server verdict for URL: " 329 DLOG(ERROR) << "Unable to get the server verdict for URL: "
314 << info->phishing_url; 330 << info->phishing_url << " status: " << status.status() << " "
331 << "response_code:" << response_code;
315 info->callback->Run(info->phishing_url, false); 332 info->callback->Run(info->phishing_url, false);
316 } 333 }
317 client_phishing_reports_.erase(source); 334 client_phishing_reports_.erase(source);
318 delete source; 335 delete source;
319 } 336 }
320 337
321 int ClientSideDetectionService::GetNumReportsPerDay() { 338 int ClientSideDetectionService::GetNumReportsPerDay() {
322 base::Time cutoff = base::Time::Now() - base::TimeDelta::FromDays(1); 339 base::Time cutoff = base::Time::Now() - base::TimeDelta::FromDays(1);
323 340
324 // Erase elements older than a day because we will never care about them 341 // Erase elements older than a day because we will never care about them
325 // again. 342 // again.
326 while (!phishing_report_times_.empty() && 343 while (!phishing_report_times_.empty() &&
327 phishing_report_times_.front() < cutoff) { 344 phishing_report_times_.front() < cutoff) {
328 phishing_report_times_.pop(); 345 phishing_report_times_.pop();
329 } 346 }
330 347
331 // Return the number of elements that are above the cutoff. 348 // Return the number of elements that are above the cutoff.
332 return phishing_report_times_.size(); 349 return phishing_report_times_.size();
333 } 350 }
334 351
335 } // namespace safe_browsing 352 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698