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/download_protection_service.h

Issue 663023007: Include high-fidelity metadata about a download in incident reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: sync to r300417 Created 6 years, 2 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
OLDNEW
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;
robertshield 2014/10/21 13:15:38 nit: line-break here to make it clearer the commen
grt (UTC plus 2) 2014/10/23 19:53:13 Done.
64 typedef base::CallbackList<void(content::DownloadItem*,
65 const ClientDownloadRequest*)>
66 ClientDownloadRequestCallbackList;
robertshield 2014/10/21 13:15:38 Does the list typedef need to be public?
grt (UTC plus 2) 2014/10/23 19:53:13 Yes, since the contained Subscription type is part
robertshield 2014/10/23 20:30:27 The Subscription is but not the SubscriptionList.
grt (UTC plus 2) 2014/10/23 21:02:18 The two ways I've found of not making the Callback
robertshield 2014/10/23 21:43:03 Can't you move the list typedef down into the priv
grt (UTC plus 2) 2014/10/24 01:51:30 Didn't work when I tried it: ...\download_protect
robertshield 2014/10/24 03:05:46 Huh, nm then, as is works for me.
67 typedef scoped_ptr<ClientDownloadRequestCallbackList::Subscription>
68 ClientDownloadRequestSubscription;
69
55 // Creates a download service. The service is initially disabled. You need 70 // Creates a download service. The service is initially disabled. You need
56 // to call SetEnabled() to start it. |sb_service| owns this object; we 71 // to call SetEnabled() to start it. |sb_service| owns this object; we
57 // keep a reference to |request_context_getter|. 72 // keep a reference to |request_context_getter|.
58 DownloadProtectionService( 73 DownloadProtectionService(
59 SafeBrowsingService* sb_service, 74 SafeBrowsingService* sb_service,
60 net::URLRequestContextGetter* request_context_getter); 75 net::URLRequestContextGetter* request_context_getter);
61 76
62 virtual ~DownloadProtectionService(); 77 virtual ~DownloadProtectionService();
63 78
64 // Checks whether the given client download is likely to be malicious or not. 79 // 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
100 115
101 // Returns the timeout that is used by CheckClientDownload(). 116 // Returns the timeout that is used by CheckClientDownload().
102 int64 download_request_timeout_ms() const { 117 int64 download_request_timeout_ms() const {
103 return download_request_timeout_ms_; 118 return download_request_timeout_ms_;
104 } 119 }
105 120
106 DownloadFeedbackService* feedback_service() { 121 DownloadFeedbackService* feedback_service() {
107 return feedback_service_.get(); 122 return feedback_service_.get();
108 } 123 }
109 124
125 // Registers a callback that will be run when a ClientDownloadRequest has
126 // been formed.
127 ClientDownloadRequestSubscription RegisterClientDownloadRequestCallback(
128 const ClientDownloadRequestCallback& callback);
129
110 protected: 130 protected:
111 // Enum to keep track why a particular download verdict was chosen. 131 // Enum to keep track why a particular download verdict was chosen.
112 // This is used to keep some stats around. 132 // This is used to keep some stats around.
113 enum DownloadCheckResultReason { 133 enum DownloadCheckResultReason {
114 REASON_INVALID_URL, 134 REASON_INVALID_URL,
115 REASON_SB_DISABLED, 135 REASON_SB_DISABLED,
116 REASON_WHITELISTED_URL, 136 REASON_WHITELISTED_URL,
117 REASON_WHITELISTED_REFERRER, 137 REASON_WHITELISTED_REFERRER,
118 REASON_INVALID_REQUEST_PROTO, 138 REASON_INVALID_REQUEST_PROTO,
119 REASON_SERVER_PING_FAILED, 139 REASON_SERVER_PING_FAILED,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Keeps track of the state of the service. 211 // Keeps track of the state of the service.
192 bool enabled_; 212 bool enabled_;
193 213
194 // BinaryFeatureExtractor object, may be overridden for testing. 214 // BinaryFeatureExtractor object, may be overridden for testing.
195 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_; 215 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor_;
196 216
197 int64 download_request_timeout_ms_; 217 int64 download_request_timeout_ms_;
198 218
199 scoped_ptr<DownloadFeedbackService> feedback_service_; 219 scoped_ptr<DownloadFeedbackService> feedback_service_;
200 220
221 // A list of callbacks to be run on the main thread when a
222 // ClientDownloadRequest has been formed.
223 ClientDownloadRequestCallbackList client_download_request_callbacks_;
224
201 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); 225 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService);
202 }; 226 };
203 } // namespace safe_browsing 227 } // namespace safe_browsing
204 228
205 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ 229 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698