File: chrome_browsing_data_lifetime_manager.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 (107 lines) | stat: -rw-r--r-- 4,288 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
// 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 CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_LIFETIME_MANAGER_H_
#define CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_LIFETIME_MANAGER_H_

#include <stdint.h>

#include <optional>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/sync/base/user_selectable_type.h"
#include "content/public/browser/browsing_data_remover.h"

namespace content {
class BrowserContext;
}  // namespace content

class Profile;

namespace browsing_data {

// The fields of each item defined in the BrowsingDataSettings policy.
namespace policy_fields {
extern const char kTimeToLiveInHours[];
extern const char kDataTypes[];
}  // namespace policy_fields

}  // namespace browsing_data

// Controls the lifetime of some browsing data.
class ChromeBrowsingDataLifetimeManager : public KeyedService {
 public:
  struct ScheduledRemovalSettings {
    uint64_t remove_mask;
    uint64_t origin_type_mask;
    int time_to_live_in_hours;
  };

  explicit ChromeBrowsingDataLifetimeManager(
      content::BrowserContext* browser_context);
  ChromeBrowsingDataLifetimeManager(const ChromeBrowsingDataLifetimeManager&) =
      delete;
  ChromeBrowsingDataLifetimeManager& operator=(
      const ChromeBrowsingDataLifetimeManager&) = delete;
  ~ChromeBrowsingDataLifetimeManager() override;

  // KeyedService:
  void Shutdown() override;

  // Sets the end time of the period for which data must be deleted, for all
  // configurations. If this is |end_time_for_testing| has no value, use the
  // computed end time from each configuration.
  void SetEndTimeForTesting(std::optional<base::Time> end_time_for_testing) {
    end_time_for_testing_ = std::move(end_time_for_testing);
  }
  void SetBrowsingDataRemoverObserverForTesting(
      content::BrowsingDataRemover::Observer* observer) {
    testing_data_remover_observer_ = observer;
  }

  // Deletes all browsing data specified by the ClearBrowsingDataOnExitList
  // policy for on the record profiles. This blocks shutdown until the required
  // data is deleted. This will be called when the last browser window of a
  // Profile is closed, then browsing data will be cleared according to the
  // ClearBrowsingDataOnExitList policy. The browser and profile will have to be
  // kept alive until the data is deleted. In case the browsing data clearing
  // does not end properly, this may be called at the next startup in order to
  // cleanup any remaining data. The browser and profile must be kept from
  // shutting down while this is running because an early deletion of the
  // profile will abort the browsing data clearing but still notify us that the
  // data was cleared, even if it was not. If |keep_browser_alive|, the browser
  // will be kept alive until the deletion is completed. This should be done if
  // this function is called as part of a shutdown, but not as part of a cleanup
  // at startup.
  void ClearBrowsingDataForOnExitPolicy(bool keep_browser_alive);

 private:
  // Updates the  scheduled removal settings from the prefs.
  void UpdateScheduledRemovalSettings();
  // Deletes data that needs to be deleted, and schedules the next deletion.
  void StartScheduledBrowsingDataRemoval();

  std::vector<ScheduledRemovalSettings> scheduled_removals_settings_;
  PrefChangeRegistrar pref_change_registrar_;
  raw_ptr<Profile> profile_;
  raw_ptr<content::BrowsingDataRemover::Observer, DanglingUntriaged>
      testing_data_remover_observer_ = nullptr;
  std::optional<base::Time> end_time_for_testing_;
  base::WeakPtrFactory<ChromeBrowsingDataLifetimeManager> weak_ptr_factory_{
      this};

  // Checks that the conditions needed to clear the browsing data types are
  // satisfied. 'sync_types' are checked if neither sync nor
  // browser sign in are disabled.
  bool IsConditionSatisfiedForBrowsingDataRemoval(
      const syncer::UserSelectableTypeSet sync_types);
};

#endif  // CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_LIFETIME_MANAGER_H_