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_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_
10 #include "base/callback_forward.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "chrome/browser/safe_browsing/two_phase_uploader.h"
20 namespace safe_browsing
{
22 class DownloadFeedbackFactory
;
24 // Handles the uploading of a single downloaded binary to the safebrowsing
25 // download feedback service.
26 class DownloadFeedback
: public base::NonThreadSafe
{
28 // Takes ownership of the file pointed to be |file_path|, it will be deleted
29 // when the DownloadFeedback is destructed.
30 static DownloadFeedback
* Create(
31 net::URLRequestContextGetter
* request_context_getter
,
32 base::TaskRunner
* file_task_runner
,
33 const base::FilePath
& file_path
,
34 const std::string
& ping_request
,
35 const std::string
& ping_response
);
37 // The largest file size we support uploading.
38 // Note: changing this will affect the max size of
39 // SBDownloadFeedback.SizeSuccess and SizeFailure histograms.
40 static const int64 kMaxUploadSize
;
42 // The URL where the browser sends download feedback requests.
43 static const char kSbFeedbackURL
[];
45 virtual ~DownloadFeedback() {}
47 // Makes the passed |factory| the factory used to instantiate
48 // a DownloadFeedback. Useful for tests.
49 static void RegisterFactory(DownloadFeedbackFactory
* factory
) {
53 // Start uploading the file to the download feedback service.
54 // |finish_callback| will be called when the upload completes or fails, but is
55 // not called if the upload is cancelled by deleting the DownloadFeedback
56 // while the upload is in progress.
57 virtual void Start(const base::Closure
& finish_callback
) = 0;
59 virtual const std::string
& GetPingRequestForTesting() const = 0;
60 virtual const std::string
& GetPingResponseForTesting() const = 0;
63 // The factory that controls the creation of DownloadFeedback objects.
64 // This is used by tests.
65 static DownloadFeedbackFactory
* factory_
;
68 class DownloadFeedbackFactory
{
70 virtual ~DownloadFeedbackFactory() {}
72 virtual DownloadFeedback
* CreateDownloadFeedback(
73 net::URLRequestContextGetter
* request_context_getter
,
74 base::TaskRunner
* file_task_runner
,
75 const base::FilePath
& file_path
,
76 const std::string
& ping_request
,
77 const std::string
& ping_response
) = 0;
80 } // namespace safe_browsing
82 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_