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 virtual ~DownloadFeedback() {}
44 // Makes the passed |factory| the factory used to instantiate
45 // a DownloadFeedback. Useful for tests.
46 static void RegisterFactory(DownloadFeedbackFactory
* factory
) {
50 // Start uploading the file to the download feedback service.
51 // |finish_callback| will be called when the upload completes or fails, but is
52 // not called if the upload is cancelled by deleting the DownloadFeedback
53 // while the upload is in progress.
54 virtual void Start(const base::Closure
& finish_callback
) = 0;
56 virtual const std::string
& GetPingRequestForTesting() const = 0;
57 virtual const std::string
& GetPingResponseForTesting() const = 0;
60 // The factory that controls the creation of DownloadFeedback objects.
61 // This is used by tests.
62 static DownloadFeedbackFactory
* factory_
;
65 class DownloadFeedbackFactory
{
67 virtual ~DownloadFeedbackFactory() {}
69 virtual DownloadFeedback
* CreateDownloadFeedback(
70 net::URLRequestContextGetter
* request_context_getter
,
71 base::TaskRunner
* file_task_runner
,
72 const base::FilePath
& file_path
,
73 const std::string
& ping_request
,
74 const std::string
& ping_response
) = 0;
77 } // namespace safe_browsing
79 #endif // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_