summaryrefslogtreecommitdiff
path: root/chromium/content/browser/conversions/conversion_manager.h
blob: 337cf3d3cfc2830511c3ea7aafb954c9842bde81 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2020 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 CONTENT_BROWSER_CONVERSIONS_CONVERSION_MANAGER_H_
#define CONTENT_BROWSER_CONVERSIONS_CONVERSION_MANAGER_H_

#include <vector>

#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/containers/circular_deque.h"
#include "content/common/content_export.h"

namespace base {
class Time;
}  // namespace base

namespace url {
class Origin;
}  // namespace url

namespace content {

class ConversionPolicy;
class StorableConversion;
class StorableImpression;
class WebContents;

struct ConversionReport;
struct SentReportInfo;

// Interface that mediates data flow between the network, storage layer, and
// blink.
class CONTENT_EXPORT ConversionManager {
 public:
  // Provides access to a ConversionManager implementation. This layer of
  // abstraction is to allow tests to mock out the ConversionManager without
  // injecting a manager explicitly.
  class Provider {
   public:
    virtual ~Provider() = default;

    // Gets the ConversionManager that should be used for handling conversions
    // that occur in the given |web_contents|. Returns nullptr if conversion
    // measurement is not enabled in the given |web_contents|, e.g. when the
    // browser context is off the record.
    virtual ConversionManager* GetManager(WebContents* web_contents) const = 0;
  };
  virtual ~ConversionManager() = default;

  // Persists the given |impression| to storage. Called when a navigation
  // originating from an impression tag finishes.
  virtual void HandleImpression(StorableImpression impression) = 0;

  // Process a newly registered conversion. Will create and log any new
  // conversion reports to storage.
  virtual void HandleConversion(StorableConversion conversion) = 0;

  // Get all impressions that are currently stored in this partition. Used for
  // populating WebUI.
  virtual void GetActiveImpressionsForWebUI(
      base::OnceCallback<void(std::vector<StorableImpression>)> callback) = 0;

  // Get all pending reports that are currently stored in this partition. Used
  // for populating WebUI.
  virtual void GetPendingReportsForWebUI(
      base::OnceCallback<void(std::vector<ConversionReport>)> callback,
      base::Time max_report_time) = 0;

  // Get all reports sent in this session. Used for populating WebUI. Limited to
  // last 100.
  virtual const base::circular_deque<SentReportInfo>& GetSentReportsForWebUI()
      const WARN_UNUSED_RESULT = 0;

  // Sends all pending reports immediately, and runs |done| once they have all
  // been sent.
  virtual void SendReportsForWebUI(base::OnceClosure done) = 0;

  // Returns the ConversionPolicy that is used to control API policies such
  // as noise.
  virtual const ConversionPolicy& GetConversionPolicy() const
      WARN_UNUSED_RESULT = 0;

  // Deletes all data in storage for URLs matching |filter|, between
  // |delete_begin| and |delete_end| time.
  //
  // If |filter| is null, then consider all origins in storage as matching.
  virtual void ClearData(
      base::Time delete_begin,
      base::Time delete_end,
      base::RepeatingCallback<bool(const url::Origin&)> filter,
      base::OnceClosure done) = 0;
};

}  // namespace content

#endif  // CONTENT_BROWSER_CONVERSIONS_CONVERSION_MANAGER_H_