File: download_feedback.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (79 lines) | stat: -rw-r--r-- 2,759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_
#define CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_

#include <stdint.h>

#include <string>

#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "base/threading/non_thread_safe.h"
#include "chrome/browser/safe_browsing/two_phase_uploader.h"

namespace safe_browsing {

class DownloadFeedbackFactory;

// Handles the uploading of a single downloaded binary to the safebrowsing
// download feedback service.
class DownloadFeedback : public base::NonThreadSafe {
 public:
  // Takes ownership of the file pointed to be |file_path|, it will be deleted
  // when the DownloadFeedback is destructed.
  static std::unique_ptr<DownloadFeedback> Create(
      net::URLRequestContextGetter* request_context_getter,
      base::TaskRunner* file_task_runner,
      const base::FilePath& file_path,
      const std::string& ping_request,
      const std::string& ping_response);

  // The largest file size we support uploading.
  // Note: changing this will affect the max size of
  // SBDownloadFeedback.SizeSuccess and SizeFailure histograms.
  static const int64_t kMaxUploadSize;

  // The URL where the browser sends download feedback requests.
  static const char kSbFeedbackURL[];

  virtual ~DownloadFeedback() {}

  // Makes the passed |factory| the factory used to instantiate
  // a DownloadFeedback. Useful for tests.
  static void RegisterFactory(DownloadFeedbackFactory* factory) {
    factory_ = factory;
  }

  // Start uploading the file to the download feedback service.
  // |finish_callback| will be called when the upload completes or fails, but is
  // not called if the upload is cancelled by deleting the DownloadFeedback
  // while the upload is in progress.
  virtual void Start(const base::Closure& finish_callback) = 0;

  virtual const std::string& GetPingRequestForTesting() const = 0;
  virtual const std::string& GetPingResponseForTesting() const = 0;

 private:
  // The factory that controls the creation of DownloadFeedback objects.
  // This is used by tests.
  static DownloadFeedbackFactory* factory_;
};

class DownloadFeedbackFactory {
 public:
  virtual ~DownloadFeedbackFactory() {}

  virtual std::unique_ptr<DownloadFeedback> CreateDownloadFeedback(
      net::URLRequestContextGetter* request_context_getter,
      base::TaskRunner* file_task_runner,
      const base::FilePath& file_path,
      const std::string& ping_request,
      const std::string& ping_response) = 0;
};

}  // namespace safe_browsing

#endif  // CHROME_BROWSER_SAFE_BROWSING_DOWNLOAD_FEEDBACK_H_