OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 15 #include "content/public/browser/download_danger_type.h" |
| 16 |
| 17 namespace base { |
| 18 class TaskRunner; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 class DownloadItem; |
| 23 } |
| 24 |
| 25 namespace net { |
| 26 class URLRequestContextGetter; |
| 27 } |
| 28 |
| 29 namespace safe_browsing { |
| 30 |
| 31 class DownloadFeedback; |
| 32 |
| 33 // Tracks active DownloadFeedback objects, provides interface for storing ping |
| 34 // data for malicious downloads. |
| 35 class DownloadFeedbackService : public base::NonThreadSafe { |
| 36 public: |
| 37 |
| 38 DownloadFeedbackService(net::URLRequestContextGetter* request_context_getter, |
| 39 base::TaskRunner* file_task_runner); |
| 40 ~DownloadFeedbackService(); |
| 41 |
| 42 // Stores the request and response ping data from the download check, if the |
| 43 // check result and file size are eligible. This must be called after a |
| 44 // download has been flagged as malicious in order for the download to be |
| 45 // enabled for uploading. |
| 46 static void MaybeStorePingsForDownload( |
| 47 DownloadProtectionService::DownloadCheckResult result, |
| 48 content::DownloadItem* download, |
| 49 const std::string& ping, |
| 50 const std::string& response); |
| 51 |
| 52 // Test if pings have been stored for |download|. |
| 53 static bool IsEnabledForDownload(const content::DownloadItem& download); |
| 54 |
| 55 // Get the ping values stored in |download|. Returns false if no ping values |
| 56 // are present. |
| 57 static bool GetPingsForDownloadForTesting( |
| 58 const content::DownloadItem& download, |
| 59 std::string* ping, |
| 60 std::string* response); |
| 61 |
| 62 // Records histogram for download feedback option shown to user. |
| 63 static void RecordFeedbackButtonShown( |
| 64 content::DownloadDangerType danger_type); |
| 65 |
| 66 // Begin download feedback for |download|. The |download| will be deleted |
| 67 // when this function returns. This must only be called if |
| 68 // IsEnabledForDownload is true for |download|. |
| 69 void BeginFeedbackForDownload(content::DownloadItem* download); |
| 70 |
| 71 private: |
| 72 void BeginFeedback(const std::string& ping_request, |
| 73 const std::string& ping_response, |
| 74 const base::FilePath& path); |
| 75 void FeedbackComplete(DownloadFeedback* feedback); |
| 76 |
| 77 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 78 scoped_refptr<base::TaskRunner> file_task_runner_; |
| 79 |
| 80 // Currently active uploads. |
| 81 std::set<DownloadFeedback*> active_feedback_; |
| 82 |
| 83 base::WeakPtrFactory<DownloadFeedbackService> weak_ptr_factory_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(DownloadFeedbackService); |
| 86 }; |
| 87 } // namespace safe_browsing |
| 88 |
| 89 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_ |
OLD | NEW |