Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: storage/browser/quota/quota_settings.cc

Issue 2777183010: [Quota] Lower quota for ephemeral mode (ie. session only) (Closed)
Patch Set: comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « storage/browser/quota/quota_settings.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "storage/browser/quota/quota_settings.h" 5 #include "storage/browser/quota/quota_settings.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/rand_util.h"
10 #include "base/sys_info.h" 11 #include "base/sys_info.h"
11 12
12 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 13 #define UMA_HISTOGRAM_MBYTES(name, sample) \
13 UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \ 14 UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \
14 10 * 1024 * 1024 /* 10TB */, 100) 15 10 * 1024 * 1024 /* 10TB */, 100)
15 16
16 namespace storage { 17 namespace storage {
17 18
19 namespace {
20
21 // Skews |value| by +/- |percent|.
22 int64_t RandomizeByPercent(int64_t value, int percent) {
23 double random_percent = (base::RandDouble() - 0.5) * percent * 2;
24 return value + (value * (random_percent / 100.0));
25 }
26
27 } // anonymous namespace
28
18 base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings( 29 base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings(
19 const base::FilePath& partition_path, 30 const base::FilePath& partition_path,
20 bool is_incognito) { 31 bool is_incognito) {
21 const int64_t kMBytes = 1024 * 1024; 32 const int64_t kMBytes = 1024 * 1024;
33 const int kRandomizedPercentage = 10;
22 34
23 if (is_incognito) { 35 if (is_incognito) {
36 // The incognito pool size is a fraction of the amount of system memory,
37 // and the amount is capped to a hard limit.
38 const double kIncognitoPoolSizeRatio = 0.1; // 10%
39 const int64_t kMaxIncognitoPoolSize = 300 * kMBytes;
40
24 storage::QuotaSettings settings; 41 storage::QuotaSettings settings;
25 settings.pool_size = 42 settings.pool_size = std::min(
26 std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10); 43 RandomizeByPercent(kMaxIncognitoPoolSize, kRandomizedPercentage),
44 static_cast<int64_t>(base::SysInfo::AmountOfPhysicalMemory() *
45 kIncognitoPoolSizeRatio));
27 settings.per_host_quota = settings.pool_size / 3; 46 settings.per_host_quota = settings.pool_size / 3;
47 settings.session_only_per_host_quota = settings.per_host_quota;
28 settings.refresh_interval = base::TimeDelta::Max(); 48 settings.refresh_interval = base::TimeDelta::Max();
29 return settings; 49 return settings;
30 } 50 }
31 51
32 // The fraction of the device's storage the browser is willing to 52 // The fraction of the device's storage the browser is willing to
33 // use for temporary storage, this is applied after adjusting the 53 // use for temporary storage, this is applied after adjusting the
34 // total to take os_accomodation into account. 54 // total to take os_accomodation into account.
35 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% 55 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
36 56
37 // The fraction of the device's storage the browser attempts to 57 // The fraction of the device's storage the browser attempts to
38 // keep free. 58 // keep free.
39 const double kShouldRemainAvailableRatio = 0.1; // 10% 59 const double kShouldRemainAvailableRatio = 0.1; // 10%
40 60
41 // The fraction of the device's storage the browser attempts to 61 // The fraction of the device's storage the browser attempts to
42 // keep free at all costs. 62 // keep free at all costs.
43 const double kMustRemainAvailableRatio = 0.01; // 1% 63 const double kMustRemainAvailableRatio = 0.01; // 1%
44 64
45 // Determines the portion of the temp pool that can be 65 // Determines the portion of the temp pool that can be
46 // utilized by a single host (ie. 5 for 20%). 66 // utilized by a single host (ie. 5 for 20%).
47 const int kPerHostTemporaryPortion = 5; 67 const int kPerHostTemporaryPortion = 5;
48 68
69 // SessionOnly (or ephemeral) origins are allotted a fraction of what
70 // normal origins are provided, and the amount is capped to a hard limit.
71 const double kSessionOnlyHostQuotaRatio = 0.1; // 10%
72 const int64_t kMaxSessionOnlyHostQuota = 300 * kMBytes;
73
49 // os_accomodation is an estimate of how much storage is needed for 74 // os_accomodation is an estimate of how much storage is needed for
50 // the os and essential application code outside of the browser. 75 // the os and essential application code outside of the browser.
51 const int64_t kDefaultOSAccomodation = 76 const int64_t kDefaultOSAccomodation =
52 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
53 1000 * kMBytes; 78 1000 * kMBytes;
54 #elif defined(OS_CHROMEOS) 79 #elif defined(OS_CHROMEOS)
55 1000 * kMBytes; 80 1000 * kMBytes;
56 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) 81 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
57 10000 * kMBytes; 82 10000 * kMBytes;
58 #else 83 #else
(...skipping 15 matching lines...) Expand all
74 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta", 99 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta",
75 kDefaultOSAccomodation - os_accomodation); 100 kDefaultOSAccomodation - os_accomodation);
76 101
77 int64_t adjusted_total = total - os_accomodation; 102 int64_t adjusted_total = total - os_accomodation;
78 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio; 103 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio;
79 104
80 settings.pool_size = pool_size; 105 settings.pool_size = pool_size;
81 settings.should_remain_available = total * kShouldRemainAvailableRatio; 106 settings.should_remain_available = total * kShouldRemainAvailableRatio;
82 settings.must_remain_available = total * kMustRemainAvailableRatio; 107 settings.must_remain_available = total * kMustRemainAvailableRatio;
83 settings.per_host_quota = pool_size / kPerHostTemporaryPortion; 108 settings.per_host_quota = pool_size / kPerHostTemporaryPortion;
109 settings.session_only_per_host_quota = std::min(
110 RandomizeByPercent(kMaxSessionOnlyHostQuota, kRandomizedPercentage),
111 static_cast<int64_t>(settings.per_host_quota *
112 kSessionOnlyHostQuotaRatio));
84 settings.refresh_interval = base::TimeDelta::FromSeconds(60); 113 settings.refresh_interval = base::TimeDelta::FromSeconds(60);
85 return settings; 114 return settings;
86 } 115 }
87 116
88 } // namespace 117 } // namespace
OLDNEW
« no previous file with comments | « storage/browser/quota/quota_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698