Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / safe_browsing / download_feedback_service.h
blob65a7f1fdaf7e9500a7c677ad24a768319bd25eab
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.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_vector.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"
17 namespace base {
18 class TaskRunner;
21 namespace content {
22 class DownloadItem;
25 namespace net {
26 class URLRequestContextGetter;
29 namespace safe_browsing {
31 class DownloadFeedback;
33 // Tracks active DownloadFeedback objects, provides interface for storing ping
34 // data for malicious downloads.
35 class DownloadFeedbackService : public base::NonThreadSafe {
36 public:
37 DownloadFeedbackService(net::URLRequestContextGetter* request_context_getter,
38 base::TaskRunner* file_task_runner);
39 ~DownloadFeedbackService();
41 // Stores the request and response ping data from the download check, if the
42 // check result and file size are eligible. This must be called after a
43 // download has been flagged as malicious in order for the download to be
44 // enabled for uploading.
45 static void MaybeStorePingsForDownload(
46 DownloadProtectionService::DownloadCheckResult result,
47 content::DownloadItem* download,
48 const std::string& ping,
49 const std::string& response);
51 // Test if pings have been stored for |download|.
52 static bool IsEnabledForDownload(const content::DownloadItem& download);
54 // Get the ping values stored in |download|. Returns false if no ping values
55 // are present.
56 static bool GetPingsForDownloadForTesting(
57 const content::DownloadItem& download,
58 std::string* ping,
59 std::string* response);
61 // Records histogram for download feedback option shown to user.
62 static void RecordEligibleDownloadShown(
63 content::DownloadDangerType danger_type);
65 // Begin download feedback for |download|. The |download| will be deleted
66 // when this function returns. This must only be called if
67 // IsEnabledForDownload is true for |download|.
68 void BeginFeedbackForDownload(content::DownloadItem* download);
70 private:
71 static void BeginFeedbackOrDeleteFile(
72 const scoped_refptr<base::TaskRunner>& file_task_runner,
73 const base::WeakPtr<DownloadFeedbackService>& service,
74 const std::string& ping_request,
75 const std::string& ping_response,
76 const base::FilePath& path);
77 void StartPendingFeedback();
78 void BeginFeedback(const std::string& ping_request,
79 const std::string& ping_response,
80 const base::FilePath& path);
81 void FeedbackComplete();
83 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
84 scoped_refptr<base::TaskRunner> file_task_runner_;
86 // Currently active & pending uploads. The first item is active, remaining
87 // items are pending.
88 ScopedVector<DownloadFeedback> active_feedback_;
90 base::WeakPtrFactory<DownloadFeedbackService> weak_ptr_factory_;
92 DISALLOW_COPY_AND_ASSIGN(DownloadFeedbackService);
94 } // namespace safe_browsing
96 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_SERVICE_H_