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 // 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 #pragma once | 10 #pragma once |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // Enables or disables the service. This is usually called by the | 89 // Enables or disables the service. This is usually called by the |
90 // SafeBrowsingService, which tracks whether any profile uses these services | 90 // SafeBrowsingService, which tracks whether any profile uses these services |
91 // at all. Disabling causes any pending and future requests to have their | 91 // at all. Disabling causes any pending and future requests to have their |
92 // callbacks called with "SAFE" results. | 92 // callbacks called with "SAFE" results. |
93 void SetEnabled(bool enabled); | 93 void SetEnabled(bool enabled); |
94 | 94 |
95 bool enabled() const { | 95 bool enabled() const { |
96 return enabled_; | 96 return enabled_; |
97 } | 97 } |
98 | 98 |
| 99 // Returns the timeout that is used by CheckClientDownload(). |
| 100 int64 download_request_timeout_ms() const { |
| 101 return download_request_timeout_ms_; |
| 102 } |
| 103 |
99 protected: | 104 protected: |
100 // Enum to keep track why a particular download verdict was chosen. | 105 // Enum to keep track why a particular download verdict was chosen. |
101 // This is used to keep some stats around. | 106 // This is used to keep some stats around. |
102 enum DownloadCheckResultReason { | 107 enum DownloadCheckResultReason { |
103 REASON_INVALID_URL, | 108 REASON_INVALID_URL, |
104 REASON_SB_DISABLED, | 109 REASON_SB_DISABLED, |
105 REASON_WHITELISTED_URL, | 110 REASON_WHITELISTED_URL, |
106 REASON_WHITELISTED_REFERRER, | 111 REASON_WHITELISTED_REFERRER, |
107 REASON_INVALID_REQUEST_PROTO, | 112 REASON_INVALID_REQUEST_PROTO, |
108 REASON_SERVER_PING_FAILED, | 113 REASON_SERVER_PING_FAILED, |
(...skipping 11 matching lines...) Expand all Loading... |
120 | 125 |
121 private: | 126 private: |
122 class CheckClientDownloadRequest; // Per-request state | 127 class CheckClientDownloadRequest; // Per-request state |
123 friend class DownloadProtectionServiceTest; | 128 friend class DownloadProtectionServiceTest; |
124 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 129 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
125 CheckClientDownloadValidateRequest); | 130 CheckClientDownloadValidateRequest); |
126 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 131 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
127 CheckClientDownloadSuccess); | 132 CheckClientDownloadSuccess); |
128 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, | 133 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
129 CheckClientDownloadFetchFailed); | 134 CheckClientDownloadFetchFailed); |
| 135 FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, |
| 136 TestDownloadRequestTimeout); |
130 | 137 |
131 static const char kDownloadRequestUrl[]; | 138 static const char kDownloadRequestUrl[]; |
132 | 139 |
133 // Cancels all requests in |download_requests_|, and empties it, releasing | 140 // Cancels all requests in |download_requests_|, and empties it, releasing |
134 // the references to the requests. | 141 // the references to the requests. |
135 void CancelPendingRequests(); | 142 void CancelPendingRequests(); |
136 | 143 |
137 // Called by a CheckClientDownloadRequest instance when it finishes, to | 144 // Called by a CheckClientDownloadRequest instance when it finishes, to |
138 // remove it from |download_requests_|. | 145 // remove it from |download_requests_|. |
139 void RequestFinished(CheckClientDownloadRequest* request); | 146 void RequestFinished(CheckClientDownloadRequest* request); |
(...skipping 12 matching lines...) Expand all Loading... |
152 // has to be invoked when the request is done. This map contains all | 159 // has to be invoked when the request is done. This map contains all |
153 // pending server requests. | 160 // pending server requests. |
154 std::set<scoped_refptr<CheckClientDownloadRequest> > download_requests_; | 161 std::set<scoped_refptr<CheckClientDownloadRequest> > download_requests_; |
155 | 162 |
156 // Keeps track of the state of the service. | 163 // Keeps track of the state of the service. |
157 bool enabled_; | 164 bool enabled_; |
158 | 165 |
159 // SignatureUtil object, may be overridden for testing. | 166 // SignatureUtil object, may be overridden for testing. |
160 scoped_refptr<SignatureUtil> signature_util_; | 167 scoped_refptr<SignatureUtil> signature_util_; |
161 | 168 |
| 169 int64 download_request_timeout_ms_; |
| 170 |
162 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); | 171 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); |
163 }; | 172 }; |
164 } // namespace safe_browsing | 173 } // namespace safe_browsing |
165 | 174 |
166 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ | 175 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ |
OLD | NEW |