File: first_party_sets_handler_database_helper.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 (104 lines) | stat: -rw-r--r-- 4,310 bytes parent folder | download | duplicates (6)
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
// 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_FIRST_PARTY_SETS_FIRST_PARTY_SETS_HANDLER_DATABASE_HELPER_H_
#define CONTENT_BROWSER_FIRST_PARTY_SETS_FIRST_PARTY_SETS_HANDLER_DATABASE_HELPER_H_

#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/sequence_checker.h"
#include "content/common/content_export.h"

namespace net {
class FirstPartySetsCacheFilter;
class FirstPartySetsContextConfig;
class GlobalFirstPartySets;
class SchemefulSite;
}  // namespace net

namespace content {

class FirstPartySetsDatabase;

// A helper class for the access of the underlying First-Party Sets database.
// Owned by the FirstPartySetsHandlerImpl, and will be created on a different
// sequence that supports blocking, i.e. a database sequence, so that none of
// these methods should be called directly on the main thread.
class CONTENT_EXPORT FirstPartySetsHandlerDatabaseHelper {
 public:
  explicit FirstPartySetsHandlerDatabaseHelper(
      const base::FilePath& user_data_directory);

  FirstPartySetsHandlerDatabaseHelper(
      const FirstPartySetsHandlerDatabaseHelper&) = delete;
  FirstPartySetsHandlerDatabaseHelper& operator=(
      const FirstPartySetsHandlerDatabaseHelper&) = delete;
  FirstPartySetsHandlerDatabaseHelper(FirstPartySetsHandlerDatabaseHelper&&) =
      delete;
  FirstPartySetsHandlerDatabaseHelper& operator=(
      FirstPartySetsHandlerDatabaseHelper&&) = delete;

  ~FirstPartySetsHandlerDatabaseHelper();

  // Gets the difference between the previously used FPSs info with the current
  // FPSs info by comparing the combined `old_sets` and `old_config` with the
  // combined `current_sets` and `current_config`. Returns the set of sites
  // that: 1) were in old FPSs but are no longer in current FPSs i.e. leave the
  // FPSs; or, 2) mapped to a different primary site.
  //
  // This method assumes that the sites were normalized properly when the maps
  // were created. Made public only for testing,
  static base::flat_set<net::SchemefulSite> ComputeSetsDiff(
      const net::GlobalFirstPartySets& old_sets,
      const net::FirstPartySetsContextConfig& old_config,
      const net::GlobalFirstPartySets& current_sets,
      const net::FirstPartySetsContextConfig& current_config);

  // Gets the list of sites to clear for the `browser_context_id`. This method
  // wraps a few DB operations: reads the old global sets and policy
  // customization from DB, call `ComputeSetsDiff` with required inputs to
  // compute the list of sites to clear, stores the sites into DB, then reads
  // the final list of sites to be cleared from DB, which can include sites
  // stored during previous browser runs that did not have state cleared.
  std::optional<std::pair<std::vector<net::SchemefulSite>,
                          net::FirstPartySetsCacheFilter>>
  UpdateAndGetSitesToClearForContext(
      const std::string& browser_context_id,
      const net::GlobalFirstPartySets& current_sets,
      const net::FirstPartySetsContextConfig& current_config);

  // Wraps FirstPartySetsDatabase::InsertBrowserContextCleared.
  // Update DB whether site data clearing has been performed for the
  // `browser_context_id`.
  void UpdateClearStatusForContext(const std::string& browser_context_id);

  // Wraps FirstPartySetsDatabase::PersistSets.
  void PersistSets(const std::string& browser_context_id,
                   const net::GlobalFirstPartySets& sets,
                   const net::FirstPartySetsContextConfig& config);

  std::optional<
      std::pair<net::GlobalFirstPartySets, net::FirstPartySetsContextConfig>>
  GetGlobalSetsAndConfigForTesting(const std::string& browser_context_id);

  // Wraps FirstPartySetsDatabase::HasEntryInBrowserContextClearedForTesting.
  bool HasEntryInBrowserContextsClearedForTesting(
      const std::string& browser_context_id);

 private:
  std::unique_ptr<FirstPartySetsDatabase> db_
      GUARDED_BY_CONTEXT(sequence_checker_);

  SEQUENCE_CHECKER(sequence_checker_);
};

}  // namespace content

#endif  // CONTENT_BROWSER_FIRST_PARTY_SETS_FIRST_PARTY_SETS_HANDLER_DATABASE_HELPER_H_