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
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124

content / browser / attribution_reporting / attribution_manager.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_MANAGER_H_
#define CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_MANAGER_H_

#include <optional>
#include <vector>

#include "base/functional/callback_forward.h"
#include "content/browser/attribution_reporting/attribution_report.h"
#include "content/common/content_export.h"
#include "content/public/browser/attribution_data_model.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/mojom/attribution.mojom-forward.h"

namespace attribution_reporting {
class SuitableOrigin;
struct RegistrationHeaderError;
}  // namespace attribution_reporting

namespace base {
class Time;
}  // namespace base

namespace content {

class AttributionDataHostManager;
class AttributionObserver;
class AttributionTrigger;
class BrowserContext;
class BrowsingDataFilterBuilder;
class StorableSource;
class StoredSource;
class WebContents;

struct GlobalRenderFrameHostId;
struct OsRegistration;

// Interface that mediates data flow between the network, storage layer, and
// blink.
class CONTENT_EXPORT AttributionManager : public AttributionDataModel {
 public:
  static AttributionManager* FromWebContents(WebContents* web_contents);

  static AttributionManager* FromBrowserContext(BrowserContext*);

  static network::mojom::AttributionSupport GetAttributionSupport(
      bool client_os_disabled);

  ~AttributionManager() override = default;

  virtual void AddObserver(AttributionObserver* observer) = 0;

  virtual void RemoveObserver(AttributionObserver* observer) = 0;

  // Gets manager responsible for tracking pending data hosts targeting `this`.
  virtual AttributionDataHostManager* GetDataHostManager() = 0;

  // Persists the given |source| to storage. Called when a navigation
  // originating from a source tag finishes.
  virtual void HandleSource(StorableSource source,
                            GlobalRenderFrameHostId render_frame_id) = 0;

  // Process a newly registered trigger. Will create and log any new
  // reports to storage.
  virtual void HandleTrigger(AttributionTrigger trigger,
                             GlobalRenderFrameHostId render_frame_id) = 0;

  virtual void HandleOsRegistration(OsRegistration) = 0;

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

  // Get all pending reports that are currently stored in this partition. Used
  // for populating WebUI and simulator.
  virtual void GetPendingReportsForInternalUse(
      int limit,
      base::OnceCallback<void(std::vector<AttributionReport>)> callback) = 0;

  // Sends the given report immediately, and runs |done| once it has been sent.
  virtual void SendReportForWebUI(AttributionReport::Id,
                                  base::OnceClosure done) = 0;

  // Deletes all data in storage for storage keys matching `filter`, between
  // `delete_begin` and `delete_end` time.
  //
  // If `filter` is null, then consider all storage keys in storage as matching.
  //
  // Precondition: `filter` should be built from the `filter_builder`, as well
  // as any check that requires inspecting the `SpecialStoragePolicy` which
  // isn't covered by `BrowsingDataFilterBuilder`.
  //
  // The only reason `filter_builder` needs to be passed here is for
  // communication with the Android system of the raw data in the filter. Caller
  // maintains ownership of `filter_builder`.
  virtual void ClearData(base::Time delete_begin,
                         base::Time delete_end,
                         StoragePartition::StorageKeyMatcherFunction filter,
                         BrowsingDataFilterBuilder* filter_builder,
                         bool delete_rate_limit_data,
                         base::OnceClosure done) = 0;

  // If debug mode is enabled, noise and delays are disabled to facilitate
  // testing, whether automated or manual. If `enabled` is `std::nullopt`,
  // falls back to `switches::kAttributionReportingDebugMode`.
  virtual void SetDebugMode(std::optional<bool> enabled,
                            base::OnceClosure done) = 0;

  // Report errors from header validation.
  virtual void ReportRegistrationHeaderError(
      attribution_reporting::SuitableOrigin reporting_origin,
      const attribution_reporting::RegistrationHeaderError&,
      const attribution_reporting::SuitableOrigin& context_origin,
      bool is_within_fenced_frame,
      GlobalRenderFrameHostId render_frame_id) = 0;
};

}  // namespace content

#endif  // CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_MANAGER_H_