OLD | NEW |
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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 const base::TimeDelta ClientSideDetectionService::kReportsInterval = | 35 const base::TimeDelta ClientSideDetectionService::kReportsInterval = |
36 base::TimeDelta::FromDays(1); | 36 base::TimeDelta::FromDays(1); |
37 const base::TimeDelta ClientSideDetectionService::kNegativeCacheInterval = | 37 const base::TimeDelta ClientSideDetectionService::kNegativeCacheInterval = |
38 base::TimeDelta::FromDays(1); | 38 base::TimeDelta::FromDays(1); |
39 const base::TimeDelta ClientSideDetectionService::kPositiveCacheInterval = | 39 const base::TimeDelta ClientSideDetectionService::kPositiveCacheInterval = |
40 base::TimeDelta::FromMinutes(30); | 40 base::TimeDelta::FromMinutes(30); |
41 | 41 |
42 const char ClientSideDetectionService::kClientReportPhishingUrl[] = | 42 const char ClientSideDetectionService::kClientReportPhishingUrl[] = |
43 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing"; | 43 "https://sb-ssl.google.com/safebrowsing/clientreport/phishing"; |
| 44 // Note: when updatng the model version, don't forget to change the filename |
| 45 // in chrome/common/chrome_constants.cc as well, or else existing users won't |
| 46 // download the new model. |
| 47 // |
| 48 // TODO(bryner): add version metadata so that clients can download new models |
| 49 // without needing a new model filename. |
44 const char ClientSideDetectionService::kClientModelUrl[] = | 50 const char ClientSideDetectionService::kClientModelUrl[] = |
45 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v0.pb"; | 51 "https://ssl.gstatic.com/safebrowsing/csd/client_model_v1.pb"; |
46 | 52 |
47 struct ClientSideDetectionService::ClientReportInfo { | 53 struct ClientSideDetectionService::ClientReportInfo { |
48 scoped_ptr<ClientReportPhishingRequestCallback> callback; | 54 scoped_ptr<ClientReportPhishingRequestCallback> callback; |
49 GURL phishing_url; | 55 GURL phishing_url; |
50 }; | 56 }; |
51 | 57 |
52 ClientSideDetectionService::CacheState::CacheState(bool phish, base::Time time) | 58 ClientSideDetectionService::CacheState::CacheState(bool phish, base::Time time) |
53 : is_phishing(phish), | 59 : is_phishing(phish), |
54 timestamp(time) {} | 60 timestamp(time) {} |
55 | 61 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 service.get()->callback_factory_.NewCallback( | 98 service.get()->callback_factory_.NewCallback( |
93 &ClientSideDetectionService::OpenModelFileDone); | 99 &ClientSideDetectionService::OpenModelFileDone); |
94 if (!base::FileUtilProxy::CreateOrOpen( | 100 if (!base::FileUtilProxy::CreateOrOpen( |
95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
96 model_path, | 102 model_path, |
97 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 103 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
98 cb)) { | 104 cb)) { |
99 delete cb; | 105 delete cb; |
100 return NULL; | 106 return NULL; |
101 } | 107 } |
| 108 |
| 109 // Delete the previous-version model file. |
| 110 // TODO(bryner): Remove this for M14. |
| 111 base::FileUtilProxy::Delete( |
| 112 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 113 model_path.DirName().AppendASCII("Safe Browsing Phishing Model"), |
| 114 false /* not recursive */, |
| 115 NULL /* not interested in result */); |
102 return service.release(); | 116 return service.release(); |
103 } | 117 } |
104 | 118 |
105 void ClientSideDetectionService::SendClientReportPhishingRequest( | 119 void ClientSideDetectionService::SendClientReportPhishingRequest( |
106 ClientPhishingRequest* verdict, | 120 ClientPhishingRequest* verdict, |
107 ClientReportPhishingRequestCallback* callback) { | 121 ClientReportPhishingRequestCallback* callback) { |
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
109 MessageLoop::current()->PostTask( | 123 MessageLoop::current()->PostTask( |
110 FROM_HERE, | 124 FROM_HERE, |
111 method_factory_.NewRunnableMethod( | 125 method_factory_.NewRunnableMethod( |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } else { | 453 } else { |
440 DLOG(FATAL) << "Unable to parse IP address range: " | 454 DLOG(FATAL) << "Unable to parse IP address range: " |
441 << kPrivateNetworks[i]; | 455 << kPrivateNetworks[i]; |
442 return false; | 456 return false; |
443 } | 457 } |
444 } | 458 } |
445 return true; | 459 return true; |
446 } | 460 } |
447 | 461 |
448 } // namespace safe_browsing | 462 } // namespace safe_browsing |
OLD | NEW |