| 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 // Helper class which handles communication with the SafeBrowsing servers for | 5 // Helper class which handles communication with the SafeBrowsing servers for |
| 6 // improved binary download protection. | 6 // improved binary download protection. |
| 7 | 7 |
| 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 8 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| 9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 9 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| 10 | 10 |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/callback_list.h" |
| 17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 18 #include "base/gtest_prod_util.h" | 19 #include "base/gtest_prod_util.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_ptr.h" |
| 20 #include "chrome/browser/safe_browsing/database_manager.h" | 22 #include "chrome/browser/safe_browsing/database_manager.h" |
| 21 #include "chrome/browser/safe_browsing/ui_manager.h" | 23 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 22 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 23 | 25 |
| 24 | 26 |
| 25 namespace content { | 27 namespace content { |
| 26 class DownloadItem; | 28 class DownloadItem; |
| 27 class PageNavigator; | 29 class PageNavigator; |
| 28 } | 30 } |
| 29 | 31 |
| 30 namespace net { | 32 namespace net { |
| 31 class URLRequestContextGetter; | 33 class URLRequestContextGetter; |
| 32 class X509Certificate; | 34 class X509Certificate; |
| 33 } // namespace net | 35 } // namespace net |
| 34 | 36 |
| 35 namespace safe_browsing { | 37 namespace safe_browsing { |
| 38 class BinaryFeatureExtractor; |
| 39 class ClientDownloadRequest; |
| 36 class DownloadFeedbackService; | 40 class DownloadFeedbackService; |
| 37 class BinaryFeatureExtractor; | |
| 38 | 41 |
| 39 // This class provides an asynchronous API to check whether a particular | 42 // This class provides an asynchronous API to check whether a particular |
| 40 // client download is malicious or not. | 43 // client download is malicious or not. |
| 41 class DownloadProtectionService { | 44 class DownloadProtectionService { |
| 42 public: | 45 public: |
| 43 enum DownloadCheckResult { | 46 enum DownloadCheckResult { |
| 44 UNKNOWN, | 47 UNKNOWN, |
| 45 SAFE, | 48 SAFE, |
| 46 DANGEROUS, | 49 DANGEROUS, |
| 47 UNCOMMON, | 50 UNCOMMON, |
| 48 DANGEROUS_HOST, | 51 DANGEROUS_HOST, |
| 49 POTENTIALLY_UNWANTED | 52 POTENTIALLY_UNWANTED |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 // Callback type which is invoked once the download request is done. | 55 // Callback type which is invoked once the download request is done. |
| 53 typedef base::Callback<void(DownloadCheckResult)> CheckDownloadCallback; | 56 typedef base::Callback<void(DownloadCheckResult)> CheckDownloadCallback; |
| 54 | 57 |
| 58 // A type of callback run on the main thread when a ClientDownloadRequest has |
| 59 // been formed for a download, or when one has not been formed for a supported |
| 60 // download. |
| 61 typedef base::Callback<void(content::DownloadItem*, |
| 62 const ClientDownloadRequest*)> |
| 63 ClientDownloadRequestCallback; |
| 64 |
| 65 // A list of ClientDownloadRequest callbacks. |
| 66 typedef base::CallbackList<void(content::DownloadItem*, |
| 67 const ClientDownloadRequest*)> |
| 68 ClientDownloadRequestCallbackList; |
| 69 |
| 70 // A subscription to a registered ClientDownloadRequest callback. |
| 71 typedef scoped_ptr<ClientDownloadRequestCallbackList::Subscription> |
| 72 ClientDownloadRequestSubscription; |
| 73 |
| 55 // Creates a download service. The service is initially disabled. You need | 74 // Creates a download service. The service is initially disabled. You need |
| 56 // to call SetEnabled() to start it. |sb_service| owns this object; we | 75 // to call SetEnabled() to start it. |sb_service| owns this object; we |
| 57 // keep a reference to |request_context_getter|. | 76 // keep a reference to |request_context_getter|. |
| 58 DownloadProtectionService( | 77 DownloadProtectionService( |
| 59 SafeBrowsingService* sb_service, | 78 SafeBrowsingService* sb_service, |
| 60 net::URLRequestContextGetter* request_context_getter); | 79 net::URLRequestContextGetter* request_context_getter); |
| 61 | 80 |
| 62 virtual ~DownloadProtectionService(); | 81 virtual ~DownloadProtectionService(); |
| 63 | 82 |
| 64 // Checks whether the given client download is likely to be malicious or not. | 83 // Checks whether the given client download is likely to be malicious or not. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 119 |
| 101 // Returns the timeout that is used by CheckClientDownload(). | 120 // Returns the timeout that is used by CheckClientDownload(). |
| 102 int64 download_request_timeout_ms() const { | 121 int64 download_request_timeout_ms() const { |
| 103 return download_request_timeout_ms_; | 122 return download_request_timeout_ms_; |
| 104 } | 123 } |
| 105 | 124 |
| 106 DownloadFeedbackService* feedback_service() { | 125 DownloadFeedbackService* feedback_service() { |
| 107 return feedback_service_.get(); | 126 return feedback_service_.get(); |
| 108 } | 127 } |
| 109 | 128 |
| 129 // Registers a callback that will be run when a ClientDownloadRequest has |
| 130 // been formed. |
| 131 ClientDownloadRequestSubscription RegisterClientDownloadRequestCallback( |
| 132 const ClientDownloadRequestCallback& callback); |
| 133 |
| 110 protected: | 134 protected: |
| 111 // Enum to keep track why a particular download verdict was chosen. | 135 // Enum to keep track why a particular download verdict was chosen. |
| 112 // This is used to keep some stats around. | 136 // This is used to keep some stats around. |
| 113 enum DownloadCheckResultReason { | 137 enum DownloadCheckResultReason { |
| 114 REASON_INVALID_URL, | 138 REASON_INVALID_URL, |
| 115 REASON_SB_DISABLED, | 139 REASON_SB_DISABLED, |
| 116 REASON_WHITELISTED_URL, | 140 REASON_WHITELISTED_URL, |
| 117 REASON_WHITELISTED_REFERRER, | 141 REASON_WHITELISTED_REFERRER, |
| 118 REASON_INVALID_REQUEST_PROTO, | 142 REASON_INVALID_REQUEST_PROTO, |
| 119 REASON_SERVER_PING_FAILED, | 143 REASON_SERVER_PING_FAILED, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // Keeps track of the state of the service. | 215 // Keeps track of the state of the service. |
| 192 bool enabled_; | 216 bool enabled_; |
| 193 | 217 |
| 194 // BinaryFeatureExtractor object, may be overridden for testing. | 218 // BinaryFeatureExtractor object, may be overridden for testing. |
| 195 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; | 219 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; |
| 196 | 220 |
| 197 int64 download_request_timeout_ms_; | 221 int64 download_request_timeout_ms_; |
| 198 | 222 |
| 199 scoped_ptr<DownloadFeedbackService> feedback_service_; | 223 scoped_ptr<DownloadFeedbackService> feedback_service_; |
| 200 | 224 |
| 225 // A list of callbacks to be run on the main thread when a |
| 226 // ClientDownloadRequest has been formed. |
| 227 ClientDownloadRequestCallbackList client_download_request_callbacks_; |
| 228 |
| 201 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); | 229 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); |
| 202 }; | 230 }; |
| 203 } // namespace safe_browsing | 231 } // namespace safe_browsing |
| 204 | 232 |
| 205 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 233 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
| OLD | NEW |