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

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

Issue 2777183010: [Quota] Lower quota for ephemeral mode (ie. session only) (Closed)
Patch Set: randomize 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
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;
24 return value + (value * (random_percent / 50.0));
25 }
26
27 } // anon 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 k10Percent = 10;
jsbell 2017/04/04 16:23:57 This should probably be named with respect to what
michaeln 2017/04/05 01:20:56 Done.
22 34
23 if (is_incognito) { 35 if (is_incognito) {
24 storage::QuotaSettings settings; 36 storage::QuotaSettings settings;
25 settings.pool_size = 37 settings.pool_size = std::min(RandomizeByPercent(300 * kMBytes, k10Percent),
jsbell 2017/04/04 16:23:57 Can we make the 300*kMBytes a constant, e.g. kMaxM
michaeln 2017/04/05 01:20:56 Done.
26 std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10); 38 base::SysInfo::AmountOfPhysicalMemory() / 10);
jsbell 2017/04/04 16:23:57 Can we make the 10 here a constant, e.g. kMemoryQu
michaeln 2017/04/05 01:20:56 Done.
27 settings.per_host_quota = settings.pool_size / 3; 39 settings.per_host_quota = settings.pool_size / 3;
40 settings.session_only_per_host_quota = settings.per_host_quota;
28 settings.refresh_interval = base::TimeDelta::Max(); 41 settings.refresh_interval = base::TimeDelta::Max();
29 return settings; 42 return settings;
30 } 43 }
31 44
32 // The fraction of the device's storage the browser is willing to 45 // The fraction of the device's storage the browser is willing to
33 // use for temporary storage, this is applied after adjusting the 46 // use for temporary storage, this is applied after adjusting the
34 // total to take os_accomodation into account. 47 // total to take os_accomodation into account.
35 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% 48 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
36 49
37 // The fraction of the device's storage the browser attempts to 50 // The fraction of the device's storage the browser attempts to
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta", 87 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta",
75 kDefaultOSAccomodation - os_accomodation); 88 kDefaultOSAccomodation - os_accomodation);
76 89
77 int64_t adjusted_total = total - os_accomodation; 90 int64_t adjusted_total = total - os_accomodation;
78 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio; 91 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio;
79 92
80 settings.pool_size = pool_size; 93 settings.pool_size = pool_size;
81 settings.should_remain_available = total * kShouldRemainAvailableRatio; 94 settings.should_remain_available = total * kShouldRemainAvailableRatio;
82 settings.must_remain_available = total * kMustRemainAvailableRatio; 95 settings.must_remain_available = total * kMustRemainAvailableRatio;
83 settings.per_host_quota = pool_size / kPerHostTemporaryPortion; 96 settings.per_host_quota = pool_size / kPerHostTemporaryPortion;
97 settings.session_only_per_host_quota =
98 std::min(RandomizeByPercent(300 * kMBytes, k10Percent),
cmumford 2017/04/04 16:38:29 This doesn't actually do what the title of issue 6
michaeln 2017/04/05 01:20:56 I've decoupled them from one another rather than l
99 settings.per_host_quota / 10);
84 settings.refresh_interval = base::TimeDelta::FromSeconds(60); 100 settings.refresh_interval = base::TimeDelta::FromSeconds(60);
85 return settings; 101 return settings;
86 } 102 }
87 103
88 } // namespace 104 } // namespace
OLDNEW
« storage/browser/quota/quota_settings.h ('K') | « storage/browser/quota/quota_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698