File: attribution_report_network_sender.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (126 lines) | stat: -rw-r--r-- 4,211 bytes parent folder | download | duplicates (5)
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
125
126
// 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_REPORT_NETWORK_SENDER_H_
#define CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_REPORT_NETWORK_SENDER_H_

#include <list>
#include <memory>
#include <string>

#include "base/functional/callback_forward.h"
#include "base/memory/scoped_refptr.h"
#include "build/buildflag.h"
#include "content/browser/attribution_reporting/attribution_report_sender.h"
#include "content/common/content_export.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/application_status_listener.h"
#endif

class GURL;

namespace net {
class HttpResponseHeaders;
}  // namespace net

namespace network {
class SharedURLLoaderFactory;
class SimpleURLLoader;
}  // namespace network

namespace url {
class Origin;
}  // namespace url

namespace content {

class AttributionReport;

// Issues POST requests containing attribution reports. Maintains a set of all
// ongoing UrlLoaders used for posting reports. Created and owned by
// `AttributionManagerImpl`.
class CONTENT_EXPORT AttributionReportNetworkSender
    : public AttributionReportSender {
 public:
  explicit AttributionReportNetworkSender(
      scoped_refptr<network::SharedURLLoaderFactory>);
  AttributionReportNetworkSender(const AttributionReportNetworkSender&) =
      delete;
  AttributionReportNetworkSender& operator=(
      const AttributionReportNetworkSender&) = delete;
  AttributionReportNetworkSender(AttributionReportNetworkSender&&) = delete;
  AttributionReportNetworkSender& operator=(AttributionReportNetworkSender&&) =
      delete;
  ~AttributionReportNetworkSender() override;

  // AttributionReportSender:
  void SetInFirstBatch(bool in_first_batch) override;

  void SendReport(AttributionReport report,
                  bool is_debug_report,
                  ReportSentCallback sent_callback) override;
  void SendReport(AttributionDebugReport report,
                  DebugReportSentCallback) override;

  void SendReport(AggregatableDebugReport,
                  base::DictValue report_body,
                  AggregatableDebugReportSentCallback) override;

 private:
  // This is a std::list so that iterators remain valid during modifications.
  using UrlLoaderList = std::list<std::unique_ptr<network::SimpleURLLoader>>;

  using UrlLoaderCallback =
      base::OnceCallback<void(UrlLoaderList::iterator it,
                              scoped_refptr<net::HttpResponseHeaders>)>;

  void SendReport(GURL url,
                  url::Origin origin,
                  std::string body,
                  UrlLoaderCallback callback);

  // Called when headers are available for a sent report.
  void OnReportSent(const AttributionReport&,
                    bool is_debug_report,
                    ReportSentCallback sent_callback,
                    UrlLoaderList::iterator it,
                    scoped_refptr<net::HttpResponseHeaders> headers);

  // Called when headers are available for a sent verbose debug report.
  void OnVerboseDebugReportSent(
      base::OnceCallback<void(int status)> callback,
      UrlLoaderList::iterator it,
      scoped_refptr<net::HttpResponseHeaders> headers);

  void OnAggregatableDebugReportSent(
      base::OnceCallback<void(int status)> callback,
      UrlLoaderList::iterator,
      scoped_refptr<net::HttpResponseHeaders>);

  // Reports that are actively being sent.
  UrlLoaderList loaders_in_progress_;

  // Used for network requests.
  scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;

  // Used for metric logging.
  bool in_first_batch_ = true;

#if BUILDFLAG(IS_ANDROID)
  // Callback invoked when the application state changes.
  void OnApplicationStateChanged(base::android::ApplicationState state);

  // Listener for changes in application state, unregisters itself when
  // destroyed.
  const std::unique_ptr<base::android::ApplicationStatusListener>
      application_status_listener_;

  base::android::ApplicationState app_state_;
#endif
};

}  // namespace content

#endif  // CONTENT_BROWSER_ATTRIBUTION_REPORTING_ATTRIBUTION_REPORT_NETWORK_SENDER_H_