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

content / browser / attribution_reporting / attribution_internals_handler_impl.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_INTERNALS_HANDLER_IMPL_H_
#define CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_INTERNALS_HANDLER_IMPL_H_

#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "content/browser/attribution_reporting/attribution_internals.mojom.h"
#include "content/browser/attribution_reporting/attribution_manager.h"
#include "content/browser/attribution_reporting/attribution_observer.h"
#include "content/browser/attribution_reporting/attribution_reporting.mojom-forward.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace attribution_reporting {
struct OsRegistrationItem;
}  // namespace attribution_reporting

namespace url {
class Origin;
}  // namespace url

namespace content {

class WebUI;

// Implements the mojo endpoint for the attribution internals WebUI which
// proxies calls to the `AttributionManager` to get information about stored
// attribution data. Also observes the manager in order to push events, e.g.
// reports being sent or dropped, to the internals WebUI. Owned by
// `AttributionInternalsUI`.
class AttributionInternalsHandlerImpl
    : public attribution_internals::mojom::Handler,
      public AttributionObserver {
 public:
  AttributionInternalsHandlerImpl(
      WebUI* web_ui,
      mojo::PendingRemote<attribution_internals::mojom::Observer>,
      mojo::PendingReceiver<attribution_internals::mojom::Handler>);
  AttributionInternalsHandlerImpl(const AttributionInternalsHandlerImpl&) =
      delete;
  AttributionInternalsHandlerImpl& operator=(
      const AttributionInternalsHandlerImpl&) = delete;
  AttributionInternalsHandlerImpl(AttributionInternalsHandlerImpl&&) = delete;
  AttributionInternalsHandlerImpl& operator=(
      AttributionInternalsHandlerImpl&&) = delete;
  ~AttributionInternalsHandlerImpl() override;

  // mojom::AttributionInternalsHandler:
  void IsAttributionReportingEnabled(
      attribution_internals::mojom::Handler::
          IsAttributionReportingEnabledCallback callback) override;
  void SendReport(AttributionReport::Id,
                  attribution_internals::mojom::Handler::SendReportCallback
                      callback) override;
  void ClearStorage(attribution_internals::mojom::Handler::ClearStorageCallback
                        callback) override;

 private:
  // AttributionObserver:
  void OnSourcesChanged() override;
  void OnReportsChanged() override;
  void OnSourceHandled(
      const StorableSource& source,
      base::Time source_time,
      std::optional<uint64_t> cleared_debug_key,
      attribution_reporting::mojom::StoreSourceResult) override;
  void OnReportSent(const AttributionReport& report,
                    bool is_debug_report,
                    const SendResult& info) override;
  void OnDebugReportSent(const AttributionDebugReport&,
                         int status,
                         base::Time) override;
  void OnAggregatableDebugReportSent(
      const AggregatableDebugReport&,
      base::ValueView report_body,
      attribution_reporting::mojom::ProcessAggregatableDebugReportResult,
      const SendAggregatableDebugReportResult&) override;
  void OnTriggerHandled(std::optional<uint64_t> cleared_debug_key,
                        const CreateReportResult& result) override;
  void OnOsRegistration(
      base::Time time,
      const attribution_reporting::OsRegistrationItem&,
      const url::Origin& top_level_origin,
      attribution_reporting::mojom::RegistrationType,
      bool is_debug_key_allowed,
      attribution_reporting::mojom::OsRegistrationResult) override;
  void OnDebugModeChanged(bool debug_mode) override;

  void OnObserverDisconnected();

  const raw_ref<WebUI> web_ui_;

  mojo::Remote<attribution_internals::mojom::Observer> observer_;

  mojo::Receiver<attribution_internals::mojom::Handler> handler_;

  base::ScopedObservation<AttributionManager, AttributionObserver>
      manager_observation_{this};

  base::WeakPtrFactory<AttributionInternalsHandlerImpl> weak_ptr_factory_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_INTERNALS_HANDLER_IMPL_H_