File: subresource_url_authorizations.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (98 lines) | stat: -rw-r--r-- 3,888 bytes parent folder | download | duplicates (8)
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 2022 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_INTEREST_GROUP_SUBRESOURCE_URL_AUTHORIZATIONS_H_
#define CONTENT_BROWSER_INTEREST_GROUP_SUBRESOURCE_URL_AUTHORIZATIONS_H_

#include <map>
#include <vector>

#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/browser/interest_group/subresource_url_builder.h"
#include "content/common/content_export.h"

namespace content {

// Manages the subresource URLs that may be fetched by the worklet process (for
// a given WorkletOwner).
//
// Owned by the AuctionURLLoaderFactoryProxy.
class CONTENT_EXPORT SubresourceUrlAuthorizations {
 public:
  SubresourceUrlAuthorizations();
  ~SubresourceUrlAuthorizations();

  explicit SubresourceUrlAuthorizations(const SubresourceUrlAuthorizations&) =
      delete;
  SubresourceUrlAuthorizations& operator=(const SubresourceUrlAuthorizations&) =
      delete;

  // Returns the BundleSubresourceInfo for `subresource_url` iff the worklet is
  // authorized to access `subresource_url`, otherwise returns std::nullopt. To
  // be called by the AuctionURLLoaderFactoryProxy.
  //
  // Returned pointer is invaliadted if AuthorizeSubresourceUrls() or
  // OnWorkletHandleDestruction() is called.
  const SubresourceUrlBuilder::BundleSubresourceInfo* GetAuthorizationInfo(
      const GURL& subresource_url) const;

  // Returns true if no URLs are authorized. NOTE: this can return true even if
  // the WorkletHandle map is not empty -- but every WorkletHandle must have
  // authorized 0 URLs.
  bool IsEmptyForTesting() const;

 private:
  friend class AuctionWorkletManager::WorkletHandle;
  friend class SubresourceUrlAuthorizationsTest;
  friend class AuctionUrlLoaderFactoryProxyTest;

  struct BundleSubresourceInfoAndCount {
    explicit BundleSubresourceInfoAndCount(
        SubresourceUrlBuilder::BundleSubresourceInfo full_info);

    SubresourceUrlBuilder::BundleSubresourceInfo full_info;
    int count = 0;
  };

  // Below are called by WorkletHandle and tests via friendship.

  // Authorize the worklet to access all subresource URLs in
  // `authorized_subresource_urls` for the duration of the lifetime of
  // `worklet_handle`.
  //
  // If a registration already exists for `worklet_handle` does nothing.
  void AuthorizeSubresourceUrls(
      const AuctionWorkletManager::WorkletHandle* worklet_handle,
      const std::vector<SubresourceUrlBuilder::BundleSubresourceInfo>&
          authorized_subresource_urls);

  // Unregisters `worklet_handle` and decrements the counts of all subresource
  // URLs registered by `worklet_handle` -- any subresource URLs whose counts
  // that reach 0 will be removed.
  //
  // To be called by the WorkletHandle destructor.
  void OnWorkletHandleDestruction(
      const AuctionWorkletManager::WorkletHandle* worklet_handle);

  // Tracks the subresource URLs associated with the given WorkletHandle so that
  // the `authorized_subresource_urls_` counts for those subresource
  // URLs can be decremented when the WorkletHandle is
  // destroyed.
  std::map<const AuctionWorkletManager::WorkletHandle*, std::vector<GURL>>
      subresource_urls_per_handle_;

  // Stores as keys the list of all subresource URLs that may be accessed by the
  // worklet associated with the AuctionURLLoaderFactoryProxy that owns this
  // SubresourceUrlAuthorizations.
  //
  // The mapped value keeps the BundleSubresourceInfo needed to access the
  // subresource URL and a count of how many WorkletHandles have authorized the
  // given subresource URL key -- when the count decrements to 0, the pair is
  // removed.
  std::map<GURL, BundleSubresourceInfoAndCount> authorized_subresource_urls_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_INTEREST_GROUP_SUBRESOURCE_URL_AUTHORIZATIONS_H_