File: quota_settings.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (105 lines) | stat: -rw-r--r-- 4,411 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
99
100
101
102
103
104
105
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_
#define STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_

#include <stdint.h>

#include <optional>

#include "base/component_export.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "storage/browser/quota/quota_device_info_helper.h"

namespace storage {

// Settings the storage lib embedder must provide to the QuotaManager.
struct QuotaSettings {
  QuotaSettings() = default;
  QuotaSettings(int64_t pool_size,
                int64_t per_storage_key_quota,
                int64_t should_remain_available,
                int64_t must_remain_available)
      : pool_size(pool_size),
        per_storage_key_quota(per_storage_key_quota),
        session_only_per_storage_key_quota(per_storage_key_quota),
        should_remain_available(should_remain_available),
        must_remain_available(must_remain_available) {}

  // The target size in bytes of the shared pool of disk space the quota
  // system allows for use by websites using HTML5 storage apis, for
  // example an embedder may use 50% of the total volume size.
  int64_t pool_size = 0;

  // The amount in bytes of the pool an individual site may consume. The
  // value must be less than or equal to the pool_size.
  int64_t per_storage_key_quota = 0;

  // The amount allotted to origins that are considered session only
  // according to the SpecialStoragePolicy provided by the embedder.
  int64_t session_only_per_storage_key_quota = 0;

  // The amount of space that should remain available on the storage
  // volume. As the volume approaches this limit, the quota system gets
  // more aggressive about evicting data.
  int64_t should_remain_available = 0;

  // The amount of space that must remain available on the storage
  // volume. As the volume approaches this limit, the quota system gets
  // very aggressive about disallowing new data.
  int64_t must_remain_available = 0;

  // The quota system queries the embedder for the QuotaSettings,
  // but will rate limit the frequency of the queries to no more than once
  // per refresh interval.
  base::TimeDelta refresh_interval = base::TimeDelta::Max();
};

// Function type used to return the settings in response to a
// GetQuotaSettingsFunc invocation. If the embedder cannot
// produce a settings values, std::nullopt can be returned.
using OptionalQuotaSettingsCallback =
    base::OnceCallback<void(std::optional<QuotaSettings>)>;

// Function type used to query the embedder about the quota manager settings.
// This function is invoked on the UI thread.
using GetQuotaSettingsFunc =
    base::RepeatingCallback<void(OptionalQuotaSettingsCallback callback)>;

// Posts a background task to calculate and report quota settings to the
// |callback| function based on the size of the volume containing the storage
// partition and a guestimate of the size required for the OS. The refresh
// interval is 60 seconds to accommodate changes to the size of the volume.
// Except, in the case of incognito, the pool size and quota values are based
// on the amount of physical memory and the refresh interval is maxed out.
COMPONENT_EXPORT(STORAGE_BROWSER)
void GetNominalDynamicSettings(const base::FilePath& partition_path,
                               bool is_incognito,
                               QuotaDeviceInfoHelper* deviceInfoHelper,
                               OptionalQuotaSettingsCallback callback);

COMPONENT_EXPORT(STORAGE_BROWSER)

// Returns settings that provide given `per_storage_key_quota` and a total
// poolsize of five times that.
inline QuotaSettings GetHardCodedSettings(int64_t per_storage_key_quota) {
  return QuotaSettings(per_storage_key_quota * 5, per_storage_key_quota,
                       per_storage_key_quota, per_storage_key_quota);
}

COMPONENT_EXPORT(STORAGE_BROWSER)
double GetIncognitoQuotaRatioLowerBound_ForTesting();
COMPONENT_EXPORT(STORAGE_BROWSER)
double GetIncognitoQuotaRatioUpperBound_ForTesting();

// Returns object that can fetch actual total disk space; instance lives
// as long as the process is a live.
COMPONENT_EXPORT(STORAGE_BROWSER)
QuotaDeviceInfoHelper* GetDefaultDeviceInfoHelper();
}  // namespace storage

#endif  // STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_