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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service.h

Issue 12313141: Use DownloadItem directly in DownloadProtectionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 7 years, 9 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) 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
(...skipping 21 matching lines...) Expand all
32 class X509Certificate; 32 class X509Certificate;
33 } // namespace net 33 } // namespace net
34 34
35 namespace safe_browsing { 35 namespace safe_browsing {
36 class SignatureUtil; 36 class SignatureUtil;
37 37
38 // This class provides an asynchronous API to check whether a particular 38 // This class provides an asynchronous API to check whether a particular
39 // client download is malicious or not. 39 // client download is malicious or not.
40 class DownloadProtectionService { 40 class DownloadProtectionService {
41 public: 41 public:
42 // TODO(noelutz): we're missing some fields here: server IPs,
43 // tab URL redirect chain, ...
44 struct DownloadInfo {
45 base::FilePath local_file; // Where the download is currently stored.
46 base::FilePath target_file; // Where it will eventually be stored.
47 std::vector<GURL> download_url_chain;
48 GURL referrer_url;
49 std::string sha256_hash;
50 int64 total_bytes;
51 bool user_initiated;
52 std::string remote_address;
53 bool zipped_executable;
54 DownloadInfo();
55 ~DownloadInfo();
56 std::string DebugString() const;
57 // Creates a DownloadInfo from a DownloadItem object.
58 static DownloadInfo FromDownloadItem(const content::DownloadItem& item);
59 };
60
61 enum DownloadCheckResult { 42 enum DownloadCheckResult {
62 SAFE, 43 SAFE,
63 DANGEROUS, 44 DANGEROUS,
64 UNCOMMON, 45 UNCOMMON,
65 DANGEROUS_HOST, 46 DANGEROUS_HOST,
66 }; 47 };
67 48
68 // Callback type which is invoked once the download request is done. 49 // Callback type which is invoked once the download request is done.
69 typedef base::Callback<void(DownloadCheckResult)> CheckDownloadCallback; 50 typedef base::Callback<void(DownloadCheckResult)> CheckDownloadCallback;
70 51
71 // Creates a download service. The service is initially disabled. You need 52 // Creates a download service. The service is initially disabled. You need
72 // to call SetEnabled() to start it. |sb_service| owns this object; we 53 // to call SetEnabled() to start it. |sb_service| owns this object; we
73 // keep a reference to |request_context_getter|. 54 // keep a reference to |request_context_getter|.
74 DownloadProtectionService( 55 DownloadProtectionService(
75 SafeBrowsingService* sb_service, 56 SafeBrowsingService* sb_service,
76 net::URLRequestContextGetter* request_context_getter); 57 net::URLRequestContextGetter* request_context_getter);
77 58
78 virtual ~DownloadProtectionService(); 59 virtual ~DownloadProtectionService();
79 60
80 // Checks whether the given client download is likely to be malicious or not. 61 // Checks whether the given client download is likely to be malicious or not.
81 // The result is delivered asynchronously via the given callback. This 62 // The result is delivered asynchronously via the given callback. This
82 // method must be called on the UI thread, and the callback will also be 63 // method must be called on the UI thread, and the callback will also be
83 // invoked on the UI thread. This method must be called once the download 64 // invoked on the UI thread. This method must be called once the download
84 // is finished and written to disk. 65 // is finished and written to disk.
85 virtual void CheckClientDownload(const DownloadInfo& info, 66 virtual void CheckClientDownload(content::DownloadItem* item,
86 const CheckDownloadCallback& callback); 67 const CheckDownloadCallback& callback);
87 68
88 // Checks whether any of the URLs in the redirect chain of the 69 // Checks whether any of the URLs in the redirect chain of the
89 // download match the SafeBrowsing bad binary URL list. The result is 70 // download match the SafeBrowsing bad binary URL list. The result is
90 // delivered asynchronously via the given callback. This method must be 71 // delivered asynchronously via the given callback. This method must be
91 // called on the UI thread, and the callback will also be invoked on the UI 72 // called on the UI thread, and the callback will also be invoked on the UI
92 // thread. Pre-condition: !info.download_url_chain.empty(). 73 // thread. Pre-condition: !info.download_url_chain.empty().
93 virtual void CheckDownloadUrl(const DownloadInfo& info, 74 virtual void CheckDownloadUrl(const content::DownloadItem& item,
94 const CheckDownloadCallback& callback); 75 const CheckDownloadCallback& callback);
95 76
96 // Returns true iff the download specified by |info| should be scanned by 77 // Returns true iff the download specified by |info| should be scanned by
97 // CheckClientDownload() for malicious content. 78 // CheckClientDownload() for malicious content.
98 virtual bool IsSupportedDownload(const DownloadInfo& info) const; 79 virtual bool IsSupportedDownload(const content::DownloadItem& item,
80 const base::FilePath& target_path) const;
99 81
100 // Display more information to the user regarding the download specified by 82 // Display more information to the user regarding the download specified by
101 // |info|. This method is invoked when the user requests more information 83 // |info|. This method is invoked when the user requests more information
102 // about a download that was marked as malicious. 84 // about a download that was marked as malicious.
103 void ShowDetailsForDownload(const DownloadInfo& info, 85 void ShowDetailsForDownload(const content::DownloadItem& item,
104 content::PageNavigator* navigator); 86 content::PageNavigator* navigator);
105 87
106 // Enables or disables the service. This is usually called by the 88 // Enables or disables the service. This is usually called by the
107 // SafeBrowsingService, which tracks whether any profile uses these services 89 // SafeBrowsingService, which tracks whether any profile uses these services
108 // at all. Disabling causes any pending and future requests to have their 90 // at all. Disabling causes any pending and future requests to have their
109 // callbacks called with "SAFE" results. 91 // callbacks called with "SAFE" results.
110 void SetEnabled(bool enabled); 92 void SetEnabled(bool enabled);
111 93
112 bool enabled() const { 94 bool enabled() const {
113 return enabled_; 95 return enabled_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // SignatureUtil object, may be overridden for testing. 184 // SignatureUtil object, may be overridden for testing.
203 scoped_refptr<SignatureUtil> signature_util_; 185 scoped_refptr<SignatureUtil> signature_util_;
204 186
205 int64 download_request_timeout_ms_; 187 int64 download_request_timeout_ms_;
206 188
207 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService); 189 DISALLOW_COPY_AND_ASSIGN(DownloadProtectionService);
208 }; 190 };
209 } // namespace safe_browsing 191 } // namespace safe_browsing
210 192
211 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_ 193 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_PROTECTION_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_shelf_context_menu.cc ('k') | chrome/browser/safe_browsing/download_protection_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698