| Index: storage/browser/quota/quota_manager.cc
|
| diff --git a/storage/browser/quota/quota_manager.cc b/storage/browser/quota/quota_manager.cc
|
| index 79268a61a297bf966605004646d272d27ea637d9..d8f7b3d16edb121820ff8f1cebb3fc8ac5824d81 100644
|
| --- a/storage/browser/quota/quota_manager.cc
|
| +++ b/storage/browser/quota/quota_manager.cc
|
| @@ -26,6 +26,7 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/sys_info.h"
|
| #include "base/task_runner_util.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "base/time/time.h"
|
| #include "base/trace_event/trace_event.h"
|
| #include "net/base/url_util.h"
|
| @@ -47,19 +48,13 @@ namespace {
|
|
|
| const int64_t kMBytes = 1024 * 1024;
|
| const int kMinutesInMilliSeconds = 60 * 1000;
|
| -
|
| const int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour
|
| -const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33%
|
|
|
| } // namespace
|
|
|
| -// Arbitrary for now, but must be reasonably small so that
|
| -// in-memory databases can fit.
|
| -// TODO(kinuko): Refer SysInfo::AmountOfPhysicalMemory() to determine this.
|
| -const int64_t QuotaManager::kIncognitoDefaultQuotaLimit = 100 * kMBytes;
|
| -
|
| const int64_t QuotaManager::kNoLimit = INT64_MAX;
|
|
|
| +// TODO(michaeln): REMOVE
|
| const int QuotaManager::kPerHostTemporaryPortion = 5; // 20%
|
|
|
| // Cap size for per-host persistent quota determined by the histogram.
|
| @@ -68,17 +63,12 @@ const int QuotaManager::kPerHostTemporaryPortion = 5; // 20%
|
| // usage that is less than 10GB for almost all users.
|
| const int64_t QuotaManager::kPerHostPersistentQuotaLimit = 10 * 1024 * kMBytes;
|
|
|
| +// TODO(michaeln): REMOVE
|
| +int64_t QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes;
|
| +
|
| const char QuotaManager::kDatabaseName[] = "QuotaManager";
|
|
|
| const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3;
|
| -
|
| -// Preserve kMinimumPreserveForSystem disk space for system book-keeping
|
| -// when returning the quota to unlimited apps/extensions.
|
| -// TODO(kinuko): This should be like 10% of the actual disk space.
|
| -// For now we simply use a constant as getting the disk size needs
|
| -// platform-dependent code. (http://crbug.com/178976)
|
| -int64_t QuotaManager::kMinimumPreserveForSystem = 1024 * kMBytes;
|
| -
|
| const int QuotaManager::kEvictionIntervalInMilliSeconds =
|
| 30 * kMinutesInMilliSeconds;
|
|
|
| @@ -234,121 +224,68 @@ bool UpdateModifiedTimeOnDBThread(const GURL& origin,
|
| return database->SetOriginLastModifiedTime(origin, type, modified_time);
|
| }
|
|
|
| -int64_t CalculateTemporaryGlobalQuota(int64_t global_limited_usage,
|
| - int64_t available_space) {
|
| - DCHECK_GE(global_limited_usage, 0);
|
| - int64_t avail_space = available_space;
|
| - if (avail_space <
|
| - std::numeric_limits<int64_t>::max() - global_limited_usage) {
|
| - // We basically calculate the temporary quota by
|
| - // [available_space + space_used_for_temp] * kTempQuotaRatio,
|
| - // but make sure we'll have no overflow.
|
| - avail_space += global_limited_usage;
|
| - }
|
| - int64_t pool_size = avail_space * kTemporaryQuotaRatioToAvail;
|
| - UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size);
|
| - return pool_size;
|
| -}
|
| -
|
| -void DispatchTemporaryGlobalQuotaCallback(
|
| - const QuotaCallback& callback,
|
| - QuotaStatusCode status,
|
| - const UsageAndQuota& usage_and_quota) {
|
| - if (status != kQuotaStatusOk) {
|
| - callback.Run(status, 0);
|
| - return;
|
| - }
|
| -
|
| - callback.Run(status, CalculateTemporaryGlobalQuota(
|
| - usage_and_quota.global_limited_usage,
|
| - usage_and_quota.available_disk_space));
|
| -}
|
| -
|
| -int64_t CalculateQuotaWithDiskSpace(int64_t available_disk_space,
|
| - int64_t usage,
|
| - int64_t quota) {
|
| - if (available_disk_space < QuotaManager::kMinimumPreserveForSystem) {
|
| - LOG(WARNING)
|
| - << "Running out of disk space for profile."
|
| - << " QuotaManager starts forbidding further quota consumption.";
|
| - return usage;
|
| - }
|
| -
|
| - if (quota < usage) {
|
| - // No more space; cap the quota to the current usage.
|
| - return usage;
|
| - }
|
| -
|
| - available_disk_space -= QuotaManager::kMinimumPreserveForSystem;
|
| - if (available_disk_space < quota - usage)
|
| - return available_disk_space + usage;
|
| -
|
| - return quota;
|
| -}
|
| -
|
| -int64_t CalculateTemporaryHostQuota(int64_t host_usage,
|
| - int64_t global_quota,
|
| - int64_t global_limited_usage) {
|
| - DCHECK_GE(global_limited_usage, 0);
|
| - int64_t host_quota = global_quota / QuotaManager::kPerHostTemporaryPortion;
|
| - if (global_limited_usage > global_quota)
|
| - host_quota = std::min(host_quota, host_usage);
|
| - return host_quota;
|
| -}
|
| -
|
| +// TODO: cleanup??
|
| void DispatchUsageAndQuotaForWebApps(
|
| StorageType type,
|
| bool is_incognito,
|
| bool is_unlimited,
|
| - bool can_query_disk_size,
|
| + int64_t cached_usage_for_incognito,
|
| const QuotaManager::GetUsageAndQuotaCallback& callback,
|
| QuotaStatusCode status,
|
| - const UsageAndQuota& usage_and_quota) {
|
| + const XUsageAndQuota& usage_and_quota) {
|
| + DCHECK(type == kStorageTypeTemporary || type == kStorageTypePersistent ||
|
| + type == kStorageTypeSyncable);
|
| if (status != kQuotaStatusOk) {
|
| callback.Run(status, 0, 0);
|
| return;
|
| }
|
|
|
| - int64_t usage = usage_and_quota.usage;
|
| - int64_t quota = usage_and_quota.quota;
|
| -
|
| - if (type == kStorageTypeTemporary && !is_unlimited) {
|
| - quota = CalculateTemporaryHostQuota(
|
| - usage, quota, usage_and_quota.global_limited_usage);
|
| - }
|
| -
|
| + //int64_t available = usage_and_quota.available_disk_space;
|
| if (is_incognito) {
|
| - quota = std::min(quota, QuotaManager::kIncognitoDefaultQuotaLimit);
|
| - callback.Run(status, usage, quota);
|
| - return;
|
| - }
|
| -
|
| - // For apps with unlimited permission or can_query_disk_size is true (and not
|
| - // in incognito mode).
|
| - // We assume we can expose the actual disk size for them and cap the quota by
|
| - // the available disk space.
|
| - if (is_unlimited || can_query_disk_size) {
|
| - quota = CalculateQuotaWithDiskSpace(
|
| - usage_and_quota.available_disk_space,
|
| - usage, quota);
|
| - }
|
| -
|
| - callback.Run(status, usage, quota);
|
| -
|
| - if (type == kStorageTypeTemporary && !is_unlimited)
|
| - UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", quota);
|
| + //int64_t incognito_space_avalable = pool_size -
|
| + // cached_usage_for_incognito;
|
| + //available = std::max(INT64_C(0), incognito_space_avalable);
|
| + }
|
| +
|
| + // For persistent and syncable, usage_and_quota.quota contains a
|
| + // per-host value. For the temporary type, usage_and_quota.quota
|
| + // contains the shared poolsize. Hoever, if the origin is unlimited,
|
| + // it will contain kNoLimit which is INT64_MAX.
|
| + int64_t desired_host_quota = usage_and_quota.quota;
|
| + if (type == kStorageTypeTemporary)
|
| + desired_host_quota /= QuotaManager::kPerHostTemporaryPortion;
|
| +
|
| + int min_preserve = !is_unlimited && (type == kStorageTypeTemporary) ?
|
| + desired_host_quota : QuotaManager::kMinimumPreserveForSystem;
|
| +
|
| + // Constrain the desired |host_quota| to something that fits.
|
| + // If available space is too low, cap usage at current levels.
|
| + // If it's close to being too low, cap growth to avoid it getting too low.
|
| + // We define "too low" as not enough room for another hosts
|
| + // nominal desired amount of data.
|
| + // Note: for incognito, available space is a number based on
|
| + // system memory.
|
| + int64_t host_quota = std::min(
|
| + desired_host_quota,
|
| + usage_and_quota.usage +
|
| + std::max(INT64_C(0),
|
| + usage_and_quota.available_disk_space - min_preserve));
|
| +
|
| + callback.Run(status, usage_and_quota.usage, host_quota);
|
| + if (type == kStorageTypeTemporary && !is_incognito && !is_unlimited)
|
| + UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", host_quota);
|
| }
|
|
|
| } // namespace
|
|
|
| -UsageAndQuota::UsageAndQuota()
|
| +XUsageAndQuota::XUsageAndQuota()
|
| : usage(0),
|
| global_limited_usage(0),
|
| quota(0),
|
| available_disk_space(0) {
|
| }
|
|
|
| -UsageAndQuota::UsageAndQuota(int64_t usage,
|
| +XUsageAndQuota::XUsageAndQuota(int64_t usage,
|
| int64_t global_limited_usage,
|
| int64_t quota,
|
| int64_t available_disk_space)
|
| @@ -357,6 +294,7 @@ UsageAndQuota::UsageAndQuota(int64_t usage,
|
| quota(quota),
|
| available_disk_space(available_disk_space) {}
|
|
|
| +// TODO: cleanup???
|
| class UsageAndQuotaCallbackDispatcher
|
| : public QuotaTask,
|
| public base::SupportsWeakPtr<UsageAndQuotaCallbackDispatcher> {
|
| @@ -373,7 +311,7 @@ class UsageAndQuotaCallbackDispatcher
|
|
|
| ~UsageAndQuotaCallbackDispatcher() override {}
|
|
|
| - void WaitForResults(const QuotaManager::UsageAndQuotaCallback& callback) {
|
| + void WaitForResults(const QuotaManager::XUsageAndQuotaCallback& callback) {
|
| callback_ = callback;
|
| Start();
|
| }
|
| @@ -427,6 +365,12 @@ class UsageAndQuotaCallbackDispatcher
|
| AsWeakPtr());
|
| }
|
|
|
| + TemporaryStorageConfigurationCallback GetTempStorageConfigCallback() {
|
| + ++waiting_callbacks_;
|
| + return base::Bind(&UsageAndQuotaCallbackDispatcher::DidGetTempStorageConfig,
|
| + AsWeakPtr());
|
| + }
|
| +
|
| private:
|
| void DidGetHostUsage(int64_t usage) {
|
| if (status_ == kQuotaStatusUnknown)
|
| @@ -461,6 +405,11 @@ class UsageAndQuotaCallbackDispatcher
|
| CheckCompleted();
|
| }
|
|
|
| + void DidGetTempStorageConfig(const TemporaryStorageConfiguration& config) {
|
| + storage_config_ = config;
|
| + CheckCompleted();
|
| + }
|
| +
|
| void Run() override {
|
| // We initialize waiting_callbacks to 1 so that we won't run
|
| // the completion callback until here even some of the callbacks
|
| @@ -469,7 +418,7 @@ class UsageAndQuotaCallbackDispatcher
|
| }
|
|
|
| void Aborted() override {
|
| - callback_.Run(kQuotaErrorAbort, UsageAndQuota());
|
| + callback_.Run(kQuotaErrorAbort, XUsageAndQuota());
|
| DeleteSoon();
|
| }
|
|
|
| @@ -500,8 +449,9 @@ class UsageAndQuotaCallbackDispatcher
|
| bool has_available_disk_space_;
|
|
|
| QuotaStatusCode status_;
|
| - UsageAndQuota usage_and_quota_;
|
| - QuotaManager::UsageAndQuotaCallback callback_;
|
| + XUsageAndQuota usage_and_quota_;
|
| + TemporaryStorageConfiguration storage_config_;
|
| + QuotaManager::XUsageAndQuotaCallback callback_;
|
| int waiting_callbacks_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaCallbackDispatcher);
|
| @@ -866,21 +816,31 @@ QuotaManager::QuotaManager(
|
| const base::FilePath& profile_path,
|
| const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
|
| const scoped_refptr<base::SequencedTaskRunner>& db_thread,
|
| - const scoped_refptr<SpecialStoragePolicy>& special_storage_policy)
|
| + const scoped_refptr<SpecialStoragePolicy>& special_storage_policy,
|
| + const GetTemporaryStorageConfigurationFunc& get_config_function)
|
| : is_incognito_(is_incognito),
|
| profile_path_(profile_path),
|
| proxy_(new QuotaManagerProxy(this, io_thread)),
|
| db_disabled_(false),
|
| eviction_disabled_(false),
|
| + get_config_function_(get_config_function),
|
| + get_config_task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| io_thread_(io_thread),
|
| db_thread_(db_thread),
|
| is_getting_eviction_origin_(false),
|
| - temporary_quota_initialized_(false),
|
| - temporary_quota_override_(-1),
|
| special_storage_policy_(special_storage_policy),
|
| get_volume_info_fn_(&QuotaManager::GetVolumeInfo),
|
| storage_monitor_(new StorageMonitor(this)),
|
| - weak_factory_(this) {}
|
| + weak_factory_(this) {
|
| + // Reset to ensure we refresh the config the first times it's accessed.
|
| + storage_config_.refresh_interval = base::TimeDelta();
|
| +}
|
| +
|
| +void QuotaManager::SetTemporaryStorageConfiguration(
|
| + const TemporaryStorageConfiguration& config) {
|
| + storage_config_ = config;
|
| + storage_config_timestamp_ = base::TimeTicks::Now();
|
| +}
|
|
|
| void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
|
| LazyInitialize();
|
| @@ -902,22 +862,23 @@ void QuotaManager::GetUsageAndQuotaForWebApps(
|
| callback.Run(kQuotaErrorNotSupported, 0, 0);
|
| return;
|
| }
|
| + if (is_incognito_ && type != kStorageTypeTemporary) {
|
| + callback.Run(kQuotaErrorNotSupported, 0, 0);
|
| + return;
|
| + }
|
|
|
| DCHECK(origin == origin.GetOrigin());
|
| LazyInitialize();
|
|
|
| - bool unlimited = IsStorageUnlimited(origin, type);
|
| - bool can_query_disk_size = CanQueryDiskSize(origin);
|
| + bool is_unlimited = IsStorageUnlimited(origin, type);
|
|
|
| UsageAndQuotaCallbackDispatcher* dispatcher =
|
| new UsageAndQuotaCallbackDispatcher(this);
|
|
|
| - if (unlimited) {
|
| + if (is_unlimited) {
|
| dispatcher->set_quota(kNoLimit);
|
| } else {
|
| if (type == kStorageTypeTemporary) {
|
| - GetUsageTracker(type)->GetGlobalLimitedUsage(
|
| - dispatcher->GetGlobalLimitedUsageCallback());
|
| GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
|
| } else if (type == kStorageTypePersistent) {
|
| GetPersistentHostQuota(net::GetHostOrSpecFromURL(origin),
|
| @@ -927,17 +888,20 @@ void QuotaManager::GetUsageAndQuotaForWebApps(
|
| }
|
| }
|
|
|
| - DCHECK(GetUsageTracker(type));
|
| GetUsageTracker(type)->GetHostUsage(net::GetHostOrSpecFromURL(origin),
|
| dispatcher->GetHostUsageCallback());
|
|
|
| - if (!is_incognito_ && (unlimited || can_query_disk_size))
|
| - GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
|
| + int64_t cached_usage_for_incognito = 0;
|
| + if (!is_incognito_) {
|
| + xGetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
|
| + } else {
|
| + cached_usage_for_incognito = GetUsageTracker(type)->GetCachedUsage();
|
| + }
|
|
|
| dispatcher->WaitForResults(base::Bind(
|
| &DispatchUsageAndQuotaForWebApps,
|
| - type, is_incognito_, unlimited, can_query_disk_size,
|
| - callback));
|
| + type, is_incognito_, is_unlimited,
|
| + cached_usage_for_incognito, callback));
|
| }
|
|
|
| void QuotaManager::GetUsageAndQuota(
|
| @@ -1019,13 +983,14 @@ void QuotaManager::DeleteHostData(const std::string& host,
|
| deleter->Start();
|
| }
|
|
|
| -void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
|
| +void QuotaManager::xGetAvailableSpace(const AvailableSpaceCallback& callback) {
|
| if (!available_space_callbacks_.Add(callback))
|
| return;
|
| // crbug.com/349708
|
| TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace");
|
|
|
| - PostTaskAndReplyWithResult(
|
| + // TODO: if (incognito) return poolsize - globalusage;
|
| + base::PostTaskAndReplyWithResult(
|
| db_thread_.get(),
|
| FROM_HERE,
|
| base::Bind(&QuotaManager::CallGetAmountOfFreeDiskSpace,
|
| @@ -1034,55 +999,18 @@ void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
|
| weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| -void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
|
| - LazyInitialize();
|
| - if (!temporary_quota_initialized_) {
|
| - db_initialization_callbacks_.Add(base::Bind(
|
| - &QuotaManager::GetTemporaryGlobalQuota,
|
| - weak_factory_.GetWeakPtr(), callback));
|
| - return;
|
| - }
|
| -
|
| - if (temporary_quota_override_ > 0) {
|
| - callback.Run(kQuotaStatusOk, temporary_quota_override_);
|
| - return;
|
| - }
|
| -
|
| - UsageAndQuotaCallbackDispatcher* dispatcher =
|
| - new UsageAndQuotaCallbackDispatcher(this);
|
| - GetUsageTracker(kStorageTypeTemporary)->
|
| - GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
|
| - GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
|
| - dispatcher->WaitForResults(
|
| - base::Bind(&DispatchTemporaryGlobalQuotaCallback, callback));
|
| +namespace {
|
| +void ContinueGetTemporaryQuota(
|
| + const QuotaCallback& callback,
|
| + const TemporaryStorageConfiguration& pool_config) {
|
| + callback.Run(kQuotaStatusOk, pool_config.pool_size);
|
| +}
|
| }
|
|
|
| -void QuotaManager::SetTemporaryGlobalOverrideQuota(
|
| - int64_t new_quota,
|
| - const QuotaCallback& callback) {
|
| +void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
|
| LazyInitialize();
|
| -
|
| - if (new_quota < 0) {
|
| - if (!callback.is_null())
|
| - callback.Run(kQuotaErrorInvalidModification, -1);
|
| - return;
|
| - }
|
| -
|
| - if (db_disabled_) {
|
| - if (!callback.is_null())
|
| - callback.Run(kQuotaErrorInvalidAccess, -1);
|
| - return;
|
| - }
|
| -
|
| - int64_t* new_quota_ptr = new int64_t(new_quota);
|
| - PostTaskAndReplyWithResultForDBThread(
|
| - FROM_HERE,
|
| - base::Bind(&SetTemporaryGlobalOverrideQuotaOnDBThread,
|
| - base::Unretained(new_quota_ptr)),
|
| - base::Bind(&QuotaManager::DidSetTemporaryGlobalOverrideQuota,
|
| - weak_factory_.GetWeakPtr(),
|
| - callback,
|
| - base::Owned(new_quota_ptr)));
|
| + GetTemporaryStorageConfig(
|
| + base::Bind(&ContinueGetTemporaryQuota, callback));
|
| }
|
|
|
| void QuotaManager::GetPersistentHostQuota(const std::string& host,
|
| @@ -1126,10 +1054,8 @@ void QuotaManager::SetPersistentHostQuota(const std::string& host,
|
| return;
|
| }
|
|
|
| - if (kPerHostPersistentQuotaLimit < new_quota) {
|
| - // Cap the requested size at the per-host quota limit.
|
| - new_quota = kPerHostPersistentQuotaLimit;
|
| - }
|
| + // Cap the requested size at the per-host quota limit.
|
| + new_quota = std::min(new_quota, kPerHostPersistentQuotaLimit);
|
|
|
| if (db_disabled_) {
|
| callback.Run(kQuotaErrorInvalidAccess, -1);
|
| @@ -1289,7 +1215,7 @@ QuotaManager::EvictionContext::~EvictionContext() {
|
| void QuotaManager::LazyInitialize() {
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| if (database_) {
|
| - // Initialization seems to be done already.
|
| + // Already initialized.
|
| return;
|
| }
|
|
|
| @@ -1307,17 +1233,16 @@ void QuotaManager::LazyInitialize() {
|
| clients_, kStorageTypeSyncable, special_storage_policy_.get(),
|
| storage_monitor_.get()));
|
|
|
| - int64_t* temporary_quota_override = new int64_t(-1);
|
| - int64_t* desired_available_space = new int64_t(-1);
|
| - PostTaskAndReplyWithResultForDBThread(
|
| - FROM_HERE,
|
| - base::Bind(&InitializeOnDBThread,
|
| - base::Unretained(temporary_quota_override),
|
| - base::Unretained(desired_available_space)),
|
| - base::Bind(&QuotaManager::DidInitialize,
|
| - weak_factory_.GetWeakPtr(),
|
| - base::Owned(temporary_quota_override),
|
| - base::Owned(desired_available_space)));
|
| + if (!is_incognito_) {
|
| + histogram_timer_.Start(FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(
|
| + kReportHistogramInterval),
|
| + this, &QuotaManager::ReportHistogram);
|
| + }
|
| +
|
| + GetTemporaryGlobalQuota(
|
| + base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
|
| + weak_factory_.GetWeakPtr(), base::TimeTicks::Now()));
|
| }
|
|
|
| void QuotaManager::RegisterClient(QuotaClient* client) {
|
| @@ -1414,9 +1339,6 @@ void QuotaManager::StartEviction() {
|
| DCHECK(!temporary_storage_evictor_.get());
|
| temporary_storage_evictor_.reset(new QuotaTemporaryStorageEvictor(
|
| this, kEvictionIntervalInMilliSeconds));
|
| - if (desired_available_space_ >= 0)
|
| - temporary_storage_evictor_->set_min_available_disk_space_to_start_eviction(
|
| - desired_available_space_);
|
| temporary_storage_evictor_->Start();
|
| }
|
|
|
| @@ -1635,7 +1557,7 @@ void QuotaManager::EvictOriginData(const GURL& origin,
|
| }
|
|
|
| void QuotaManager::GetUsageAndQuotaForEviction(
|
| - const UsageAndQuotaCallback& callback) {
|
| + const XUsageAndQuotaCallback& callback) {
|
| // crbug.com/349708
|
| TRACE_EVENT0("io", "QuotaManager::GetUsageAndQuotaForEviction");
|
|
|
| @@ -1647,7 +1569,7 @@ void QuotaManager::GetUsageAndQuotaForEviction(
|
| GetUsageTracker(kStorageTypeTemporary)
|
| ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
|
| GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
|
| - GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
|
| + xGetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
|
| dispatcher->WaitForResults(callback);
|
| }
|
|
|
| @@ -1656,7 +1578,7 @@ void QuotaManager::AsyncGetVolumeInfo(
|
| DCHECK(io_thread_->BelongsToCurrentThread());
|
| uint64_t* available_space = new uint64_t(0);
|
| uint64_t* total_space = new uint64_t(0);
|
| - PostTaskAndReplyWithResult(
|
| + base::PostTaskAndReplyWithResult(
|
| db_thread_.get(),
|
| FROM_HERE,
|
| base::Bind(get_volume_info_fn_,
|
| @@ -1699,28 +1621,13 @@ void QuotaManager::GetLRUOrigin(StorageType type,
|
| base::Owned(url)));
|
| }
|
|
|
| -void QuotaManager::DidSetTemporaryGlobalOverrideQuota(
|
| - const QuotaCallback& callback,
|
| - const int64_t* new_quota,
|
| - bool success) {
|
| - QuotaStatusCode status = kQuotaErrorInvalidAccess;
|
| - DidDatabaseWork(success);
|
| - if (success) {
|
| - temporary_quota_override_ = *new_quota;
|
| - status = kQuotaStatusOk;
|
| - }
|
| -
|
| - if (callback.is_null())
|
| - return;
|
| -
|
| - callback.Run(status, *new_quota);
|
| -}
|
| -
|
| void QuotaManager::DidGetPersistentHostQuota(const std::string& host,
|
| const int64_t* quota,
|
| bool success) {
|
| DidDatabaseWork(success);
|
| - persistent_host_quota_callbacks_.Run(host, kQuotaStatusOk, *quota);
|
| + persistent_host_quota_callbacks_.Run(
|
| + host, kQuotaStatusOk,
|
| + std::min(*quota, kPerHostPersistentQuotaLimit));
|
| }
|
|
|
| void QuotaManager::DidSetPersistentHostQuota(const std::string& host,
|
| @@ -1731,27 +1638,6 @@ void QuotaManager::DidSetPersistentHostQuota(const std::string& host,
|
| callback.Run(success ? kQuotaStatusOk : kQuotaErrorInvalidAccess, *new_quota);
|
| }
|
|
|
| -void QuotaManager::DidInitialize(int64_t* temporary_quota_override,
|
| - int64_t* desired_available_space,
|
| - bool success) {
|
| - temporary_quota_override_ = *temporary_quota_override;
|
| - desired_available_space_ = *desired_available_space;
|
| - temporary_quota_initialized_ = true;
|
| - DidDatabaseWork(success);
|
| -
|
| - if (!is_incognito_) {
|
| - histogram_timer_.Start(FROM_HERE,
|
| - base::TimeDelta::FromMilliseconds(
|
| - kReportHistogramInterval),
|
| - this, &QuotaManager::ReportHistogram);
|
| - }
|
| -
|
| - db_initialization_callbacks_.Run();
|
| - GetTemporaryGlobalQuota(
|
| - base::Bind(&QuotaManager::DidGetInitialTemporaryGlobalQuota,
|
| - weak_factory_.GetWeakPtr(), base::TimeTicks::Now()));
|
| -}
|
| -
|
| void QuotaManager::DidGetLRUOrigin(const GURL* origin,
|
| bool success) {
|
| DidDatabaseWork(success);
|
| @@ -1797,6 +1683,48 @@ void QuotaManager::DidGetAvailableSpace(int64_t space) {
|
| available_space_callbacks_.Run(kQuotaStatusOk, space);
|
| }
|
|
|
| +namespace {
|
| +void DidGetTempStorageConfigThreadAdapter(
|
| + base::TaskRunner* task_runner,
|
| + const TemporaryStorageConfigurationCallback& callback,
|
| + const TemporaryStorageConfiguration& storage_config) {
|
| + task_runner->PostTask(FROM_HERE, base::Bind(callback, storage_config));
|
| +}
|
| +} // namespace
|
| +
|
| +void QuotaManager::GetTemporaryStorageConfig(
|
| + const TemporaryStorageConfigurationCallback& callback) {
|
| + if (base::TimeTicks::Now() - storage_config_timestamp_ <
|
| + storage_config_.refresh_interval) {
|
| + callback.Run(storage_config_);
|
| + return;
|
| + }
|
| +
|
| + if (!storage_config_callbacks_.Add(callback))
|
| + return;
|
| +
|
| + // We invoke our clients GetTemporaryPoolConfigurationFunc on the
|
| + // UI thread and plumb the resulting value back to this thread.
|
| + get_config_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + get_config_function_,
|
| + profile_path_, is_incognito_,
|
| + base::Bind(
|
| + &DidGetTempStorageConfigThreadAdapter,
|
| + base::RetainedRef(base::ThreadTaskRunnerHandle::Get()),
|
| + base::Bind(
|
| + &QuotaManager::DidGetTemporaryStorageConfig,
|
| + weak_factory_.GetWeakPtr()))));
|
| +}
|
| +
|
| +void QuotaManager::DidGetTemporaryStorageConfig(
|
| + const TemporaryStorageConfiguration& config) {
|
| + SetTemporaryStorageConfiguration(config);
|
| + storage_config_callbacks_.Run(config);
|
| +}
|
| +
|
| +
|
| void QuotaManager::DidDatabaseWork(bool success) {
|
| db_disabled_ = !success;
|
| }
|
| @@ -1842,20 +1770,17 @@ int64_t QuotaManager::CallGetAmountOfFreeDiskSpace(
|
| return static_cast<int64_t>(available);
|
| }
|
|
|
| +// todo:maybe delete this, or make it private we can use SysInfo directly now
|
| //static
|
| bool QuotaManager::GetVolumeInfo(const base::FilePath& path,
|
| uint64_t* available_space,
|
| uint64_t* total_size) {
|
| - // Inspired by similar code in the base::SysInfo class.
|
| - base::ThreadRestrictions::AssertIOAllowed();
|
| -
|
| int64_t available = base::SysInfo::AmountOfFreeDiskSpace(path);
|
| if (available < 0)
|
| return false;
|
| int64_t total = base::SysInfo::AmountOfTotalDiskSpace(path);
|
| if (total < 0)
|
| return false;
|
| -
|
| *available_space = static_cast<uint64_t>(available);
|
| *total_size = static_cast<uint64_t>(total);
|
| return true;
|
|
|